One Dionys (Localization Manager) - Manager to manage various local resources in multilingual applications.
npm install onedionys-localization-managerManager to manage various local resources in multilingual applications. 💖
Web Browser - Can be used as an emulator to build applications. Example [Chrome, Firefox, Safari & Opera].
Internet - Because many use CDN and to make it easier to find solutions to all problems.
javascript
// Example usage of LocalizationManager
const LocalizationManager = require('./src/localizationManager');
// Create a new instance of LocalizationManager
const manager = new LocalizationManager();
// Load localization data for English locale
const englishData = {
greeting: 'Hello',
farewell: 'Goodbye'
};
manager.loadLocaleData('en', englishData);
// Translate keys to English
console.log(manager.translate('greeting', 'en')); // Output: Hello
console.log(manager.translate('farewell', 'en')); // Output: Goodbye
console.log(manager.translate('missingKey', 'en')); // Output: Translation not found for key 'missingKey' in locale 'en'
`
#### Explanation
* loadLocaleData(locale, data): Loads localization data for a specific locale. locale is a string representing the locale (e.g., 'en' for English), and data is an object containing key-value pairs of translations.
* translate(key, locale): Translates the given key to the specified locale. Returns the translated string if found, otherwise returns a message indicating that the translation was not found.
#### Return Value
* For loadLocaleData(locale, data): No return value.
* For translate(key, locale)`: Returns the translated string if found, otherwise returns a message indicating that the translation was not found.