Skip to content

Commit

Permalink
Update translation scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelarnauts committed Mar 24, 2021
1 parent 9483a24 commit 513e25d
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.env.example export-ignore
.github/ export-ignore
scripts/ export-ignore
tests/ export-ignore
.gitattributes export-ignore
.gitignore export-ignore
Expand Down
6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ check-translations:
@$(foreach lang,$(languages), \
msgcmp --use-untranslated resources/language/resource.language.$(lang)/strings.po resources/language/resource.language.en_gb/strings.po; \
)
@tests/check_for_unused_translations.py
@scripts/check_for_unused_translations.py

update-translations:
@printf ">>> Updating languages\n"
@-$(foreach lang,$(languages), \
tests/update_translations.py resources/language/resource.language.$(lang)/strings.po resources/language/resource.language.en_gb/strings.po; \
)
@scripts/update_translations.py

check-addon: clean build
@printf ">>> Running addon checks\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
# Load po file
po = polib.pofile('resources/language/resource.language.en_gb/strings.po')
for entry in po:
# Skip empty translations
if entry.msgid == '':
continue

# Extract msgctxt
msgctxt = entry.msgctxt.lstrip('#')

Expand Down
40 changes: 40 additions & 0 deletions scripts/update_translations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# pylint: disable=missing-docstring,no-self-use,wrong-import-order,wrong-import-position,invalid-name

import sys
from glob import glob

import polib

original_file = 'resources/language/resource.language.en_gb/strings.po'
original = polib.pofile(original_file, wrapwidth=0)

for translated_file in glob('resources/language/resource.language.*/strings.po'):
# Skip original file
if translated_file == original_file:
continue
print('Updating %s...' % translated_file)

# Load po-files
translated = polib.pofile(translated_file, wrapwidth=0)

for entry in original:
# Find a translation
translation = translated.find(entry.msgctxt, 'msgctxt')

if translation and entry.msgid == translation.msgid:
entry.msgstr = translation.msgstr

original.metadata = translated.metadata

if sys.platform.startswith('win'):
# On Windows save the file keeping the Linux return character
with open(translated_file, 'wb') as _file:
content = str(original).encode('utf-8')
content = content.replace(b'\r\n', b'\n')
_file.write(content)
else:
# Save it now over the translation
original.save(translated_file)
31 changes: 0 additions & 31 deletions tests/update_translations.py

This file was deleted.

0 comments on commit 513e25d

Please sign in to comment.