@module i18n
*/
-const fs = require('fs')
const i18n = require('i18next')
+const extend = require('lodash/extend')
-let i18nConf = fs.readFileSync(`${__dirname}/interface/project-tap.i18n`)
-i18nConf = JSON.parse(i18nConf)
+const LanguageDetector = require('i18next-browser-languagedetector')
+
+
+const supported_languages = ['en', 'zh']
const resources = {
- dev: { translation: require('./interface/i18n/desktop.en.i18n.json') },
+ dev: { translations: require('./interface/i18n/desktop.en.i18n.json') },
}
// add supported languages
-i18nConf.supported_languages.forEach((lang) => {
- resources[lang] = { translation: require(`./interface/i18n/desktop.${lang}.i18n.json`) }
+supported_languages.forEach((lang) => {
+ const desktopTranslations = require(`./interface/i18n/desktop.${lang}.i18n.json`)
+ const uiTranslations = require(`../src/locales/${lang}/translation.json`)
+ resources[lang] = { translations: extend(desktopTranslations, uiTranslations) }
})
/**
return bestMatchedCode
}
-i18n.init({
- lng: global.language || 'en',
- fallbackLng: 'en',
+i18n.use(LanguageDetector).init({
+ lng: global.language,
+ fallbackLng: 'en',
resources,
- interpolation: { prefix: '__', suffix: '__' },
-})
+ interpolation: {
+ escapeValue: false, // not needed for react!!
+ prefix: '__',
+ suffix: '__'
+ },
+ debug: false,
+
+ ns: ['translations'],
+ defaultNS: 'translations',
+ detection: {
+ // order and from where user language should be detected
+ order: ['localStorage', 'querystring', 'cookie', 'navigator', 'htmlTag', 'path', 'subdomain']
+ },
+
+ react: {
+ wait: true,
+ bindStore: false
+ }
+})
module.exports = i18n
const { Menu, app, shell, ipcMain, dialog , nativeImage} = require('electron')
const settings = require('electron-settings')
-global.language = settings.get('browserSetting.core.lang') || app.getLocale()
+global.language = settings.get('lang') || app.getLocale()
const i18n = require('../i18n.js')
global.i18n = i18n
const path = require('path')
// LANGUAGE (VIEW)
const defaultLanguage = i18n.getBestMatchedLangCode(app.getLocale())
- let currentLanguage = settings.get('browserSetting.core.lang') || defaultLanguage
+ let currentLanguage = settings.get('lang') || defaultLanguage
const LanguageMenu = [{
label: i18n.t('desktop.applicationMenu.view.default'),
type: 'checkbox',
},{
label: i18n.t('desktop.applicationMenu.view.langCodes.zh'),
type: 'checkbox',
- checked: currentLanguage === 'zh',
+ checked: currentLanguage.substring(0,2) == 'zh' ,
click: (item, focusedWindow) => {
if (focusedWindow) {
i18n.changeLanguage('zh', (err, t) => {
},{
label: i18n.t('desktop.applicationMenu.view.langCodes.en'),
type: 'checkbox',
- checked: currentLanguage === 'en',
+ checked: currentLanguage == 'en',
click: (item, focusedWindow) => {
if (focusedWindow) {
i18n.changeLanguage('en', (err, t) => {
menu.items[3].submenu.items[0].submenu.items[2].checked = ( btmAmountUnit === 'NEU' )
})
-settings.watch('browserSetting.core.lang', newValue => {
+settings.watch('lang', newValue => {
i18n.changeLanguage(newValue, (err, t) => {
if (err) return log.error('i18n: something went wrong loading', err)
createMenu()
import Root from 'Root'
import configureStore from 'configureStore'
import { I18nextProvider } from 'react-i18next'
-import i18n from './i18n'
+import i18n from '../modules/i18n.js'
// Set favicon
let faviconPath = require('!!file?name=favicon.ico!../static/images/favicon.png')
favicon.href = faviconPath
document.getElementsByTagName('head')[0].appendChild(favicon)
+
// Start app
export const store = configureStore()
render(
window.ipcRenderer.on('btmAmountUnitState', (event, arg) => {
this.props.uptdateBtmAmountUnit(arg)
})
+ window.ipcRenderer.on('lang', (event, arg) => {
+ this.props.i18n.changeLanguage(arg)
+ })
window.ipcRenderer.on('ConfiguredNetwork', (event, arg) => {
if(arg === 'startNode'){
this.props.fetchInfo().then(() => {
const browserSetting = {
core:{
btmAmountUnit: state.core.btmAmountUnit,
- lang: state.core.lang
},
app:{
navAdvancedState : state.app.navAdvancedState,
try {
localStorage.setItem('reduxState', JSON.stringify(exportable))
settings.set('browserSetting', browserSetting)
+ settings.set('lang',window.localStorage.getItem('i18nextLng'))
} catch (err) { /* localstorage not available */ }
}