2.0.4 • Published 4 years ago
com.recoyxgroup.localization v2.0.4
Localization
String localization in JavaScript.
Features:
- Supports loading text resources from HTTP (Web Browser and Node.js) and File System (Node.js).
- Basic language information and settings
Examples
import { LocaleMap, Gender, parseLocale } from 'com.recoyxgroup.localization';
const localeMap = new LocaleMap({
// Set of supported Locales.
// NOTE that the strings here indicate where
// the assets are located.
supportedLocales: ['en-US', 'en-GB', 'ja', 'pt-BR'],
defaultLocale: 'en-US',
fallbacks: {
'pt-BR': 'en-US',
'en-GB': ['ja', 'pt-BR']
},
assets: {
// assets URL or path
src: 'path/to/res/lang',
// asset JSON files
// - NOTE: slash works here
baseFileNames: ['common'],
// whether to clean assets automatically on locale switch
autoClean: true,
// 'fileSystem', 'http'
loaderType: 'fileSystem',
},
});
(async () => {
await localeMap.load();
const t = localeMap.get.bind(localeMap);
console.log(t('common.messageId'));
console.log(t('common.parameterized', { x: 'foo' }));
console.log(t('common.contextual', Gender.MALE));
console.log(t('common.qty', 10));
})();
Example assets:
{
"messageId": "Some message",
"parameterized": "Here: $x",
"contextualMale": "Male message",
"contextualFemale": "Female message",
"qtyEmpty": "$amount: empty",
"qtySingle": "$amount: single",
"qtyPlural": "$amount: plural"
}
2.0.3
4 years ago
2.0.2
4 years ago
2.0.4
4 years ago
3.2.0
4 years ago
3.1.0
4 years ago
3.0.0
4 years ago
2.0.1
4 years ago
2.0.0
4 years ago
1.1.15
4 years ago
1.1.14
4 years ago
1.1.13
4 years ago
1.1.9
4 years ago
1.1.6
4 years ago
1.1.11
4 years ago
1.1.10
4 years ago
1.1.5
4 years ago
1.1.4
4 years ago
1.1.3
4 years ago
1.1.2
4 years ago
1.1.1
4 years ago
1.1.0
4 years ago
1.0.6
4 years ago
1.0.5
4 years ago
1.0.4
4 years ago
1.0.3
4 years ago
1.0.2
4 years ago
1.0.1
4 years ago
1.0.0
4 years ago