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",
"release": "build",
"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": {
"*.js": [
@ -112,6 +113,7 @@
"babel-preset-flow": "^6.23.0",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"chalk": "^2.3.1",
"chance": "^1.0.13",
"concurrently": "^3.5.1",
"dotenv": "^5.0.0",
@ -131,6 +133,7 @@
"flow-typed": "^2.3.0",
"hard-source-webpack-plugin": "^0.5.18",
"husky": "^0.14.3",
"js-yaml": "^3.10.0",
"lint-staged": "^6.1.1",
"node-loader": "^0.6.0",
"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
chooseWalletPlaceholder: Choose a wallet...
currency: Currency
language:
en: English
fr: French
orderAccounts:
name: Alphabetic
balance: Balance
type: Cryptocurrency
sidebar:
menu: Menu
accounts: Accounts
device:
connected: Connected
notConnected: Not connected
dashboard:
title: Dashboard
send:
title: Send
receive:
title: Receive
addAccount:
title: Add account
import:
placeholder: Account {{index}}
placeholder: 'Account {{index}}'
settings:
title: Settings
tabs:
display: Display
money: Money
@ -47,26 +36,20 @@ settings:
tools: Tools
blockchain: Blockchain
profile: Profile
display:
language: Language
orderAccounts: Order accounts
SelectAccount:
placeholder: Select a account
placeholder: Select an account
AccountPage:
balance: Balance
receive: Receive
lastOperations: Last operations
update:
newVersionReady: A new version is ready to be installed.
relaunch: Re-launch app now
IsUnlocked:
password: Password
sendModal:
Amount: Amount
Summary: Summary

23
static/i18n/fr/translation.yml

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

Loading…
Cancel
Save