Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

Commit

Permalink
feat: Relates to #402. Internationalisation. Base Support (#452)
Browse files Browse the repository at this point in the history
* chore: Update to latest React 16.8.3 to requirements of react-i18next

* feat: Scaffold basic translation with English and German

* feat: Relates to #402. German translation fully working

* fix: Switch back to English by default

* fix: Allow user to switch between languages in preferences of context menu

* feat: Translate the context menus

* refactor: Remove German language. Add as separate PR

* refactor: Remove blank line

* docs: Update Readme with Internationalisation Add New language instructions

* docs: Update Readme with Known Issues and Usage instructions

* review-fix: Disabled tooltip Please fill out this field. Add High and Low tx speed

* review-fix: Update license headers to be 2019 instead of 2018

* review-fix: Change ns1 to fether-electron and fether-react. Use pino.debug

* fix: Add missing i18n conversion for macOS Edit menu

* review-fix: Remove unused i18next browser languagedetector dependency

* merge latest from master and fix conflicts

* merge latest master and fix conflicts. TODO do not expose remote

* fix: Do not expose remote. Only expose add and remove listener, and reload via bridge

* feat: Convert new release available text to i18n
  • Loading branch information
ltfschoen authored and Tbaut committed Apr 12, 2019
1 parent 6184a29 commit 649d6bf
Show file tree
Hide file tree
Showing 45 changed files with 1,475 additions and 502 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"preelectron": "yarn build",
"electron": "cd packages/fether-electron && yarn electron",
"fetch-parity": "cd scripts && node ./fetch-latest-parity.js",
"lint-files": "./scripts/lint-files.sh '**/*.js'",
"lint-files": "FILES='**/*.js' ./scripts/lint-files.sh $FILES",
"lint": "yarn lint-files",
"prepackage": "yarn build",
"package": "cd packages/fether-electron && yarn package",
Expand All @@ -61,7 +61,7 @@
},
"husky": {
"hooks": {
"pre-commit": "FILES=`git diff --staged --name-only --diff-filter=d HEAD | grep -E '.js$|.ts$'`; [ -z \"$FILES\" ] && exit 0; yarn lint-files $FILES; git add $FILES"
"pre-commit": "FILES=`git diff --staged --name-only --diff-filter=d HEAD | grep -E '.js$'`; [ -z \"$FILES\" ] && exit 0; yarn lint-files $FILES; git add $FILES"
}
},
"devDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions packages/fether-electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
"electron-positioner": "^4.1.0",
"electron-settings": "^3.2.0",
"fether-react": "^0.4.0",
"i18next": "^15.0.4",
"i18next-node-fs-backend": "^2.0.0",
"pino": "^4.16.1",
"pino-multi-stream": "^3.1.2",
"source-map-support": "^0.5.10",
Expand Down
82 changes: 82 additions & 0 deletions packages/fether-electron/src/main/app/menu/i18n/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
// This file is part of Parity.
//
// SPDX-License-Identifier: BSD-3-Clause

import i18next from 'i18next';
import Backend from 'i18next-node-fs-backend';
import electron from 'electron';
import settings from 'electron-settings';

import { name } from '../../../../../package.json';
import Pino from '../../utils/pino';
import { en } from './locales';

let { app } = electron;
const pino = Pino();
let resourceEnglishNS = {};
resourceEnglishNS[name] = en;
const packageNS = Object.keys(resourceEnglishNS)[0].toString();
const moduleNS = 'i18n';
const menuNS = `${packageNS}-${moduleNS}`;

const i18n = i18next;
i18n
.use(Backend)
.init({
debug: true,
defaultNS: packageNS,
fallbackLng: ['en-US', 'en'],
interpolation: {
escapeValue: false
},
lng: settings.get('fether-language') || 'en',
ns: [packageNS],
resources: {
en: resourceEnglishNS
},
saveMissing: true
})
.then(() => pino.info(`${menuNS}: success`))
.catch(error => pino.info(`${menuNS}: failure`, error));

// FIXME i18n - convert all text below to i18n

// https://www.i18next.com/overview/api#changelanguage
i18n.changeLanguage(app.getLocale(), (err, t) => {
if (err) {
pino.info(`${menuNS}: Error loading language ${app.getLocale()}`, err);
}
});

i18next.on('initialized', options => {
pino.debug(`${menuNS}: Detected initialisation of i18n`);
});

i18next.on('loaded', loaded => {
pino.info(`${menuNS}: Detected success loading resources: `, loaded);
});

i18next.on('failedLoading', (lng, ns, msg) => {
pino.info(`${menuNS}: Detected failure loading resources: `, lng, ns, msg);
});

// saveMissing must be configured to `true`
i18next.on('missingKey', (lngs, namespace, key, res) => {
pino.info(`${menuNS}: Detected missing key: `, lngs, namespace, key, res);
});

i18next.store.on('added', (lng, ns) => {
pino.debug(`${menuNS}: Detected resources added: `, lng, ns);
});

i18next.store.on('removed', (lng, ns) => {
pino.debug(`${menuNS}: Detected resources removed: `, lng, ns);
});

// https://www.i18next.com/overview/api#changelanguage
i18next.on('languageChanged', lng => {
pino.info(`${menuNS}: Detected language change to: `, lng);
});

export default i18n;
55 changes: 55 additions & 0 deletions packages/fether-electron/src/main/app/menu/i18n/locales/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"menu": {
"file": {
"submenu_name": "File",
"about": "About",
"preferences": {
"submenu_name": "Preferences",
"languages": {
"submenu_name": "Languages",
"language": "Language",
"english": "English",
"german": "German"
}
},
"services": "Services",
"hide": "Hide",
"hide_others": "Hide Others",
"unhide": "Unhide",
"quit": "Quit"
},
"edit": {
"submenu_name": "Edit",
"undo": "Undo",
"redo": "Redo",
"cut": "Cut",
"copy": "Copy",
"paste": "Paste",
"delete": "Delete",
"select_all": "Select All",
"speech": {
"submenu_name": "Speech",
"start_speaking": "Start Speaking",
"stop_speaking": "Stop Speaking"
}
},
"view": {
"submenu_name": "View",
"reload": "Reload",
"toggle_developer_tools": "Toggle Developer Tools"
},
"window": {
"submenu_name": "Window",
"close": "Close",
"minimize": "Minimize",
"zoom": "Zoom",
"bring_all_to_front": "Bring All to Front"
},
"help": {
"submenu_name": "Help",
"search": "Search",
"learn_more": "Learn More"
},
"show_hide_fether": "Show/Hide Fether"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import en from './en.json';

export { en };
Loading

0 comments on commit 649d6bf

Please sign in to comment.