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')
|
||||
|
||||
Reference in New Issue
Block a user