From 45e10234eceddc08c03ff2965f9bd2e765ea0f53 Mon Sep 17 00:00:00 2001 From: Yanis Guenane Date: Mon, 28 Dec 2020 00:18:15 +0100 Subject: [PATCH] Introduce translation automation --- Makefile | 36 +++++++++++++++++++ exercises/ansible_rhel/1.1-setup/po4a.cfg | 1 + exercises/ansible_rhel/1.2-adhoc/po4a.cfg | 1 + exercises/ansible_rhel/1.3-playbook/po4a.cfg | 1 + exercises/ansible_rhel/1.4-variables/po4a.cfg | 1 + exercises/ansible_rhel/1.5-handlers/po4a.cfg | 1 + exercises/ansible_rhel/1.6-templates/po4a.cfg | 1 + exercises/ansible_rhel/1.7-role/po4a.cfg | 1 + exercises/ansible_rhel/2.1-intro/po4a.cfg | 1 + exercises/ansible_rhel/2.2-cred/po4a.cfg | 1 + exercises/ansible_rhel/2.3-projects/po4a.cfg | 1 + exercises/ansible_rhel/2.4-surveys/po4a.cfg | 1 + exercises/ansible_rhel/2.5-rbac/po4a.cfg | 1 + exercises/ansible_rhel/2.6-workflows/po4a.cfg | 1 + exercises/ansible_rhel/2.7-wrap/po4a.cfg | 1 + po4a.cfg | 4 +++ pooneliner.py | 26 ++++++++++++++ 17 files changed, 80 insertions(+) create mode 100644 Makefile create mode 120000 exercises/ansible_rhel/1.1-setup/po4a.cfg create mode 120000 exercises/ansible_rhel/1.2-adhoc/po4a.cfg create mode 120000 exercises/ansible_rhel/1.3-playbook/po4a.cfg create mode 120000 exercises/ansible_rhel/1.4-variables/po4a.cfg create mode 120000 exercises/ansible_rhel/1.5-handlers/po4a.cfg create mode 120000 exercises/ansible_rhel/1.6-templates/po4a.cfg create mode 120000 exercises/ansible_rhel/1.7-role/po4a.cfg create mode 120000 exercises/ansible_rhel/2.1-intro/po4a.cfg create mode 120000 exercises/ansible_rhel/2.2-cred/po4a.cfg create mode 120000 exercises/ansible_rhel/2.3-projects/po4a.cfg create mode 120000 exercises/ansible_rhel/2.4-surveys/po4a.cfg create mode 120000 exercises/ansible_rhel/2.5-rbac/po4a.cfg create mode 120000 exercises/ansible_rhel/2.6-workflows/po4a.cfg create mode 120000 exercises/ansible_rhel/2.7-wrap/po4a.cfg create mode 100644 po4a.cfg create mode 100755 pooneliner.py diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..7b309dacf --- /dev/null +++ b/Makefile @@ -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 + diff --git a/exercises/ansible_rhel/1.1-setup/po4a.cfg b/exercises/ansible_rhel/1.1-setup/po4a.cfg new file mode 120000 index 000000000..cce0d185c --- /dev/null +++ b/exercises/ansible_rhel/1.1-setup/po4a.cfg @@ -0,0 +1 @@ +../../../po4a.cfg \ No newline at end of file diff --git a/exercises/ansible_rhel/1.2-adhoc/po4a.cfg b/exercises/ansible_rhel/1.2-adhoc/po4a.cfg new file mode 120000 index 000000000..cce0d185c --- /dev/null +++ b/exercises/ansible_rhel/1.2-adhoc/po4a.cfg @@ -0,0 +1 @@ +../../../po4a.cfg \ No newline at end of file diff --git a/exercises/ansible_rhel/1.3-playbook/po4a.cfg b/exercises/ansible_rhel/1.3-playbook/po4a.cfg new file mode 120000 index 000000000..cce0d185c --- /dev/null +++ b/exercises/ansible_rhel/1.3-playbook/po4a.cfg @@ -0,0 +1 @@ +../../../po4a.cfg \ No newline at end of file diff --git a/exercises/ansible_rhel/1.4-variables/po4a.cfg b/exercises/ansible_rhel/1.4-variables/po4a.cfg new file mode 120000 index 000000000..cce0d185c --- /dev/null +++ b/exercises/ansible_rhel/1.4-variables/po4a.cfg @@ -0,0 +1 @@ +../../../po4a.cfg \ No newline at end of file diff --git a/exercises/ansible_rhel/1.5-handlers/po4a.cfg b/exercises/ansible_rhel/1.5-handlers/po4a.cfg new file mode 120000 index 000000000..cce0d185c --- /dev/null +++ b/exercises/ansible_rhel/1.5-handlers/po4a.cfg @@ -0,0 +1 @@ +../../../po4a.cfg \ No newline at end of file diff --git a/exercises/ansible_rhel/1.6-templates/po4a.cfg b/exercises/ansible_rhel/1.6-templates/po4a.cfg new file mode 120000 index 000000000..cce0d185c --- /dev/null +++ b/exercises/ansible_rhel/1.6-templates/po4a.cfg @@ -0,0 +1 @@ +../../../po4a.cfg \ No newline at end of file diff --git a/exercises/ansible_rhel/1.7-role/po4a.cfg b/exercises/ansible_rhel/1.7-role/po4a.cfg new file mode 120000 index 000000000..cce0d185c --- /dev/null +++ b/exercises/ansible_rhel/1.7-role/po4a.cfg @@ -0,0 +1 @@ +../../../po4a.cfg \ No newline at end of file diff --git a/exercises/ansible_rhel/2.1-intro/po4a.cfg b/exercises/ansible_rhel/2.1-intro/po4a.cfg new file mode 120000 index 000000000..cce0d185c --- /dev/null +++ b/exercises/ansible_rhel/2.1-intro/po4a.cfg @@ -0,0 +1 @@ +../../../po4a.cfg \ No newline at end of file diff --git a/exercises/ansible_rhel/2.2-cred/po4a.cfg b/exercises/ansible_rhel/2.2-cred/po4a.cfg new file mode 120000 index 000000000..cce0d185c --- /dev/null +++ b/exercises/ansible_rhel/2.2-cred/po4a.cfg @@ -0,0 +1 @@ +../../../po4a.cfg \ No newline at end of file diff --git a/exercises/ansible_rhel/2.3-projects/po4a.cfg b/exercises/ansible_rhel/2.3-projects/po4a.cfg new file mode 120000 index 000000000..cce0d185c --- /dev/null +++ b/exercises/ansible_rhel/2.3-projects/po4a.cfg @@ -0,0 +1 @@ +../../../po4a.cfg \ No newline at end of file diff --git a/exercises/ansible_rhel/2.4-surveys/po4a.cfg b/exercises/ansible_rhel/2.4-surveys/po4a.cfg new file mode 120000 index 000000000..cce0d185c --- /dev/null +++ b/exercises/ansible_rhel/2.4-surveys/po4a.cfg @@ -0,0 +1 @@ +../../../po4a.cfg \ No newline at end of file diff --git a/exercises/ansible_rhel/2.5-rbac/po4a.cfg b/exercises/ansible_rhel/2.5-rbac/po4a.cfg new file mode 120000 index 000000000..cce0d185c --- /dev/null +++ b/exercises/ansible_rhel/2.5-rbac/po4a.cfg @@ -0,0 +1 @@ +../../../po4a.cfg \ No newline at end of file diff --git a/exercises/ansible_rhel/2.6-workflows/po4a.cfg b/exercises/ansible_rhel/2.6-workflows/po4a.cfg new file mode 120000 index 000000000..cce0d185c --- /dev/null +++ b/exercises/ansible_rhel/2.6-workflows/po4a.cfg @@ -0,0 +1 @@ +../../../po4a.cfg \ No newline at end of file diff --git a/exercises/ansible_rhel/2.7-wrap/po4a.cfg b/exercises/ansible_rhel/2.7-wrap/po4a.cfg new file mode 120000 index 000000000..cce0d185c --- /dev/null +++ b/exercises/ansible_rhel/2.7-wrap/po4a.cfg @@ -0,0 +1 @@ +../../../po4a.cfg \ No newline at end of file diff --git a/po4a.cfg b/po4a.cfg new file mode 100644 index 000000000..b4365c027 --- /dev/null +++ b/po4a.cfg @@ -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" diff --git a/pooneliner.py b/pooneliner.py new file mode 100755 index 000000000..4b3b7f7c0 --- /dev/null +++ b/pooneliner.py @@ -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()