Browse Source

Synchronize translations with Lokalise

master
meriadec 7 years ago
parent
commit
de4354eb76
No known key found for this signature in database GPG Key ID: 1D2FC2305E2CB399
  1. 5
      package.json
  2. 71
      scripts/trans.js
  3. 21
      static/i18n/en/translation.yml
  4. 23
      static/i18n/fr/translation.yml

5
package.json

@ -18,7 +18,8 @@
"publish-storybook": "bash ./scripts/publish-storybook.sh", "publish-storybook": "bash ./scripts/publish-storybook.sh",
"release": "build", "release": "build",
"start": "bash ./scripts/start.sh", "start": "bash ./scripts/start.sh",
"storybook": "STORYBOOK_ENV=1 start-storybook -s ./static -p 4444" "storybook": "STORYBOOK_ENV=1 start-storybook -s ./static -p 4444",
"trans": "node scripts/trans"
}, },
"lint-staged": { "lint-staged": {
"*.js": [ "*.js": [
@ -112,6 +113,7 @@
"babel-preset-flow": "^6.23.0", "babel-preset-flow": "^6.23.0",
"babel-preset-react": "^6.24.1", "babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1", "babel-preset-stage-0": "^6.24.1",
"chalk": "^2.3.1",
"chance": "^1.0.13", "chance": "^1.0.13",
"concurrently": "^3.5.1", "concurrently": "^3.5.1",
"dotenv": "^5.0.0", "dotenv": "^5.0.0",
@ -131,6 +133,7 @@
"flow-typed": "^2.3.0", "flow-typed": "^2.3.0",
"hard-source-webpack-plugin": "^0.5.18", "hard-source-webpack-plugin": "^0.5.18",
"husky": "^0.14.3", "husky": "^0.14.3",
"js-yaml": "^3.10.0",
"lint-staged": "^6.1.1", "lint-staged": "^6.1.1",
"node-loader": "^0.6.0", "node-loader": "^0.6.0",
"prettier": "^1.10.2", "prettier": "^1.10.2",

71
scripts/trans.js

@ -0,0 +1,71 @@
#!/usr/bin/env node
/* eslint-disable no-console */
/* eslint-disable no-use-before-define */
require('dotenv').config()
const path = require('path')
const fs = require('fs')
const axios = require('axios')
const querystring = require('querystring')
const forEach = require('lodash/forEach')
const objectPath = require('object-path')
const yaml = require('js-yaml')
const chalk = require('chalk')
const { LOKALISE_TOKEN, LOKALISE_PROJECT } = process.env
const BASE = 'https://api.lokalise.co/api'
const stats = {
nb: 0,
}
main()
async function main() {
try {
console.log(`${chalk.blue('[>]')} ${chalk.dim('Fetching translations...')}`)
const url = `${BASE}/string/list`
const { data } = await axios.post(
url,
querystring.stringify({
api_token: LOKALISE_TOKEN,
id: LOKALISE_PROJECT,
}),
)
if (data.response.status === 'error') {
throw new Error(JSON.stringify(data.response))
}
const { strings } = data
forEach(strings, syncLanguage)
console.log(
`${chalk.blue('[>]')} ${chalk.dim('Successfully imported')} ${stats.nb} ${chalk.dim(
'translations',
)}`,
)
} catch (err) {
console.log(err)
console.log(`${chalk.red('[x] Error in the process')}`)
process.exit(1)
}
}
function syncLanguage(translations, language) {
const folderPath = getLanguageFolderPath(language)
const filePath = path.resolve(folderPath, 'translation.yml')
if (!fs.existsSync(folderPath)) {
fs.mkdirSync(folderPath)
}
const obj = translations.reduce((acc, cur) => {
objectPath.set(acc, cur.key, cur.translation)
console.log(`${chalk.green('[✓]')} ${language} ${chalk.dim(cur.key)}`)
++stats.nb
return acc
}, {})
fs.writeFileSync(filePath, yaml.dump(obj))
}
function getLanguageFolderPath(language) {
return path.resolve(__dirname, `../static/i18n/${language}`)
}

21
static/i18n/en/translation.yml

@ -3,42 +3,31 @@ common:
cancel: Cancel cancel: Cancel
chooseWalletPlaceholder: Choose a wallet... chooseWalletPlaceholder: Choose a wallet...
currency: Currency currency: Currency
language: language:
en: English en: English
fr: French fr: French
orderAccounts: orderAccounts:
name: Alphabetic name: Alphabetic
balance: Balance balance: Balance
type: Cryptocurrency type: Cryptocurrency
sidebar: sidebar:
menu: Menu menu: Menu
accounts: Accounts accounts: Accounts
device: device:
connected: Connected connected: Connected
notConnected: Not connected notConnected: Not connected
dashboard: dashboard:
title: Dashboard title: Dashboard
send: send:
title: Send title: Send
receive: receive:
title: Receive title: Receive
addAccount: addAccount:
title: Add account title: Add account
import: import:
placeholder: Account {{index}} placeholder: 'Account {{index}}'
settings: settings:
title: Settings title: Settings
tabs: tabs:
display: Display display: Display
money: Money money: Money
@ -47,26 +36,20 @@ settings:
tools: Tools tools: Tools
blockchain: Blockchain blockchain: Blockchain
profile: Profile profile: Profile
display: display:
language: Language language: Language
orderAccounts: Order accounts orderAccounts: Order accounts
SelectAccount: SelectAccount:
placeholder: Select a account placeholder: Select an account
AccountPage: AccountPage:
balance: Balance balance: Balance
receive: Receive receive: Receive
lastOperations: Last operations lastOperations: Last operations
update: update:
newVersionReady: A new version is ready to be installed. newVersionReady: A new version is ready to be installed.
relaunch: Re-launch app now relaunch: Re-launch app now
IsUnlocked: IsUnlocked:
password: Password password: Password
sendModal: sendModal:
Amount: Amount Amount: Amount
Summary: Summary Summary: Summary

23
static/i18n/fr/translation.yml

@ -1,44 +1,33 @@
common: common:
ok: Okay ok: Ok
cancel: Annuler cancel: Annuler
chooseWalletPlaceholder: Choisir un portefeuille... chooseWalletPlaceholder: Choisir un portefeuille...
currency: Monnaie currency: Monnaie
language: language:
en: Anglais en: Anglais
fr: Français fr: Français
orderAccounts: orderAccounts:
name: Alphabetic name: Alphabétique
balance: Balance balance: Balance
type: Cryptocurrency type: Cryptocurrency
sidebar: sidebar:
menu: Menu menu: Menu
accounts: Comptes accounts: Comptes
device: device:
connected: Connecté connected: Connecté
notConnected: Non connecté notConnected: Non connecté
dashboard: dashboard:
title: Tableau de bord title: Tableau de bord
send: send:
title: Envoyer title: Envoyer
receive: receive:
title: Recevoir title: Recevoir
addAccount: addAccount:
title: Ajouter un compte title: Ajouter un compte
import: import:
placeholder: Compte {{index}} placeholder: 'Compte {{index}}'
settings: settings:
title: Réglages title: Réglages
tabs: tabs:
display: Affichage display: Affichage
money: Monnaie money: Monnaie
@ -47,26 +36,20 @@ settings:
tools: Outils tools: Outils
blockchain: Blockchain blockchain: Blockchain
profile: Profil profile: Profil
display: display:
language: Langage language: Langage
orderAccounts: Ordre des comptes orderAccounts: Ordre des comptes
SelectAccount: SelectAccount:
placeholder: Sélectionner un compte placeholder: Sélectionner un compte
AccountPage: AccountPage:
balance: Balance balance: Balance
receive: Recevoir receive: Recevoir
lastOperations: Dernières opérations lastOperations: Dernières opérations
update: update:
newVersionReady: Une nouvelle version est prête à être installée newVersionReady: Une nouvelle version est prête à être installée
relaunch: Redémarrer l'application maintenant relaunch: Redémarrer l'application maintenant
IsUnlocked: IsUnlocked:
password: Mot de passe password: Mot de passe
sendModal: sendModal:
Amount: Montant Amount: Montant
Summary: Résumé Summary: Résumé

Loading…
Cancel
Save