Refactor external source files to live in app/

This commit is contained in:
David Balatero 2017-06-21 17:31:20 -07:00 committed by Scott Nonnenberg
parent db62494109
commit ed831dacd0
No known key found for this signature in database
GPG key ID: A4931C09644C654B
6 changed files with 13 additions and 9 deletions

29
app/locale.js Normal file
View file

@ -0,0 +1,29 @@
const path = require('path');
const fs = require('fs');
function normalizeLocaleName(locale) {
if (/^en-/.test(locale)) {
return 'en';
}
return locale;
}
function getLocaleMessages(locale) {
const onDiskLocale = locale.replace('-', '_');
const targetFile = path.join(
__dirname,
'..',
'_locales',
onDiskLocale,
'messages.json'
);
return JSON.parse(fs.readFileSync(targetFile, 'utf-8'))
}
module.exports = {
normalizeLocaleName,
getLocaleMessages
}