2.0.4 • Published 3 years ago

com.recoyxgroup.localization v2.0.4

Weekly downloads
2
License
ISC
Repository
github
Last release
3 years ago

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

3 years ago

2.0.2

3 years ago

2.0.4

3 years ago

3.2.0

3 years ago

3.1.0

3 years ago

3.0.0

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.1.15

3 years ago

1.1.14

3 years ago

1.1.13

3 years ago

1.1.9

3 years ago

1.1.6

3 years ago

1.1.11

3 years ago

1.1.10

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago