3.0.0 • Published 6 months ago

@tree-house/translations v3.0.0

Weekly downloads
4,031
License
ISC
Repository
github
Last release
6 months ago

Tree House Translations

NodeJS tranlations utilities for JSON files.

Installation

Install via npm

npm install @tree-house/translations

or via yarn

yarn add @tree-house/translations

NodeJS

getTranslator

Initialise a translator object pointing to the .json files where are translations are being stored and set a default locale. This object contains all functions which you can use after initialisation.

This becomes a singleton instance which will cache your translations globally. It is not possible at the moment to store translations into different folders.

import { getTranslator } from '@tree-house/translations';

const translator = getTranslator('/locales', 'en');
translator.translate(...);

The name of the translation file needs to match the language name. For example: /locales/en.json -> en

.translate

After initialising the translator you can easily find a translation value by its key for the required language in your localisation files.

translator.translate('key_to_translate', 'nl');

You can also replace values by using {{}} in your string values in the translation files.

translator.translate('key_to_translate', 'en', { name: 'Brent' });

This is my new sentence from {{name}} -> This is my new sentence from Brent

Tests

  • You can run npm run test to run all tests
  • You can run npm run test:coverage to run all tests with coverage report

Bugs

When you find issues, please report them:

Be sure to include all of the output from the npm command that didn't work as expected. The npm-debug.log file is also helpful to provide.

Authors

See the list of contributors who participated in this project.

License

This project is licensed under the ISC License - see the LICENSE.md file for details

3.0.0

6 months ago

2.3.0

2 years ago

2.2.0

2 years ago

2.1.0

2 years ago

2.0.1

2 years ago

2.0.0

3 years ago

1.2.0

3 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago

0.0.0

4 years ago