stolenn1

1.0.0 • Public • Published

Localization Library

Overview

The Localization Library is a JavaScript package that provides support for managing translations in multiple languages. It allows you to easily add translations for different languages and retrieve translated strings based on keys.

Installation

You can install the Localization Library via npm:

npm install @your-username/localization

Usage

Initialization

To use the library, you first need to initialize an instance of the Localization class:

const Localization = require('@your-username/localization');

// Initialize with default language
const localization = new Localization('en');

Adding Translations

You can add translations for different languages using the addTranslations method:

localization.addTranslations('en', {
  'greeting': 'Hello',
  'farewell': 'Goodbye'
});

localization.addTranslations('fr', {
  'greeting': 'Bonjour',
  'farewell': 'Au revoir'
});

Translating Strings

Once translations are added, you can use the translate method to retrieve translated strings:

console.log(localization.translate('greeting')); // Output: Hello
console.log(localization.translate('farewell', 'fr')); // Output: Au revoir
console.log(localization.translate('missing_key')); // Output: missing_key (warning message logged)

API Reference

Localization(defaultLanguage)

  • defaultLanguage (optional): Default language code (default is 'en')

Methods

  • addTranslations(language, translations): Add translations for a specific language.
  • translate(key, language): Retrieve the translated string for a given key and language. If language is not provided, the default language is used.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Readme

Keywords

none

Package Sidebar

Install

npm i stolenn1

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

3.12 kB

Total Files

3

Last publish

Collaborators

  • aserboman