/i18n-fast-translate

an easy way to translate the I18n files

Primary LanguageJavaScript

code style: prettier

I18n Fast Translate

an easy way to translate the I18n files fast

  • ⭐ easy to integrate
  • 💥 translates i18n files with one command
  • 👐 supports multiples providers

Content

Installation

add in your package.json

"@moonshot-partners/i18n-fast-translate": "moonshot-partners/i18n-fast-translate"

Usage

you have to create a configuration file in the root of your project

touch .fast-translate.json
{
  "base": "translations/en-us.json", // translation base
  "format": "json", // we only support json and yaml
  "onlyMissingKeys": true, // translate only if the target doesn't have the key from the i18n base
  "provider": "google" // translation service
  "translates": [ // target files: target = file path, to: translate language
    { "target": "translations/es.json", "to": "es" },
    { "target": "translations/pt-br.json", "to": "pt" }
  ]

then you can run fast-translate and it translates all the files automatically

fast-translate

Providers

Google

to default we use google cloud to translates the files, in order to it works fine you have to set up this env

Env:

export GOOGLE_APPLICATION_CREDENTIALS="your key path"

you can find more information about this here

Config key

{ "provider": "google" }

Google Legacy

if you are using the old API you can use this provider Env:

export GOOGLE_TRANSLATE_V2_API_KEY="YOUR API KEY"

Config key

{ "provider": "google-v2" }

Configuration

.fast-translation.json

{
  "base": "translations/en-us.json", // translation base
  "format": "json", // we only support json and yaml
  "onlyMissingKeys": true, // translate only if the target doesn't have the key from the i18n base
  "commit": true, //  send a git commit when it finishes to translates the files
  "provider": "google" // translation service
  "translates": [ // target files: target = file path, to: translate language
    { "target": "translations/es.json", "to": "es" },
    { "target": "translations/pt-br.json", "to": "pt" }
  ]