split added glitch locales from vanilla (#82)

* Locale script now accepts overrides and new keys from glitch/locales

* Revert glitchsoc changes to mastodon/locales to prevent future merge conflicts
This commit is contained in:
Ondřej Hruška
2017-07-16 01:15:25 +02:00
committed by GitHub
parent 4715161a93
commit 3ea02314b9
4 changed files with 62 additions and 139 deletions

View File

@ -34,6 +34,23 @@ locales.forEach(locale => {
].filter(filename => fs.existsSync(path.join(outPath, filename)))
.map(filename => filename.replace(/..\/..\/node_modules\//, ''))[0];
let glitchInject = `
const mergedMessages = messages;
`;
const glitchPath = `../../app/javascript/glitch/locales/${locale}.json`;
if (fs.existsSync(path.join(outPath, glitchPath))) {
glitchInject = `
import glitchMessages from ${JSON.stringify(glitchPath)};
let mergedMessages = messages;
Object.keys(glitchMessages).forEach(function (key) {
mergedMessages[key] = glitchMessages[key];
});
`;
}
const localeContent = `//
// locale_${locale}.js
// automatically generated by generateLocalePacks.js
@ -41,7 +58,8 @@ locales.forEach(locale => {
import messages from '../../app/javascript/mastodon/locales/${locale}.json';
import localeData from ${JSON.stringify(localeDataPath)};
import { setLocale } from '../../app/javascript/mastodon/locales';
setLocale({messages, localeData});
${glitchInject}
setLocale({messages: mergedMessages, localeData: localeData});
`;
fs.writeFileSync(localePath, localeContent, 'utf8');
outPaths.push(localePath);