Skip to content

Sage/f-locale

Folders and files

NameName
Last commit message
Last commit date

Latest commit

b414da9 · Mar 24, 2020

History

37 Commits
May 19, 2017
Jun 26, 2019
Jun 26, 2019
May 18, 2017
May 18, 2017
Jun 26, 2019
Jun 30, 2019
May 18, 2017
Jun 26, 2019
Jun 26, 2019
Mar 24, 2020
Mar 24, 2020
Jun 26, 2019
Jun 30, 2019

Repository files navigation

f-locale

Localization helper for f-promise

f-locale is a companion package for f-promise. It provides a small helper to manage localized messages.

Installation

npm install --save f-locale

Usage

Resources must be placed in JSON files inside a resources subdirectory of the current directory:

source-folder/
    resources/
        module1-en.json
        module1-fr.json
        ...
        module2-en.json
        module2-fr.json
        ...
    module1.ts
    module2.ts

The JSON files contain a simple object hash:

{
    "simple": "a simple message",
    "complex": "a more complex message with {{0}} and {{1}} args"
}

f-locale uses handlebars formatting directives.

Basic usage:

import { locale } from 'f-locale';
const resources = locale.resources(module);

// setting the locale
locale.current = 'fr';
// loading a simple message
console.log(resources.message('simple'));
// formating a parameterized message
cconsole.log(resources.format('complex', 'hello', 5));

License

MIT.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published