Merge locale-provided strings into english for failover support

FREEBIE
This commit is contained in:
Scott Nonnenberg 2017-08-17 10:52:59 -07:00
parent 270f626cd7
commit 5099ca0ccd
No known key found for this signature in database
GPG key ID: A4931C09644C654B
2 changed files with 9 additions and 1 deletions

View file

@ -1,6 +1,7 @@
const path = require('path');
const fs = require('fs');
const app = require('electron').app;
const _ = require('lodash');
function normalizeLocaleName(locale) {
if (/^en-/.test(locale)) {
@ -25,6 +26,8 @@ function getLocaleMessages(locale) {
}
function load() {
var english = getLocaleMessages('en');
// Load locale - if we can't load messages for the current locale, we
// default to 'en'
//
@ -35,12 +38,15 @@ function load() {
try {
messages = getLocaleMessages(localeName);
// We start with english, then overwrite that with anything present in locale
messages = _.merge(english, messages);
} catch (e) {
console.log('Problem loading messages for locale ', localeName, e.stack);
console.log('Falling back to en locale');
localeName = 'en';
messages = getLocaleMessages(localeName);
messages = english;
}
return {

View file

@ -57,6 +57,8 @@
}
}
// We load locale this way and not via app.getLocale() because this call returns
// 'es_ES' and not just 'es.' And hunspell requires the fully-qualified locale.
var locale = osLocale.sync().replace('-', '_');
// The LANG environment variable is how node spellchecker finds its default language: