Add warnings about duplicate keyboard shortcuts when building translations (close #7185)

Update translations
This commit is contained in:
Quincy Morgan
2019-12-31 11:40:41 -05:00
parent 48f4462d5f
commit c8ce5eb8bb
24 changed files with 2657 additions and 172 deletions
+55
View File
@@ -3,6 +3,7 @@ const fs = require('fs');
const prettyStringify = require('json-stringify-pretty-compact');
const request = require('request').defaults({ maxSockets: 1 });
const YAML = require('js-yaml');
const colors = require('colors/safe');
const resources = ['core', 'presets', 'imagery', 'community'];
const outdir = './dist/locales/';
@@ -27,6 +28,8 @@ const sourcePresets = YAML.load(fs.readFileSync('./data/presets.yaml', 'utf8'));
const sourceImagery = YAML.load(fs.readFileSync('./node_modules/editor-layer-index/i18n/en.yaml', 'utf8'));
const sourceCommunity = YAML.load(fs.readFileSync('./node_modules/osm-community-index/i18n/en.yaml', 'utf8'));
const dataShortcuts = JSON.parse(fs.readFileSync('./data/shortcuts.json', 'utf8')).dataShortcuts;
const cldrMainDir = './node_modules/cldr-localenames-full/main/';
var referencedScripts = [];
@@ -36,6 +39,26 @@ const languageInfo = {
};
fs.writeFileSync('data/languages.json', JSON.stringify(languageInfo, null, 4));
var shortcuts = [];
dataShortcuts.forEach(function(tab) {
tab.columns.forEach(function(col) {
col.rows.forEach(function(row) {
if (!row.shortcuts) return;
row.shortcuts.forEach(function(shortcut) {
if (shortcut.includes('.')) {
var info = {
shortcut: shortcut
};
if (row.modifiers) {
info.modifier = row.modifiers.join('');
}
shortcuts.push(info);
}
});
});
});
});
asyncMap(resources, getResource, function(err, results) {
if (err) return console.log(err);
@@ -133,6 +156,8 @@ function getResource(resource, callback) {
}
}
}
} else if (resource === 'core') {
checkForDuplicateShortcuts(codes[i], result);
}
locale[codes[i]] = result;
@@ -212,6 +237,36 @@ function asyncMap(inputs, func, callback) {
}
}
function checkForDuplicateShortcuts(code, coreStrings) {
var usedShortcuts = {};
shortcuts.forEach(function(shortcutInfo) {
var shortcutPathString = shortcutInfo.shortcut;
var modifier = shortcutInfo.modifier || '';
var path = shortcutPathString
.split('.')
.map(function (s) { return s.replace(/<TX_DOT>/g, '.'); })
.reverse();
var rep = coreStrings;
while (rep !== undefined && path.length) {
rep = rep[path.pop()];
}
if (rep !== undefined) {
var shortcut = modifier + rep;
if (usedShortcuts[shortcut] && usedShortcuts[shortcut] !== shortcutPathString) {
var message = code + ': duplicate shortcut "' + shortcut + '" for "' + usedShortcuts[shortcut] + '" and "' + shortcutPathString + '"';
console.warn(colors.yellow(message));
} else {
usedShortcuts[shortcut] = shortcutPathString;
}
}
});
}
function getLangNamesInNativeLang() {
// manually add languages we want that aren't in CLDR
var unordered = {