Installation
Purpose
- Are you tired of cpy-paste of translation keys?
- Are you in love with TS?
- You do hate a typos when providing a translation key?
- Want to avoid providing a key that does not exist?
Perfect! I answered yes
to all the above and made a simple tool for us:
instead of i18n.t('auth.password')
lets write i18n.t(typedJson.auth.password)
!
Are you fancy testing it out?
Quickstart
- grab this json and save it to some file:
-
run
npm i i18next2ts --save-dev
in your project -
run
i18next2ts translation.json LanguageKeys.ts
-
create any .ts file to test it
import LocalizationKeys from 'LocalizationKeys'const json = require('./translation.json');const typedJson = json as LocalizationKeys;
-
now try to type
typedJson.
- tadam! hints are working like a charm. -
you can now change your
i18n.t('auth.passowrd
)into
i18n.t(typedJson.auth.password)` instead
Dependencies:
- no dependencies for module itself!
- CLI uses 'fs' native module
restrictions
- keys should be .notation acceptable (no - for example)
- types other than
string
or{}
are not supported - they are not present in the common translation files for i18next
//TODO GIF //TODO tests //TODO travis //TODO coveralls