Skip to content

Commit

Permalink
check translations in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
guruofgentoo committed May 14, 2020
1 parent 0505daa commit 825d32e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 51 deletions.
59 changes: 9 additions & 50 deletions keg_auth_ta/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,55 +19,14 @@ def command_extension():

@app.cli.command('verify-translations', help='Verifies all strings marked for translation')
def verify_translations():
# This method is intended for a CI check on translations. To make it work, we'd have to
# pin Babel to 2.6, though, so I'll hold off on the CI usage.
from keg_auth.extensions import Manager, translation_manager

def clone_manager(locales=None):
manager = translation_manager

return Manager(dirname=manager.dirname, locales=locales or manager.locales,
domain=manager.domain, package_name=manager.package_name)

# The following strings can be treated as false positives below, since the translation will
# equal the original string
ignored_strings = {
'Email',
}
from pathlib import Path
from morphi.messages.validation import check_translations

root_path = Path(__file__).resolve().parent.parent
setup_py = str(root_path / 'setup.py')
subprocess.run(['python', setup_py, 'extract_messages'])
subprocess.run(['python', setup_py, 'update_catalog', '--no-fuzzy-matching'])
subprocess.run(['python', setup_py, 'compile_catalog'])
subprocess.run(['python', setup_py, 'compile_json'])

found_fuzzy = False
untranslated_strings = []

# check for fuzzy matches
po_path = root_path / 'keg_auth' / 'i18n' / 'es' / 'LC_MESSAGES' / 'keg_auth.po'
with open(po_path, mode='rb') as fp:
contents = fp.read()
found_fuzzy = b'#, fuzzy' in contents

manager = clone_manager(locales=['es'])
catalog = manager.translations._catalog
for key, value in catalog.items():
if key and key == value and key not in ignored_strings:
untranslated_strings.append(key)

# note: the strings below are intentionally left untranslated
if found_fuzzy:
print('Detected fuzzy translations.')

if untranslated_strings:
print('Did not find translations for the following strings:')
for item in untranslated_strings:
print(' ', item)

if found_fuzzy or untranslated_strings:
print('Edit the PO file and compile the catalogs.')
sys.exit(1)

print('No detected translation issues.')
check_translations(
root_path,
'keg_auth',
ignored_strings = {
'Email',
}
)
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
# $ pip install -e .[dev,test]
extras_require={
'test': [
'email_validator',
'flake8',
'flask-bootstrap',
'flask-jwt-extended',
Expand Down
9 changes: 8 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# and also to help confirm pull requests to this project.

[tox]
envlist = py{36,37,38}-{base,i18n},flake8,project
envlist = py{36,37,38}-{base,i18n},flake8,project,i18n


[testenv]
Expand Down Expand Up @@ -62,6 +62,13 @@ commands =
flake8 keg_auth


[testenv:i18n]
skip_install = true
commands =
pip install .[test,i18n]
python keg_auth_ta/app.py --profile=TestProfile verify-translations


[flake8]
exclude = .tox,*egg,build,git,dist
select = E,W,F
Expand Down

0 comments on commit 825d32e

Please sign in to comment.