diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-03-27 07:41:16 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-03-27 07:41:16 +0200 |
commit | 62d4496931cf17b240022ffcf48bf27e27c5e605 (patch) | |
tree | b8fb95e07f840f66b53a8a158b2ee58e5e4dd521 /po | |
parent | 4083bcc2e39ee6a00e6342f7dca72e52f660e2c0 (diff) |
Lang: Get missing strings from base language
IssueID #192
Diffstat (limited to 'po')
-rwxr-xr-x | po/compile.py | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/po/compile.py b/po/compile.py index 0bda0a07..a78859a4 100755 --- a/po/compile.py +++ b/po/compile.py | |||
@@ -13,6 +13,7 @@ ESCAPES = { | |||
13 | 'r': '\r', | 13 | 'r': '\r', |
14 | 't': '\t' | 14 | 't': '\t' |
15 | } | 15 | } |
16 | BASE_STRINGS = {} | ||
16 | 17 | ||
17 | if '--new' in sys.argv: | 18 | if '--new' in sys.argv: |
18 | MODE = 'new' | 19 | MODE = 'new' |
@@ -80,21 +81,35 @@ def parse_po(src): | |||
80 | #print(msg_id, '=>', msg_str) | 81 | #print(msg_id, '=>', msg_str) |
81 | return pluralized | 82 | return pluralized |
82 | 83 | ||
83 | 84 | ||
85 | def compile_string(msg_id, msg_str): | ||
86 | return msg_id.encode('utf-8') + bytes([0]) + \ | ||
87 | msg_str.encode('utf-8') + bytes([0]) | ||
88 | |||
89 | |||
84 | if MODE == 'compile': | 90 | if MODE == 'compile': |
91 | for msg_id, msg_str in parse_po('en.po'): | ||
92 | BASE_STRINGS[msg_id] = msg_str | ||
85 | for src in os.listdir('.'): | 93 | for src in os.listdir('.'): |
86 | if src.endswith('.po') and src.split('.')[0] in BUILD_LANGS: | 94 | if src.endswith('.po') and src.split('.')[0] in BUILD_LANGS: |
87 | # Make a binary blob with strings sorted by ID. | 95 | # Make a binary blob with strings sorted by ID. |
96 | have_ids = set() | ||
88 | compiled = bytes() | 97 | compiled = bytes() |
89 | for msg in sorted(parse_po(src)): | 98 | lang = parse_po(src) |
90 | compiled += msg[0].encode('utf-8') + bytes([0]) | 99 | for msg_id, _ in lang: |
91 | compiled += msg[1].encode('utf-8') + bytes([0]) | 100 | have_ids.add(msg_id) |
101 | # Take missing strings from the base language. | ||
102 | for msg_id in BASE_STRINGS: | ||
103 | if msg_id not in have_ids: | ||
104 | print(src, 'missing:', msg_id) | ||
105 | lang.append((msg_id, BASE_STRINGS[msg_id])) | ||
106 | for msg_id, msg_str in sorted(lang): | ||
107 | compiled += compile_string(msg_id, msg_str) | ||
92 | open(f'../res/lang/{src[:-3]}.bin', 'wb').write(compiled) | 108 | open(f'../res/lang/{src[:-3]}.bin', 'wb').write(compiled) |
93 | 109 | ||
94 | elif MODE == 'new': | 110 | elif MODE == 'new': |
95 | messages = parse_po('en.po') | 111 | messages = parse_po('en.po') |
96 | f = open('new.po', 'wt', encoding='utf-8') | 112 | f = open('new.po', 'wt', encoding='utf-8') |
97 | # TODO: plurals | ||
98 | for msg_id, _ in messages: | 113 | for msg_id, _ in messages: |
99 | print(f'\nmsgid "{msg_id}"\nmsgstr ""\n', file=f) | 114 | print(f'\nmsgid "{msg_id}"\nmsgstr ""\n', file=f) |
100 | 115 | ||