From d51fa29acdff882787f6ff293b739f4a627f5870 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 26 Jan 2020 14:29:28 +0530 Subject: [PATCH] Also generate ISO 639 POT file automatically from the db. Fixes #1860856 [String not found in Transifex](https://bugs.launchpad.net/calibre/+bug/1860856) --- setup/translations.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/setup/translations.py b/setup/translations.py index dd003a3de9..78e1e94407 100644 --- a/setup/translations.py +++ b/setup/translations.py @@ -91,6 +91,28 @@ class POT(Command): # {{{ return '\n'.join(ans) + def get_iso639_strings(self): + self.info('Generating translation template for iso639') + src = self.j(self.d(self.SRC), 'setup', 'iso_639-3.json') + if not os.path.exists(src): + raise Exception(src + ' does not exist') + with open(src, 'rb') as f: + root = json.load(f) + entries = root['639-3'] + ans = [] + for x in sorted(entries, key=lambda x:(x.get('name') or '').lower()): + name = x.get('name') + if name: + ans.append(u'msgid "{}"'.format(name)) + ans.append('msgstr ""') + ans.append('') + pot = self.pot_header() + '\n\n' + '\n'.join(ans) + dest = self.j(self.TRANSLATIONS, 'iso_639', 'iso_639_3.pot') + with open(dest, 'wb') as f: + f.write(pot.encode('utf-8')) + self.upload_pot(resource='iso639') + self.git(['add', dest]) + def get_content_server_strings(self): self.info('Generating translation template for content_server') from calibre import walk @@ -182,6 +204,7 @@ class POT(Command): # {{{ def run(self, opts): require_git_master() + self.get_iso639_strings() self.get_website_strings() self.get_content_server_strings() self.get_user_manual_docs()