displaykey
Simple text localization for your node.js application.
Example
var displaykey = ; var pathToLocaleFiles = ;var refreshInterval = 30000;displaykey;
Installation
$ npm install displaykey
Usage
Locale Files
displaykey loads in the different locale-specific values from JSON files. You need to create a directory to store these JSON files (it cannot contain anything other than these files). The format of the files should be similar to the following:
You should have one of these files created for each locale you plan to support. Name them appropriately, since the name
you use will be used as the locale code that is passed into the get()
function (minus the '.json' extension).
Setting Up
After installing using npm, you must setup displaykey to load in locale-specific JSON files from the correct directory
and tell it how often to check for changes to these files and load them in. To do this, it exposes the setup()
function.
var displaykey = ; // Set an absolute path to the locale-specific JSON files.var pathToLocaleFiles = ; // Set the refresh interval in milliseconds.var refreshInterval = 30000; // Call the setup function, passing in these values.// It will invoke the callback function when all displaykeys are loaded.displaykey;
Getting Values
Now that everything is set up, you are able to use the displaykey module in all it's glory. The get()
function
provides you with the ability to get the value of something for a specific locale. You can use it as follows:
displaykey;
where 'some.nested.key'
is a nested key in each of the locale files, and 'en'
is the name of the locale file to retrieve
the value from.
Therefore, if you have two locale files like so:
en.json
fr.json
The call to get()
above would return 'some nested english value'
.
License
MIT © 2015 Gavin Flood