Files
omarchy/shell/Commons/Tr.js
T
ZacharyZhang-NY a9b39710a2 Add Simplified Chinese as a system language
The installer asks for the language before the keyboard, and
Setup > Language (omarchy language en|zh) switches it later. Under
zh_CN the menu reads its labels from omarchy-menu.zh-cn.jsonc, the
shell from I18nZh.js through I18n.tr, and notifications are worded
by their sender through omarchy-text, which reads the same table.
User text is never translated.
2026-10-12 02:56:40 -04:00

25 lines
1023 B
JavaScript

.pragma library
.import "I18nZh.js" as Zh
// Shell text in the session's language; QML reaches this through the I18n singleton, plain JS imports it.
var chinese = Qt.locale().name.indexOf("zh_CN") === 0
function tr(text) {
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 a panel's own model builds in known formats: the first matching template 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)
}