@relocale/i18n
v1.0.12
Published
Internationalization and localization package
Downloads
5
Maintainers
Readme
Relocale
Getting started
Library for localization and internationalization.
Advantages
- The size is 10 times smaller than in i18next
- Works with all possible frameworks (React, Next.js, Vue itc.) and in pure javascript
- Supports SSR, SSG
Init
import { init } from '@relocale/i18n';
const lang = 'en';
const resources = {
en: {
// ...some keys
},
de: {
// ...some keys
}
};
const onMissingKey = (missingKey) => {
console.log(`Missing key: ${missingKey}`);
}
// sync operation
init({ lang, resources, onMissingKey });
Usage
import { t } from '@relocale/i18n';
// without params
t`some-key`
// or
t('some-key')
// or with nesting
t`key1.key2.key3`
// with params
t('hi', { username: 'Garry' }) // Hi Garry
Translations with params
const resources = {
en: {
hi: 'Hi {{username}}'
},
};
Change language
import { changeLang, getLang } from '@relocale/i18n';
const newLang = 'fr';
changeLang(newLang);
getLang(); // fr