Little helper for I18n-js


stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
00Mar 17, 2020Oct 19, 2016Minified + gzip package size for @morsedigital/i18n_helper in KB



A little helper to work with i18n-js

Set i18n-js gem in your rails app as the readme. Although maybe sure you have install i18n-js through npm/yarn.abs

By default the helper will use the lang attribute too set the language.


<html lang="<%= I18n.locale %>"></html>

Then in your JS:

import i18nHelper from '@morsedigital/i18n_helper';

const t = i18nHelper();

// Basics
p.innerHTML = t('my.key.goes.here', { translate: true }); // looks up 'my.key.goes.here'

// split keys
p.innerHTML = t('my', 'key', 'goes.here', { translate: true }); // looks up 'my.key.goes.here'

// pass option keys
p.innerHTML = t('my', 'key', 'goes.here', { translate: true, foo: 'bar' }); // looks up 'my.key.goes.here' with options {foo: 'bar'}

// Preset part keys
const key = t('my.key');

p.innerHTML = key('goes.here', { translate: true }); // looks up 'my.key.goes.here'

p2.innerHTML = key('another.here', { translate: true }); // looks up 'my.key.another.here'

p3.innerHTML = key('another.here', { translate: true, foo: 'bar' }); // looks up 'my.key.goes.here' with options {foo: 'bar'}

// Preset part keys and options
const key = t('my.key', { foo: 'bar' });

p.innerHTML = key('goes.here', { translate: true, path: 'foo/bar' }); // looks up 'my.key.goes.here' with options {foo: 'bar', path: 'foo/bar'}

p2.innerHTML = key('another.here', { translate: true, path: 'bar/foo' }); // looks up 'my.key.another.here' with options {foo: 'bar', path: 'bar/foo'}

Bug reports

If you discover any bugs, feel free to create an issue on GitHub. Please add as much information as possible to help us fixing the possible bug. We also encourage you to help even more by forking and sending us a pull request.



If you'd like to contribute, i18n_helper is written using babel and rollup in ES6.

Please make sure any additional code should be covered in tests (Jest).

If you need to run the test please use:

yarn test

or to rebuild the JS run:

yarn build


Adrian Stainforth (https://github.com/djforth)


i18n_helper is an open source project falling under the MIT License. By using, distributing, or contributing to this project, you accept and agree that all code within the @morsedigital/select-filter project are licensed under MIT license.

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.