Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Implement i18n for electron wrapper menu - Closes #768 #797

Merged
merged 25 commits into from
Oct 18, 2017

Conversation

reyraa
Copy link
Contributor

@reyraa reyraa commented Sep 29, 2017

  • Adds an i18n module to translate menu items
  • Creates Deutsch translation files
  • Uses osLocale to get the default locale of the browser
  • Uses electron-json-storage to store the last saved language
  • Communicates with react app to change the language consistently
    Closes Setup i18n in Electron menus #768

app/i18n.js Outdated
const fs = require('fs');
const storage = require('electron-json-storage'); // eslint-disable-line import/no-extraneous-dependencies
const osLocale = require('os-locale'); // eslint-disable-line import/no-extraneous-dependencies

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"os-locale" needs to be added to the package.json

@slaweet
Copy link
Contributor

slaweet commented Oct 2, 2017

When opening npm run start for the first time with the new changes I get this error.

A JavaScript error occurred in the main process
Uncaught Exception:
TypeError: locale.substr is not a function
    at Localization.init (/Users/slaweet/git/nano-review/app/i18n.js:13:60)
    at i18n.getLng (/Users/slaweet/git/nano-review/app/main.js:38:10)
    at storage.get (/Users/slaweet/git/nano-review/app/i18n.js:28:7)
    at /Users/slaweet/git/nano-review/node_modules/async/dist/async.js:421:16
    at next (/Users/slaweet/git/nano-review/node_modules/async/dist/async.js:5302:29)
    at /Users/slaweet/git/nano-review/node_modules/async/dist/async.js:906:16
    at /Users/slaweet/git/nano-review/node_modules/electron-json-storage/lib/storage.js:136:14
    at nextTask (/Users/slaweet/git/nano-review/node_modules/async/dist/async.js:5297:14)
    at next (/Users/slaweet/git/nano-review/node_modules/async/dist/async.js:5304:9)
    at /Users/slaweet/git/nano-review/node_modules/async/dist/async.js:906:16

"Lisk Forum": "Lisk Forum",
"Report Issue...": "Report Issue...",
"What's New...": "What's New..."
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to use other name then common.json (e.g. menu.json) for this file to make it easier to distinguish from src/locales/en/common.json in any localization platform we will choose.

@slaweet slaweet changed the base branch from development to 1.2.0 October 9, 2017 09:17
@slaweet slaweet assigned yasharAyari and unassigned reyraa Oct 12, 2017
@reyraa reyraa force-pushed the 768-electron-menu-i18n branch from b055619 to ef091e2 Compare October 13, 2017 09:22
@reyraa
Copy link
Contributor Author

reyraa commented Oct 13, 2017

For reviewing please note I've reset the history to fix merge conflicts easier.

app/src/menu.js Outdated
click(item, focusedWindow) {
if (focusedWindow) {
const options = {
buttons: ['OK'],
icon: `${__dirname}/assets/lisk.png`,
message: `Lisk Nano\nVersion ${app.getVersion()}\n${copyright}`,
message: `${i18n.t('Lisk Nano\nVersion')} ${app.getVersion()}\n${copyright}`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer the \nnot to be part of the translation string, it might be confusing to the translators. On the other hand, the version should be part of the translations string.

${i18n.t('Lisk Nano')}\n${i18n.t('Version {{version}}', { version: app.getVersion() })}

"{{count}} of entered delegate names could not be resolved:": "{{count}} of entered delegate names could not be resolved:",
"{{count}} of entered delegate names could not be resolved:_plural": "{{count}} of entered delegate names could not be resolved:"
"{{count}} of entered delegate names could not be resolved:_plural": ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert changes on lines 149-197. There was a problem in npm run i18n-scanner that caused those changes, but now it should keep the strings intact.

* Sends an event to client application
* @param {String} locale - the 2 letter name of the local
*/
const sendDetectedLang = (locale) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sendDetectedLang looks very similar tosendUrlToRouter. The common pattern could be abstracted into a function, e.g.: sendEvent(eventName, data)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need event in sendDetectedLang but we don't need it in sendUrlToRouter

app/src/menu.js Outdated
click() {
electron.shell.openExternal('https://explorer.lisk.io');
{
type: i18n.t('separator'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be just type: 'separator',. 'separator' is not a string in the UI.

"Last {{count}} days": "Last {{count}} day",
"Last {{count}} days_plural": "Last {{count}} days",
"Last {{count}} days": "Last {{count}} days",
"Last {{count}} days_plural": "",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two lines should not be changed. It's my bad. I've sent you wrong common.json.

@slaweet slaweet removed the request for review from yasharAyari October 17, 2017 13:49
@slaweet slaweet changed the base branch from 1.2.0 to development October 17, 2017 13:53
@slaweet slaweet changed the base branch from development to 1.2.0 October 17, 2017 13:53
Copy link
Contributor

@slaweet slaweet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it's all good. Thank you.

@yasharAyari yasharAyari merged commit 915920d into 1.2.0 Oct 18, 2017
@yasharAyari yasharAyari deleted the 768-electron-menu-i18n branch October 18, 2017 06:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants