i18next2ts
v1.0.0
Published
# 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?
Downloads
8
Readme
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:
{
"screenA": {
"title": "Screen Title",
"description": "Description",
"value": "value does not matter, can be empty!"
},
"auth": {
"password": "Password is required!",
"strangeKey": "does not matter"
},
"deepKeys": {
"lostInSpace": {
"andTime": {
"farAwayInAnother": "galaxy"
}
}
}
}
run
npm i i18next2ts --save-dev
in your projectrun
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