tsv-i18njs
v0.1.3
Published
convert TSV into i18n-js format translation files.
Downloads
5
Maintainers
Readme
tsv-i18njs
Convert i18n translation texts mageged on Google Sheets into i18n-js style translation files.
Installation
npm install tsv-i18njs --save-dev
Usage
node_modules/.bin/tsv-i18njs.js \
'https://docs.google.com/spreadsheets/d/e/2PACX-1vSUUk1_F-VxePs-exsB6R2F3fVIcAdxRRVLxgxz0uV4_Y0xPFDfMrLjvMAHQeYO4EXelqaJ2fgiNmF2/pub?gid=0&single=true&output=tsv' \
./
You can obtain the TSV URL by following menu [File] → [Publish to the web]
on Google Sheets.
The command generates i18n-js style translation files ready to use with i18n-js in current directory.
const I18n = require("i18n-js")
I18n.translations = {
en: require('./en-US.js'),
ja: require('./ja-JP.js'),
zh: require('./zh-CN.js'),
}
I18n.locale = "en-US"
I18n.t("screen.welcome.hello") // returns Hello
Each generated file looks like this.
// THIS FILE IS GENERATED BY tsv-i18njs
// DO NOT MODIFY DIRECTLY.
module.exports = {
"screen": {
"welcome": {
"hello": "Hello"
}
},
"currency_sign": "$",
"ok": "OK",
"cancel": "Cancel"
}
If you are an ES paranoia, add --format=es
to the command line to generate the file with export default
instead of module.exports
.
with gulp
with React Native Expo
import I18n = require("i18n-js")
import en from './translations/en'
import ja from './translations/ja'
import zh from './translations/zh'
async componentWillMount() {
I18n.translations = { en, ja, zh }
await I18n.locale = Expo.Util.getCurrentLocaleAsync()
}