Lukáš Tinkl 639a70b611 fix(l10n): fix strings extraction
- handle `SOURCES` recursively, rather than spelling all the paths out;
most of them were outdated and some still missing
- let the Python script skip existing translations (in case we need to
manually add plurals)
- updated qml_en.ts as a result of these changes

Stats:
```
Updating '../../ui/i18n/qml_en.ts'...
    Found 1703 source text(s) (109 new and 1594 already existing)
    Kept 35 obsolete entries
    Same-text heuristic provided 35 translation(s)
```
2022-07-21 15:57:59 -04:00

32 lines
996 B
Python

import xml.etree.ElementTree as ET
import subprocess
# 1) Runs lupdate ../../ui/nim-status-client.pro -target-language en
# 2) Fixups qml_en.ts: ensure each source has translation, otherwise Lokalise can't figure out base words
#
# usage: `python update-en-ts.py`
def fixupTranslations(enTsFile: str):
tsXmlTree = ET.parse(enTsFile)
messageNodes = tsXmlTree.findall('.//message')
for messageNode in messageNodes:
enString = messageNode.find('source').text
trNode = messageNode.find('translation')
if not trNode.text:
trNode.text = enString # add translation
trNode.attrib = {} # remove 'type="unfinished"'
tsXmlTree.write(enTsFile)
if __name__ == "__main__":
p = subprocess.run(['lupdate', '../../ui/nim-status-client.pro', '-target-language', 'en'],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, check=True, text=True)
print(p.stdout)
fixupTranslations('../../ui/i18n/qml_en.ts')