fix(ui): 校正三语指标文案并核对构建包译文
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
"""Validate catalog coverage and printf argument compatibility against zh-Hans."""
|
||||
"""Validate catalog coverage and printf argument compatibility in the source catalogs and optionally the compiled app."""
|
||||
import argparse
|
||||
import collections
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
|
||||
root = Path(__file__).resolve().parents[1] / 'kymo/Resources'
|
||||
pattern = re.compile(r'%(?:(\d+)\$)?[-+#0 ]*(?:\d+)?(?:\.\d+)?(ll|l|h)?([@diuoxXfFeEgGcCsSp])')
|
||||
@@ -13,13 +15,25 @@ def arguments(text):
|
||||
result[(int(match[1] or index), (match[2] or '') + match[3])] += 1
|
||||
return result
|
||||
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--app', type=Path, help='Also compare every translation with the built app')
|
||||
app = parser.parse_args().app
|
||||
locales = ('zh-Hans', 'en', 'zh-Hant')
|
||||
count = 0
|
||||
for path in sorted(root.glob('*.xcstrings')):
|
||||
compiled = {}
|
||||
if app:
|
||||
for locale in locales:
|
||||
table = app / 'Contents' / 'Resources' / f'{locale}.lproj' / f'{path.stem}.strings'
|
||||
compiled[locale] = json.loads(subprocess.check_output(['plutil', '-convert', 'json', '-o', '-', table]))
|
||||
for key, entry in json.loads(path.read_text())['strings'].items():
|
||||
units = {locale: entry['localizations'][locale]['stringUnit']
|
||||
for locale in ['zh-Hans', 'en', 'zh-Hant']}
|
||||
for locale in locales}
|
||||
expected = arguments(key) or arguments(units['en']['value'])
|
||||
for locale, unit in units.items():
|
||||
assert unit['state'] == 'translated' and unit['value'].strip(), (path, key, locale)
|
||||
assert arguments(unit['value']) == arguments(units['zh-Hans']['value']), (path, key, locale)
|
||||
assert arguments(unit['value']) == expected, (path, key, locale)
|
||||
if app:
|
||||
assert compiled[locale].get(key) == unit['value'], (path, key, locale, 'built translation')
|
||||
count += 1
|
||||
print(f'PASS: {count} catalog entries, three-language coverage and format arguments')
|
||||
|
||||
@@ -36,7 +36,12 @@ import Foundation
|
||||
let expected = ["en": "Fan", "zh-Hans": "风扇", "zh-Hant": "風扇"][language]!
|
||||
precondition(title == "\(expected) \(number)", "Numbered fan must use the selected app locale")
|
||||
}
|
||||
|
||||
let minutes = AppLocalization.string("duration.minutes %lld", locale: locale, bundle: bundle)
|
||||
let hours = AppLocalization.string("duration.hours %@", locale: locale, bundle: bundle)
|
||||
let durations = [String(format: minutes, Int64(45)), String(format: hours, "1.5")]
|
||||
let expectedDurations = ["en": ["45 min", "1.5 h"], "zh-Hans": ["45 分钟", "1.5 小时"],
|
||||
"zh-Hant": ["45 分鐘", "1.5 小時"]]
|
||||
precondition(durations == expectedDurations[language])
|
||||
}
|
||||
print("PASS: system matching, explicit override, fallback, preference roundtrip, built three-language resources")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user