Skip to content

thorgate/tg-i18n

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 

tg-i18n

Internal tool to use translations in React that are loaded from our Django backend

Example init:

// i18n.js
import makeI18n, {setConfig} from 'tg-i18n';

const LANGUAGE_CODE = 'en';
const LOCALE_DATA = {
    '': {
        'domain': 'djangojs',
        // locale header
    },
    
    'en': {
        // translation strings
    },
}; 

setConfig('languageCode', LANGUAGE_CODE);
setConfig('localeData', LOCALE_DATA || {});

const i18n = makeI18n();

export const gettext = i18n.gettext;
export const pgettext = i18n.pgettext;
export const ngettext = i18n.ngettext;
export const npgettext = i18n.npgettext;
export const interpolate = i18n.interpolate;

export {setConfig} from 'tg-i18n';
export default i18n;

Using:

import i18n, {gettext} from './i18n';

i18n.setActiveLang('en');

console.log(gettext('Test string');

About

Internal tool to use translations in React that are loaded from our Django backend

Resources

Stars

Watchers

Forks

Packages

No packages published