1.0.8 • Published 3 years ago

i18n-keys v1.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Build Status Coverage Status npm version npm bundle size

i18n-keys

This library will help to access the translation field from JSON / TypeScript file and take advantage of TypeScript.

It is useful when the localization file grows. Works fine with i18n,i18next.

The idea is simple, handy, and quite helpful:

Instead of accessing field by a string path like this:

i18next.t('homePage.header.buttons.signIn.title');

you can access translation key in that way:

i18next.t(translationKeys.homePage.header.buttons.signIn.title);

The only thing you need to do is to initialize translationKeys object like:

import en from './en.json'; // or `./en.ts`
import i18next from 'i18n-js';

i18next.init({
  lng: 'en',
  resources: {
    en: {
      translation: en,
    },
  },
});

const translationKeys = getTranslationKeys(en);

You can enjoy the benefits of TypeScript as well as IntelliSense of your IDE and lint.

Then you can use like this:

const text = i18next.t(translationKeys.homePage.header.buttons.signIn.title);

Check the example folder!

1.0.2

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago