mirror of https://github.com/espruino/BangleApps
Better support for translation, added some more common translations to German translation
parent
3cd15ab7e4
commit
1b266f7279
|
@ -6,9 +6,19 @@ See https://github.com/espruino/BangleApps/issues/1311
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var IGNORE_STRINGS = [
|
var IGNORE_STRINGS = [
|
||||||
"5x5",
|
"5x5","6x8","6x8:2","12x20","---","...",
|
||||||
"5x9Numeric7Seg",
|
"5x9Numeric7Seg",
|
||||||
"Vector"
|
"Vector",
|
||||||
|
"sortorder","tl","tr"
|
||||||
|
];
|
||||||
|
|
||||||
|
var IGNORE_FUNCTION_PARAMS = [
|
||||||
|
"read",
|
||||||
|
"readJSON",
|
||||||
|
"require",
|
||||||
|
"setFont",
|
||||||
|
"on",
|
||||||
|
"RegExp",
|
||||||
];
|
];
|
||||||
|
|
||||||
var BASEDIR = __dirname+"/../";
|
var BASEDIR = __dirname+"/../";
|
||||||
|
@ -40,7 +50,11 @@ try{
|
||||||
}
|
}
|
||||||
|
|
||||||
// Given a string value, work out if it's obviously not a text string
|
// Given a string value, work out if it's obviously not a text string
|
||||||
function isNotString(s) {
|
function isNotString(s, wasFnCall) {
|
||||||
|
// wasFnCall is set to the function name if 's' is the first argument to a function
|
||||||
|
if (wasFnCall && IGNORE_FUNCTION_PARAMS.includes(wasFnCall)) return true;
|
||||||
|
if (s=="Storage") console.log("isNotString",s,wasFnCall);
|
||||||
|
|
||||||
if (s.length<2) return true; // too short
|
if (s.length<2) return true; // too short
|
||||||
if (s.length>40) return true; // too long
|
if (s.length>40) return true; // too long
|
||||||
if (s[0]=="#") return true; // a color
|
if (s[0]=="#") return true; // a color
|
||||||
|
@ -51,53 +65,77 @@ function isNotString(s) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getTextFromString(s) {
|
||||||
|
return s.replace(/^([.<>\- ]*)([^<>\!\?]*?)([.<>\!\?\- ]*)$/,"$2");
|
||||||
|
}
|
||||||
|
|
||||||
// A string that *could* be translated?
|
// A string that *could* be translated?
|
||||||
var untranslatedStrings = [];
|
var untranslatedStrings = [];
|
||||||
// Strings that are marked with 'LANG'
|
// Strings that are marked with 'LANG'
|
||||||
var translatedStrings = [];
|
var translatedStrings = [];
|
||||||
|
|
||||||
|
function addString(list, str, file) {
|
||||||
|
str = getTextFromString(str);
|
||||||
|
var entry = list.find(e => e.str==str);
|
||||||
|
if (!entry) {
|
||||||
|
entry = { str:str, uses:0, files : [] };
|
||||||
|
list.push(entry);
|
||||||
|
}
|
||||||
|
entry.uses++;
|
||||||
|
if (!entry.files.includes(file))
|
||||||
|
entry.files.push(file)
|
||||||
|
}
|
||||||
|
|
||||||
console.log("Scanning apps...");
|
console.log("Scanning apps...");
|
||||||
|
//apps = apps.filter(a=>a.id=="wid_edit");
|
||||||
apps.forEach((app,appIdx) => {
|
apps.forEach((app,appIdx) => {
|
||||||
var appDir = APPSDIR+app.id+"/";
|
var appDir = APPSDIR+app.id+"/";
|
||||||
app.storage.forEach((file) => {
|
app.storage.forEach((file) => {
|
||||||
if (!file.url || !file.name.endsWith(".js")) return;
|
if (!file.url || !file.name.endsWith(".js")) return;
|
||||||
var fileContents = fs.readFileSync(appDir+file.url).toString();
|
var filePath = appDir+file.url;
|
||||||
|
var fileContents = fs.readFileSync(filePath).toString();
|
||||||
var lex = Espruino.Core.Utils.getLexer(fileContents);
|
var lex = Espruino.Core.Utils.getLexer(fileContents);
|
||||||
var lastIdx = 0;
|
var lastIdx = 0;
|
||||||
|
var wasFnCall = undefined; // set to 'setFont' if we're at soemthing like setFont(".."
|
||||||
var tok = lex.next();
|
var tok = lex.next();
|
||||||
while (tok!==undefined) {
|
while (tok!==undefined) {
|
||||||
var previousString = fileContents.substring(lastIdx, tok.startIdx);
|
var previousString = fileContents.substring(lastIdx, tok.startIdx);
|
||||||
|
//console.log(wasFnCall,tok.type,tok.value);
|
||||||
if (tok.type=="STRING") {
|
if (tok.type=="STRING") {
|
||||||
if (previousString.includes("/*LANG*/")) { // translated!
|
if (previousString.includes("/*LANG*/")) { // translated!
|
||||||
if (!translatedStrings.includes(tok.value))
|
addString(translatedStrings, tok.value, filePath);
|
||||||
translatedStrings.push(tok.value);
|
|
||||||
} else { // untranslated - potential to translate?
|
} else { // untranslated - potential to translate?
|
||||||
if (!isNotString(tok.value)) {
|
if (!isNotString(tok.value, wasFnCall)) {
|
||||||
if (!untranslatedStrings.includes(tok.value))
|
addString(untranslatedStrings, tok.value, filePath);
|
||||||
untranslatedStrings.push(tok.value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if (tok.value!="(") wasFnCall=undefined;
|
||||||
|
if (tok.type=="ID") wasFnCall=tok.value;
|
||||||
lastIdx = tok.endIdx;
|
lastIdx = tok.endIdx;
|
||||||
tok = lex.next();
|
tok = lex.next();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
untranslatedStrings.sort();
|
untranslatedStrings.sort((a,b)=>a.uses - b.uses);
|
||||||
translatedStrings.sort();
|
translatedStrings.sort((a,b)=>a.uses - b.uses);
|
||||||
|
untranslatedStrings.filter(e => e.uses>2); // ignore individual uses
|
||||||
|
|
||||||
var report = "";
|
var report = "";
|
||||||
/* // too many! don't output these
|
// too many! don't output these
|
||||||
log("Possible English Strings that could be translated");
|
log("Possible English Strings that could be translated");
|
||||||
log("=================================================================");
|
log("=================================================================");
|
||||||
log("");
|
log("");
|
||||||
log("Add these to IGNORE_STRINGS if the don't make sense...");
|
log("Add these to IGNORE_STRINGS if the don't make sense...");
|
||||||
log("");
|
log("");
|
||||||
log(untranslatedStrings.map(s=>JSON.stringify(s)).join(",\n"));*/
|
log(untranslatedStrings.map(e=>`${JSON.stringify(e.str)} (${e.uses} uses)`).join("\n"));
|
||||||
log("");
|
log("");
|
||||||
|
|
||||||
var languages = JSON.parse(fs.readFileSync(BASEDIR+"/lang/index.json").toString());
|
var languages = JSON.parse(fs.readFileSync(BASEDIR+"/lang/index.json").toString());
|
||||||
languages.forEach(language => {
|
languages.forEach(language => {
|
||||||
|
if (language.code=="en_GB") {
|
||||||
|
console.log("Ignoring "+language.code);
|
||||||
|
return;
|
||||||
|
}
|
||||||
console.log("Scanning "+language.code);
|
console.log("Scanning "+language.code);
|
||||||
log(language.code);
|
log(language.code);
|
||||||
log("==========");
|
log("==========");
|
||||||
|
|
2
core
2
core
|
@ -1 +1 @@
|
||||||
Subproject commit 649489412e27ef770bc0c8ed12cfca6a17a98c0d
|
Subproject commit daedea685620abea71c0f876b234fe1dd553d3a2
|
|
@ -14,7 +14,13 @@
|
||||||
"Sleep" : "Schlummern",
|
"Sleep" : "Schlummern",
|
||||||
"Alarms" : "Wecker",
|
"Alarms" : "Wecker",
|
||||||
"New Alarm" : "Neuer Wecker",
|
"New Alarm" : "Neuer Wecker",
|
||||||
"ALARM!" : "ALARM!"
|
"ALARM!" : "ALARM!",
|
||||||
|
"Yes" : "Ja",
|
||||||
|
"No" : "Nein",
|
||||||
|
"On" : "Auf",
|
||||||
|
"Off" : "aus",
|
||||||
|
"Ok" : "OK",
|
||||||
|
"Back" : "zurück"
|
||||||
},
|
},
|
||||||
"alarm": {
|
"alarm": {
|
||||||
"//":"App-specific overrides",
|
"//":"App-specific overrides",
|
||||||
|
|
Loading…
Reference in New Issue