Skip to content

Commit

Permalink
Introduce translation automation
Browse files Browse the repository at this point in the history
  • Loading branch information
Spredzy committed Jan 14, 2021
1 parent b61dd79 commit 45e1023
Show file tree
Hide file tree
Showing 17 changed files with 80 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
TRANSLATED_FOLDERS := $(shell find . -name 'po4a.cfg' -exec dirname {} \;)
EXISTING_PO_FILES := $(shell find . -name '*.po')

show-translated-folders:
@echo $(TRANSLATED_FOLDERS)

.SILENT:
generate-po:
for translated_folder in $(TRANSLATED_FOLDERS); do \
pushd 2>&1>/dev/null $$translated_folder && \
po4a po4a.cfg --no-translations 2>&1>/dev/null && \
popd 2>&1>/dev/null ; \
done

.SILENT:
list-po-needs-translation:
for file in $(EXISTING_PO_FILES); do \
python pooneliner.py $$file ; \
done

.SILENT:
translation:
for translated_folder in $(TRANSLATED_FOLDERS); do \
pushd 2>&1>/dev/null $$translated_folder && \
po4a po4a.cfg --no-update 2>&1>/dev/null && \
popd 2>&1>/dev/null ; \
done

.SILENT:
translation-clean:
for translated_folder in $(TRANSLATED_FOLDERS); do \
pushd 2>&1>/dev/null $$translated_folder && \
rm -rf locales && \
popd 2>&1>/dev/null ; \
done

1 change: 1 addition & 0 deletions exercises/ansible_rhel/1.1-setup/po4a.cfg
1 change: 1 addition & 0 deletions exercises/ansible_rhel/1.2-adhoc/po4a.cfg
1 change: 1 addition & 0 deletions exercises/ansible_rhel/1.3-playbook/po4a.cfg
1 change: 1 addition & 0 deletions exercises/ansible_rhel/1.4-variables/po4a.cfg
1 change: 1 addition & 0 deletions exercises/ansible_rhel/1.5-handlers/po4a.cfg
1 change: 1 addition & 0 deletions exercises/ansible_rhel/1.6-templates/po4a.cfg
1 change: 1 addition & 0 deletions exercises/ansible_rhel/1.7-role/po4a.cfg
1 change: 1 addition & 0 deletions exercises/ansible_rhel/2.1-intro/po4a.cfg
1 change: 1 addition & 0 deletions exercises/ansible_rhel/2.2-cred/po4a.cfg
1 change: 1 addition & 0 deletions exercises/ansible_rhel/2.3-projects/po4a.cfg
1 change: 1 addition & 0 deletions exercises/ansible_rhel/2.4-surveys/po4a.cfg
1 change: 1 addition & 0 deletions exercises/ansible_rhel/2.5-rbac/po4a.cfg
1 change: 1 addition & 0 deletions exercises/ansible_rhel/2.6-workflows/po4a.cfg
1 change: 1 addition & 0 deletions exercises/ansible_rhel/2.7-wrap/po4a.cfg
4 changes: 4 additions & 0 deletions po4a.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[options] --keep 0 --wrap-po no --master-charset UTF-8 --localized-charset UTF-8 --master-language en
[po4a_langs] ja zh
[po4a_paths] locales/README.pot $lang:locales/README.$lang.po
[type: text] README.md $lang:README.$lang.md opt:"-o markdown"
26 changes: 26 additions & 0 deletions pooneliner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python

import io
import sys
from babel.messages import pofile


def main():

filename = sys.argv[1]

with io.open(filename, 'rb') as f:
cat = pofile.read_po(f)
charset = cat.charset or 'utf-8'

with io.open(filename, 'rb') as f:
my_catalog = pofile.read_po(f, charset=charset)
fuzzy_entries = len([m for m in my_catalog if m.id and m.fuzzy])
untranslated_entries = len([m for m in my_catalog if m.id and not m.string])

if fuzzy_entries or untranslated_entries:
print(filename)


if __name__ == "__main__":
main()

0 comments on commit 45e1023

Please sign in to comment.