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

feat: Relates to #402. Internationalisation. Base Support #452

Merged
merged 23 commits into from
Apr 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e7a81dc
chore: Update to latest React 16.8.3 to requirements of react-i18next
ltfschoen Feb 25, 2019
27c6e06
feat: Scaffold basic translation with English and German
ltfschoen Feb 26, 2019
12142e2
feat: Relates to #402. German translation fully working
ltfschoen Feb 26, 2019
fe1efc3
fix: Switch back to English by default
ltfschoen Feb 26, 2019
33c66f3
Merge branch 'master' into luke-402-i18n
ltfschoen Feb 27, 2019
55b4270
fix: Allow user to switch between languages in preferences of context…
ltfschoen Feb 27, 2019
9574abc
feat: Translate the context menus
ltfschoen Feb 28, 2019
f3b6124
refactor: Remove German language. Add as separate PR
ltfschoen Mar 17, 2019
060ac5f
refactor: Remove blank line
ltfschoen Mar 17, 2019
013470b
docs: Update Readme with Internationalisation Add New language instru…
ltfschoen Mar 17, 2019
674219c
docs: Update Readme with Known Issues and Usage instructions
ltfschoen Mar 17, 2019
766a842
Merge branch 'master' into luke-402-i18n
ltfschoen Mar 17, 2019
accff7d
review-fix: Disabled tooltip Please fill out this field. Add High and…
ltfschoen Mar 18, 2019
824cff5
review-fix: Update license headers to be 2019 instead of 2018
ltfschoen Mar 18, 2019
7a38c24
review-fix: Change ns1 to fether-electron and fether-react. Use pino.…
ltfschoen Mar 19, 2019
cabd0b5
fix: Add missing i18n conversion for macOS Edit menu
ltfschoen Mar 19, 2019
781eed4
review-fix: Remove unused i18next browser languagedetector dependency
ltfschoen Mar 19, 2019
7904485
Merge branch 'master' into luke-402-i18n
ltfschoen Mar 19, 2019
88c9b18
merge latest from master and fix conflicts
ltfschoen Mar 26, 2019
f8907fc
merge latest master and fix conflicts. TODO do not expose remote
ltfschoen Apr 11, 2019
3a3baee
fix: Do not expose remote. Only expose add and remove listener, and r…
ltfschoen Apr 11, 2019
5aacf6a
feat: Convert new release available text to i18n
ltfschoen Apr 11, 2019
cfbb472
Merge branch 'master' into luke-402-i18n
ltfschoen Apr 11, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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