0.0.5 • Published 9 years ago

localized-string v0.0.5

Weekly downloads
4
License
MIT
Repository
bitbucket
Last release
9 years ago

localized-string

Fetches and formats translated strings.

If you're using .properties files, grunt-concat-i18n is recommended.

Installation

$ npm i localized-string --save

Usage

var localizedString = require('localized-string')(translations);

var myDefaultLanguageString = localizedString.getText('', 'some.key', 'parameter');
var myGermanString = localizedString.getText('de_DE', 'some.key', ['more', 'params']);

translations is expected to be a hash of translations containing the translated strings, for example:

var translations = {
    '' : { // Default language
        'some.key': 'This is the parameter: {1}'
    },
    'de_DE': {
        'some.key': 'Zwei parameters: {1} {2}'
    }
}

It can also be a string pointing to a file which exports the default language. If files are named according to the pattern filename_de_DE.js then it will automatically pick up the languages. For example:

Directory contains

  1. translations.js
  2. translations_de_DE.js

And the files contain

module.exports = {
    'some.key': 'This is the parameter: {1}'
}

This could then be used with localized-string

var localizedString = require('localized-string')('path/to/file/translations);
0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago