Merge locale-provided strings into english for failover support

FREEBIE
pull/749/head
Scott Nonnenberg 8 years ago
parent 270f626cd7
commit 5099ca0ccd
No known key found for this signature in database
GPG Key ID: A4931C09644C654B

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

@ -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('-', '_'); var locale = osLocale.sync().replace('-', '_');
// The LANG environment variable is how node spellchecker finds its default language: // The LANG environment variable is how node spellchecker finds its default language:

Loading…
Cancel
Save