Show the desktop shell in Chinese under zh_CN
This commit is contained in:
1 parent
e590f22de6
commit
e236713d9f
55 files changed
+867
-331
No files matched your search
@@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
|
||||
|
||||
run_node_test <<'JS'
|
||||
const fs = require('fs')
|
||||
const vm = require('vm')
|
||||
|
||||
const source = fs.readFileSync(path.join(root, 'shell/Commons/I18nZh.js'), 'utf8').replace('.pragma library', '')
|
||||
const context = {}
|
||||
vm.runInNewContext(source + '\nthis.table = table', context)
|
||||
const table = context.table
|
||||
|
||||
const files = []
|
||||
const walk = dir => {
|
||||
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
||||
const full = path.join(dir, entry.name)
|
||||
if (entry.isDirectory()) walk(full)
|
||||
else if (/\.(qml|js)$/.test(entry.name)) files.push(full)
|
||||
}
|
||||
}
|
||||
walk(path.join(root, 'shell'))
|
||||
|
||||
const missing = []
|
||||
let calls = 0
|
||||
for (const file of files) {
|
||||
const text = fs.readFileSync(file, 'utf8')
|
||||
for (const match of text.matchAll(/I18n\.tr\(\s*"((?:[^"\\]|\\.)*)"/g)) {
|
||||
calls++
|
||||
const key = JSON.parse('"' + match[1] + '"')
|
||||
if (!(key in table)) missing.push(`${path.relative(root, file)}: ${key}`)
|
||||
}
|
||||
}
|
||||
assert(calls > 300, 'the shell routes its text through I18n.tr', `found ${calls} calls`)
|
||||
assert(missing.length === 0, 'every I18n.tr text has a Chinese entry', missing.join('\n'))
|
||||
|
||||
const placeholders = s => (s.match(/%\d/g) || []).sort().join(',')
|
||||
const mismatched = Object.keys(table).filter(key => placeholders(key) !== placeholders(table[key]))
|
||||
assert(mismatched.length === 0, 'every Chinese entry keeps its English placeholders', mismatched.join('\n'))
|
||||
JS
|
||||
Reference in new issue
Block a user