2gis/i18n-dialect

Name: i18n-dialect

Owner: 2GIS

Description: null

Created: 2017-08-03 13:58:25.0

Updated: 2018-05-15 03:39:37.0

Pushed: 2018-05-15 03:39:46.0

Homepage: null

Size: 88

Language: TypeScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

i18n-dialect

dialect is a library to support runtime i18n functions.

Usage

dialect exports a controller class called TranslationController, which should be instantiated in your application. Controller's constructor has following configurational parameters:

The TranslationController object also has a setLocale method to update internal dictionary - once this is done, the changes are applied to all subsequent calls of translation functions. Notice that setLocale method is asynchronous, so updating your user interface should not be done right after it's call: you should wait until everything is loaded and parsed.

Function interface

dialect exports four simple translation functions:

These functions are function generators (higher order functions), and before using them in your project you should parameterize them with TranslationController instance, like this:

rt { TranslationController, _tGen, _ptGen, _ntGen, _nptGen } from 'i18n-dialect';

controller = new TranslationController(...);

rt const _t = _tGen(controller);
rt const _pt = _ptGen(controller);
rt const _nt = _ntGen(controller);
rt const _npt = _nptGen(controller);

In some other file:

rt { _t, _pt, _nt, _npt } from '...';

ow you can use _t, _pt, etc.

Make sure that names of your created functions are strictly equal to _t, _nt, _pt and _npt, and you use these functions with these names only in your code; otherwise your translations will not be parsed successfully with i18n-stex parser.

Object interface

dialect also exports a single class called TranslationProvider, which simplifies interaction with library for a bit. You should instantiate it once and then just pass it into your other files and components. Example:

rt { TranslationController, TranslationProvider } from 'i18n-dialect';

controller = new TranslationController(...);
rt const i18n = new TranslationProvider(controller);

In some other file:

rt { i18n } from '...';

ow you can use i18n._t, i18n._pt, etc.
Contributing

i18n-dialect uses github-flow to accept & merge fixes and improvements. Basic process is:

Pull requests with failing tests will not be accepted. Also, if you add or modify packages to package.json, make sure you use yarn and update yarn.lock.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.