1.0.0 • Published 6 years ago

i18next2ts v1.0.0

Weekly downloads
1
License
MIT
Repository
-
Last release
6 years ago

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

1) 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"
      }
    }
  }
}

2) run npm i i18next2ts --save-dev in your project

3) run i18next2ts translation.json LanguageKeys.ts

4) create any .ts file to test it

import LocalizationKeys from 'LocalizationKeys'
const json = require('./translation.json');
const typedJson = json as LocalizationKeys;

5) now try to type typedJson. - tadam! hints are working like a charm.

6) you can now change your i18n.t('auth.passowrd)intoi18n.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