Translate the remaining shell text at display and keep translated values out of logic
This commit is contained in:
1 parent
e236713d9f
commit
2b2302a279
17 files changed
+112
-25
No files matched your search
+16
-3
@@ -5,7 +5,20 @@
|
||||
var chinese = Qt.locale().name.indexOf("zh_CN") === 0
|
||||
|
||||
function tr(text) {
|
||||
var out = chinese && Zh.table[text] !== undefined ? Zh.table[text] : text
|
||||
for (var i = 1; i < arguments.length; i++) out = out.split("%" + i).join(String(arguments[i]))
|
||||
return out
|
||||
var args = arguments
|
||||
var template = chinese && Object.prototype.hasOwnProperty.call(Zh.table, text) ? Zh.table[text] : text
|
||||
// One pass, so an argument that itself contains %2 stays as given.
|
||||
return String(template).replace(/%(\d)/g, function(match, n) {
|
||||
return n > 0 && n < args.length ? String(args[n]) : match
|
||||
})
|
||||
}
|
||||
|
||||
// Text built elsewhere around a name: the first English template that matches is translated with what %1.. captured.
|
||||
function trMatch(text, templates) {
|
||||
for (var i = 0; i < templates.length; i++) {
|
||||
var pattern = "^" + templates[i].replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/%\d/g, "(.+?)") + "$"
|
||||
var match = String(text).match(new RegExp(pattern))
|
||||
if (match) return tr.apply(null, [templates[i]].concat(match.slice(1)))
|
||||
}
|
||||
return tr(text)
|
||||
}
|
||||
Reference in new issue
Block a user