Compare commits

...

1 Commits
v1.9.0 ... i18n

Author SHA1 Message Date
Akash Nimare
411150fd72 i18n: Add test i18n framework. 2018-03-01 02:29:57 +05:30
5 changed files with 52 additions and 7 deletions

View File

@@ -10,6 +10,8 @@ const ConfigUtil = require(__dirname + '/../renderer/js/utils/config-util.js');
const appName = app.getName();
const i18n = require(__dirname + '/../translations/i18n');
class AppMenu {
getHistorySubmenu() {
return [{
@@ -246,15 +248,15 @@ class AppMenu {
}, {
label: 'Edit',
submenu: [{
role: 'undo'
role: 'undo', label: i18n._('Undo')
}, {
role: 'redo'
role: 'redo', label: i18n._('Redo')
}, {
type: 'separator'
}, {
role: 'cut'
role: 'cut', label: i18n._('Cut')
}, {
role: 'copy'
role: 'copy', label: i18n._('Copy')
}, {
role: 'paste'
}, {
@@ -334,11 +336,11 @@ class AppMenu {
accelerator: 'Ctrl+Q'
}]
}, {
label: 'Edit',
label: i18n.__('Edit'),
submenu: [{
role: 'undo'
role: 'undo', label: i18n.__('Undo')
}, {
role: 'redo'
role: 'redo', label: i18n.__('Redo')
}, {
type: 'separator'
}, {

View File

@@ -41,6 +41,7 @@ document.addEventListener('DOMContentLoaded', () => {
if (serverLanguage) {
// Set spellcheker language
ConfigUtil.setConfigItem('spellcheckerLanguage', serverLanguage);
// Init spellchecker
SetupSpellChecker.init();
}

4
app/translations/de.json Normal file
View File

@@ -0,0 +1,4 @@
{
"Edit": "Redigera",
"Undo": "Ångra"
}

4
app/translations/en.json Normal file
View File

@@ -0,0 +1,4 @@
{
"Edit": "Edit",
"Undo": "Undo"
}

34
app/translations/i18n.js Normal file
View File

@@ -0,0 +1,34 @@
const path = require('path');
const electron = require('electron');
const fs = require('fs');
const ConfigUtil = require(__dirname + '/../renderer/js/utils/config-util.js');
class i18n {
constructor() {
this.app = electron.app ? electron.app : electron.remote.app;
this.appLanguage = ConfigUtil.getConfigItem('spellcheckerLanguage');
this.appLocale = path.join(__dirname, this.appLanguage + '.json');
if (fs.existsSync(this.appLocale)) {
this.loadedLanguage = JSON.parse(fs.readFileSync(this.appLocale, 'utf8'));
console.log('translate into', this.appLanguage);
console.log(this.loadedLanguage);
} else {
this.loadedLanguage = JSON.parse(fs.readFileSync(path.join(__dirname, 'en.json'), 'utf8'));
console.log('no lang found');
console.log(this.loadedLanguage);
}
}
_(phrase) {
let translation = this.loadedLanguage[phrase];
if (translation === undefined) {
translation = phrase;
}
return translation;
}
}
// eslint-disable-next-line new-cap
module.exports = new i18n();