Refactor locale to only expose the data we care about
This commit is contained in:

committed by
Scott Nonnenberg

parent
5e5ca80a6e
commit
ceaff68d55
@@ -1,5 +1,6 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const app = require('electron').app;
|
||||
|
||||
function normalizeLocaleName(locale) {
|
||||
if (/^en-/.test(locale)) {
|
||||
@@ -23,7 +24,25 @@ function getLocaleMessages(locale) {
|
||||
return JSON.parse(fs.readFileSync(targetFile, 'utf-8'))
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
normalizeLocaleName,
|
||||
getLocaleMessages
|
||||
// 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
|
||||
let localeName = normalizeLocaleName(app.getLocale());
|
||||
let messages;
|
||||
|
||||
try {
|
||||
messages = getLocaleMessages(localeName);
|
||||
} catch (e) {
|
||||
console.log('Problem loading messages for locale ', localeName, e.stack);
|
||||
console.log('Falling back to en locale');
|
||||
|
||||
localeName = 'en';
|
||||
messages = getLocaleMessages(localeName);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
name: localeName,
|
||||
messages
|
||||
}
|
||||
|
Reference in New Issue
Block a user