From aab6cb45cc8f91da8b1aea78a65e67faa317e684 Mon Sep 17 00:00:00 2001 From: whphhg Date: Wed, 24 May 2017 12:03:11 +0200 Subject: [PATCH] Locales: Folder names follow ISO 639 & 3166 --- README.md | 27 +++++++++++-- package.json | 4 +- src/locales/{en => en-US}/wallet.json | 0 src/locales/{pt => pt-PT}/wallet.json | 0 src/locales/{sl => sl-SI}/wallet.json | 0 src/stores/gui.js | 8 ++-- src/utilities/i18next.js | 56 ++++++++++++++++++--------- 7 files changed, 68 insertions(+), 27 deletions(-) rename src/locales/{en => en-US}/wallet.json (100%) rename src/locales/{pt => pt-PT}/wallet.json (100%) rename src/locales/{sl => sl-SI}/wallet.json (100%) diff --git a/README.md b/README.md index 06cf855..9d7bc79 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,27 @@ using `npm run dev` or `npm run dev-win` on Windows. $ npm run dev (Linux and macOS) $ npm run dev-win (Windows) +## Contributing translations +First follow the `Install from source` guide above. Then create a copy of the +`en-US` directory in `src/locales` and construct the first part of the directory +name by using the `ISO 639-1 Code` +[language code](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) +and the second part by using the `ISO 3166 Alpha-2 code` +[country code](https://en.wikipedia.org/wiki/ISO_3166-1#Current_codes). Delimit +the two with a dash `-`. + +After you've created the correctly named translation directory, open +`src/stores/gui.js` and add the new translation to the `languages` array (in +alphabetical order). + + { language: 'languageCode-countryCode', name: 'New language' }, + +You can now select your new translation in the GUI and start translating the +strings in the `wallet.json`. + +**Note:** Please use an editor that will open and save `wallet.json` in UTF-8 +(e.g. [Atom](https://atom.io/)). + ## Package and build To bundle the daemon with the GUI, name it `vcashd-arch`, where `arch` can be either `ia32` or `x64` and place it into the `bin` directory. This directory @@ -43,6 +64,9 @@ actually packaging the GUI run `npm run pack`. $ npm run pack +You can read more about the `electron-builder` options +[here](https://github.com/electron-userland/electron-builder/wiki/Options). + ### Linux and Windows (using Docker) The following dependencies are required to be installed: * docker (make sure your user is in the docker group) @@ -83,9 +107,6 @@ Script | Target arch | Description dist-linux | x64 | Create 64-bit Linux .deb and .zip packages dist-mac | x64 | Create 64-bit macOS .dmg package -You can read more about the `electron-builder` options -[here](https://github.com/electron-userland/electron-builder/wiki/Options). - ## License This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/package.json b/package.json index 23e4467..a9eba27 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "vcash-electron", "productName": "Vcash Electron GUI", - "version": "0.31.3", + "version": "0.31.4", "description": "Multi-platform and multi-node GUI for Vcash.", "main": "src/electron.js", "scripts": { @@ -55,7 +55,7 @@ "electron-compile": "6.4.1", "i18next": "8.3.0", "i18next-node-fs-backend": "1.0.0", - "mobx": "3.1.9", + "mobx": "3.1.10", "mobx-logger": "0.6.0", "mobx-react": "4.1.8", "moment": "2.18.1", diff --git a/src/locales/en/wallet.json b/src/locales/en-US/wallet.json similarity index 100% rename from src/locales/en/wallet.json rename to src/locales/en-US/wallet.json diff --git a/src/locales/pt/wallet.json b/src/locales/pt-PT/wallet.json similarity index 100% rename from src/locales/pt/wallet.json rename to src/locales/pt-PT/wallet.json diff --git a/src/locales/sl/wallet.json b/src/locales/sl-SI/wallet.json similarity index 100% rename from src/locales/sl/wallet.json rename to src/locales/sl-SI/wallet.json diff --git a/src/stores/gui.js b/src/stores/gui.js index 93801af..e498090 100644 --- a/src/stores/gui.js +++ b/src/stores/gui.js @@ -9,7 +9,7 @@ class GUI { * @property {string} language - Display language. * @property {string} localCurrency - Local currency. */ - @observable language = getItem('language') || 'en' + @observable language = getItem('language') || 'en-US' @observable localCurrency = getItem('localCurrency') || 'EUR' /** @@ -18,9 +18,9 @@ class GUI { */ constructor () { this.languages = [ - { language: 'en', name: 'English' }, - { language: 'pt', name: 'Portuguese' }, - { language: 'sl', name: 'Slovenian' } + { language: 'en-US', name: 'English' }, + { language: 'pt-PT', name: 'Portuguese' }, + { language: 'sl-SI', name: 'Slovenian' } ] /** Update i18next and moment on locale change. */ diff --git a/src/utilities/i18next.js b/src/utilities/i18next.js index 536be59..602a2e6 100644 --- a/src/utilities/i18next.js +++ b/src/utilities/i18next.js @@ -1,24 +1,44 @@ import i18next from 'i18next' import backend from 'i18next-node-fs-backend' import { getItem } from '../utilities/localStorage' +import { readdirSync } from 'fs' import { join } from 'path' -/** Initialize a i18next instance. */ -i18next - .use(backend) - .init({ - fallbackLng: getItem('language') || 'en', - ns: ['wallet'], - defaultNS: 'wallet', - debug: process.env.NODE_ENV === 'dev', - backend: { - loadPath: join(__dirname, '/../locales/{{lng}}/{{ns}}.json'), - addPath: join(__dirname, '/../locales/{{lng}}/{{ns}}.missing.json'), - jsonIndent: 2 - }, - load: 'current', - languages: ['en', 'sl'], - interpolation: { escapeValue: false } - }) +/** + * Start i18next. + * @function start + * @return {object} i18next instance. + */ +const start = () => { + /** Get available languages. */ + const languages = readdirSync(join(__dirname, '..', 'locales')) -export default i18next + /** Get saved language. */ + let fallbackLng = getItem('language') + + /** Check if the language exists or revert to default. */ + fallbackLng = languages.includes(fallbackLng) === true + ? fallbackLng + : 'en-US' + + /** Initialize a i18next instance. */ + return i18next + .use(backend) + .init({ + fallbackLng, + ns: ['wallet'], + defaultNS: 'wallet', + debug: process.env.NODE_ENV === 'dev', + backend: { + loadPath: join(__dirname, '..', 'locales', '{{lng}}', '{{ns}}.json'), + addPath: join(__dirname, '..', 'locales', '{{lng}}', '{{ns}}.missing.json'), + jsonIndent: 2 + }, + load: 'currentOnly', + languages, + interpolation: { escapeValue: false } + }) +} + +/** Export i18next instance. */ +export default start()