Load locale information only after application's 'ready' event
FREEBIE
This commit is contained in:
parent
5526958c52
commit
53d1e7e6c7
2 changed files with 29 additions and 18 deletions
|
@ -24,25 +24,31 @@ function getLocaleMessages(locale) {
|
||||||
return JSON.parse(fs.readFileSync(targetFile, 'utf-8'));
|
return JSON.parse(fs.readFileSync(targetFile, 'utf-8'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load locale - if we can't load messages for the current locale, we
|
function load() {
|
||||||
// default to 'en'
|
// Load locale - if we can't load messages for the current locale, we
|
||||||
//
|
// default to 'en'
|
||||||
// possible locales:
|
//
|
||||||
// https://github.com/electron/electron/blob/master/docs/api/locales.md
|
// possible locales:
|
||||||
let localeName = normalizeLocaleName(app.getLocale());
|
// https://github.com/electron/electron/blob/master/docs/api/locales.md
|
||||||
let messages;
|
let localeName = normalizeLocaleName(app.getLocale());
|
||||||
|
let messages;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
messages = getLocaleMessages(localeName);
|
messages = getLocaleMessages(localeName);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('Problem loading messages for locale ', localeName, e.stack);
|
console.log('Problem loading messages for locale ', localeName, e.stack);
|
||||||
console.log('Falling back to en locale');
|
console.log('Falling back to en locale');
|
||||||
|
|
||||||
localeName = 'en';
|
localeName = 'en';
|
||||||
messages = getLocaleMessages(localeName);
|
messages = getLocaleMessages(localeName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
name: localeName,
|
||||||
|
messages
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: localeName,
|
load: load
|
||||||
messages
|
};
|
||||||
}
|
|
||||||
|
|
7
main.js
7
main.js
|
@ -40,9 +40,14 @@ if (config.environment === 'production' && !process.mas) {
|
||||||
const userConfig = require('./app/user_config');
|
const userConfig = require('./app/user_config');
|
||||||
let windowConfig = userConfig.get('window');
|
let windowConfig = userConfig.get('window');
|
||||||
|
|
||||||
const locale = require('./app/locale');
|
const loadLocale = require('./app/locale').load;
|
||||||
|
let locale;
|
||||||
|
|
||||||
function createWindow () {
|
function createWindow () {
|
||||||
|
if (!locale) {
|
||||||
|
locale = loadLocale();
|
||||||
|
}
|
||||||
|
|
||||||
const windowOptions = Object.assign({
|
const windowOptions = Object.assign({
|
||||||
width: 800,
|
width: 800,
|
||||||
height: 610,
|
height: 610,
|
||||||
|
|
Loading…
Reference in a new issue