Skip to content

Commit

Permalink
Locales: Folder names follow ISO 639 & 3166
Browse files Browse the repository at this point in the history
  • Loading branch information
whphhg committed May 24, 2017
1 parent d33956a commit aab6cb4
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 27 deletions.
27 changes: 24 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down Expand Up @@ -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",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions src/stores/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

/**
Expand All @@ -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. */
Expand Down
56 changes: 38 additions & 18 deletions src/utilities/i18next.js
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit aab6cb4

Please sign in to comment.