Dynamic I18n
Dynamic I18n is a tool to export and import your i18n data.
Supported Providers
- Google sheets
Getting started
npm install --save dynamic-i18n
Usage
Configuration
logger: consolelog title: 'Translate' provider: 'google-sheet' languages: 'fr' 'en' 'spreadsheet-key': '1FDE8DWKCQu6HWm3TqgEd-VUK7EuImAnbtanObrNzgZg' 'credentials': "Your credential according to the provider that you are using"
key | Required | Default | Description |
---|---|---|---|
languages | Required | [] |
Contain all the locales we want to import. |
spreadsheet-key | Required | '' |
The identifier for the source of the data stored. |
credentials | Required | {} |
Configuration for the provider. |
logger | Optional | console.log |
Used to display log informations. |
title | Optional | 'Translate' |
Title of the document. |
outputFilePrefix | Optional | 'locale' |
Prefix of the output file like : {{outputFilePrefix}}-{{language}}.json. |
Sample of credentials for google-sheet provider
"type": "service_account" "project_id": " [...] " "private_key_id": " [...] " "private_key": "-----BEGIN PRIVATE KEY----- [...] -----END PRIVATE KEY-----\n" "client_email": " [...] @ [...] .gserviceaccount.com" "client_id": " [...] " "auth_uri": "https://accounts.google.com/o/oauth2/auth" "token_uri": "https://accounts.google.com/o/oauth2/token" "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs" "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/ [...] .gserviceaccount.com"
Import i18n files : provider --> locale.json
var dynamicI18n = ; dynamicI18n;
Export i18n files : locale.json --> provider
var dynamicI18n = ; dynamicI18n;
Example with Gulp
This task will import your locales from the provider to your project
gulp;
This task will initialize the locales to the provider based on your project locales.
gulp;
Example with Webpack
This plugin export locales to google-sheet :
const dynamicI18n = ;const fs = ; { thisoptions = options} TranslatePluginprototype { compiler;}; moduleexports = TranslatePlugin;
This plugin import locales from google-sheet to translations in dist folder :
const dynamicI18n = ;const fs = ; { thisoptions = options} TranslatePluginprototype { compiler;}; moduleexports = TranslatePlugin;
Plugin usage sample :
const TranslatePlugin = ; ... "dynamic-i18n": conf: logger: consoleerror title: 'translate-dev' provider: 'google-sheet' languages: 'FR-FR' 'EN-GB' 'spreadsheet-key': '1bkUt23PspVVC0Q2BGQq4PWQFdP0LXT7H5ypzPnKizAY' credentials: "type": "service_account" ... "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/admin-346%40alehos-m5.iam.gserviceaccount.com" ;