mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-12-17 19:12:40 -05:00
fa566ac140
Since it's using `require` to get the localisation strings, check if the error is `MODULE_NOT_FOUND` before moving on – because if it isn't, then there is an unknown error that should be thrown. Thanks @rschamp for the suggestion!
72 lines
2.3 KiB
JavaScript
72 lines
2.3 KiB
JavaScript
/*
|
|
* spot checks the translation of the nav bar for a select set
|
|
* of languages that cover a number of types of translations.
|
|
*
|
|
* Languages checked:
|
|
* - Hebrew
|
|
* - Edible Scratch (fake language)
|
|
* - Mandarin
|
|
* - Japanese
|
|
* - Brasilian Portuguese
|
|
* - Polish
|
|
* - Norwegian
|
|
* - German
|
|
*/
|
|
var path = require('path');
|
|
var tap = require('tap');
|
|
|
|
var localeCompare = require('../../bin/lib/locale-compare');
|
|
var languagesToCheck = [
|
|
'he', 'zh-cn', 'ja', 'pt-br', 'pl', 'nb'
|
|
];
|
|
var idsToCheck = [
|
|
'general.about', 'general.create', 'general.help', 'general.joinScratch',
|
|
'general.signIn', 'general.discuss'
|
|
];
|
|
|
|
|
|
var ids = require(path.resolve(__dirname, '../../src/l10n.json'));
|
|
var viewLocales = {
|
|
general: {en: ids}
|
|
};
|
|
var idsWithICU = localeCompare.idToICUMap('general', ids);
|
|
var icuWithIds = localeCompare.icuToIdMap('general', ids);
|
|
var md5WithIds = localeCompare.getMD5Map(icuWithIds);
|
|
|
|
tap.test('spotCheckNavBar', function (t) {
|
|
for (var i in languagesToCheck) {
|
|
var translations = localeCompare.getTranslationsForLanguage(languagesToCheck[i], idsWithICU, md5WithIds);
|
|
for (var j in idsToCheck) {
|
|
t.notEqual(
|
|
translations['general'][languagesToCheck[i]][idsToCheck[j]],
|
|
viewLocales['general']['en'][idsToCheck[j]],
|
|
'check localization of ' + idsToCheck[j] + ' for ' + languagesToCheck[i]
|
|
);
|
|
}
|
|
}
|
|
t.end();
|
|
});
|
|
|
|
|
|
// Test splash items for fake language.
|
|
var fakeLanguageIdsToCheck = ['news.scratchNews', 'splash.featuredProjects', 'splash.featuredStudios'];
|
|
|
|
ids = require(path.resolve(__dirname, '../../src/views/splash/l10n.json'));
|
|
viewLocales = {
|
|
splash: {en: ids}
|
|
};
|
|
idsWithICU = localeCompare.idToICUMap('splash', ids);
|
|
icuWithIds = localeCompare.icuToIdMap('splash', ids);
|
|
md5WithIds = localeCompare.getMD5Map(icuWithIds);
|
|
|
|
tap.test('spotCheckNavBarFakeLanguage', function (t) {
|
|
var translations = localeCompare.getTranslationsForLanguage('yum', idsWithICU, md5WithIds);
|
|
for (var i in fakeLanguageIdsToCheck) {
|
|
t.notEqual(
|
|
translations['splash']['yum'][fakeLanguageIdsToCheck[i]],
|
|
viewLocales['splash']['en'][fakeLanguageIdsToCheck[i]],
|
|
'check localization of ' + fakeLanguageIdsToCheck[i] + ' for yum'
|
|
);
|
|
}
|
|
t.end();
|
|
});
|