i18next2ts
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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"
      }
    }
  }
}
  1. run npm i i18next2ts --save-dev in your project

  2. run i18next2ts translation.json LanguageKeys.ts

  3. create any .ts file to test it

import LocalizationKeys from 'LocalizationKeys'
const json = require('./translation.json');
const typedJson = json as LocalizationKeys;
  1. now try to type typedJson. - tadam! hints are working like a charm.

  2. 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

Package Sidebar

Install

npm i i18next2ts

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

32.1 kB

Total Files

24

Last publish

Collaborators

  • kgajowy