Refactor external source files to live in app/
This commit is contained in:
parent
db62494109
commit
ed831dacd0
6 changed files with 13 additions and 9 deletions
29
app/locale.js
Normal file
29
app/locale.js
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue