mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2025-05-03 17:34:12 -04:00
Use routes.json
to get localization paths
Before we were using glob, which was about to start failing on subdirectories in views (which we started using in `conference`). Instead of searching for `l10n.json`, it seemed more appropriate to instead look for localization by using the configured pages that need to be localized.
This commit is contained in:
parent
b1be409dea
commit
1f871e7cf1
8 changed files with 123 additions and 119 deletions
bin/lib
|
@ -125,15 +125,24 @@ Helpers.writeTranslationsToJS = function (outputDir, viewName, translationObject
|
|||
fs.writeFileSync(outputDir + '/' + viewName + '.intl.js', fileString);
|
||||
};
|
||||
|
||||
Helpers.getIdsForView = function (viewName, viewFile, localeObject, idsWithICU, icuWithIds) {
|
||||
var ids = JSON.parse(fs.readFileSync(viewFile, 'utf8'));
|
||||
localeObject[viewName] = {
|
||||
en: ids
|
||||
};
|
||||
// Returns a FormattedMessage id with english string as value. Use for default values in translations
|
||||
// Sample structure: { 'general-general.blah': 'blah', 'about-about.blah': 'blahblah' }
|
||||
Helpers.idToICUMap = function (viewName, ids) {
|
||||
var idsToICU = {};
|
||||
for (var id in ids) {
|
||||
idsWithICU[viewName + '-' + id] = ids[id];
|
||||
icuWithIds[ids[id]] = viewName + '-' + id; // add viewName to identifier for later
|
||||
idsToICU[viewName + '-' + id] = ids[id];
|
||||
}
|
||||
return idsToICU;
|
||||
};
|
||||
|
||||
// Reuturns reverse (i.e. english string with message key as the value) object for searching po files.
|
||||
// Sample structure: { 'blah': 'general-general.blah', 'blahblah': 'about-about.blah' }
|
||||
Helpers.icuToIdMap = function (viewName, ids) {
|
||||
var icuToIds = {};
|
||||
for (var id in ids) {
|
||||
icuToIds[ids[id]] = viewName + '-' + id;
|
||||
}
|
||||
return icuToIds;
|
||||
};
|
||||
|
||||
module.exports = Helpers;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue