]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Adding infrastructure for i18n
authorFrank Brehm <frank.brehm@pixelpark.com>
Fri, 8 Feb 2019 09:02:20 +0000 (10:02 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Fri, 8 Feb 2019 09:02:20 +0000 (10:02 +0100)
.gitignore
babel.ini [new file with mode: 0644]
compile-xlate-msgs.sh [new file with mode: 0755]
lib/cr_vmware_tpl/xlate.py [new file with mode: 0644]
locale/create_vm_template.pot [new file with mode: 0644]
locale/de_DE/LC_MESSAGES/create_vm_template.po [new file with mode: 0644]
locale/en_US/LC_MESSAGES/create_vm_template.po [new file with mode: 0644]
xtract-xlate-msgs.sh [new file with mode: 0755]

index fbac3f1845f8ce39836db33a3d3749872b78d76a..115f1e8a604aeec543be60ab82572c67b8dec051 100644 (file)
@@ -4,6 +4,7 @@
 *.egg
 *-stamp
 *.bak
+*.mo
 tmp/*
 venv/*
 etc/*.ini
diff --git a/babel.ini b/babel.ini
new file mode 100644 (file)
index 0000000..d7dfdfd
--- /dev/null
+++ b/babel.ini
@@ -0,0 +1,5 @@
+# Extraction from Python source files
+[python: **.py]
+
+[python: bin/*]
+
diff --git a/compile-xlate-msgs.sh b/compile-xlate-msgs.sh
new file mode 100755 (executable)
index 0000000..5aafcb8
--- /dev/null
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+set -e
+set -u
+
+base_dir=$( dirname $0 )
+cd ${base_dir}
+
+locale_dir=locale
+locale_domain="create_vm_template"
+pot_file="${locale_dir}/${locale_domain}.pot"
+po_with=99
+my_address="${DEBEMAIL:-frank.brehm@pixelpark.com}"
+
+pybabel compile --domain "${locale_domain}" \
+    --directory "${locale_dir}" \
+    --statistics
+
diff --git a/lib/cr_vmware_tpl/xlate.py b/lib/cr_vmware_tpl/xlate.py
new file mode 100644 (file)
index 0000000..f647ecb
--- /dev/null
@@ -0,0 +1,62 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+@author: Frank Brehm
+@contact: frank.brehm@pixelpark.com
+@copyright: © 2019 by Frank Brehm, Berlin
+@summary: The module for i18n.
+          It provides translation object, usable from all other
+          modules in this package.
+"""
+from __future__ import absolute_import, print_function
+
+# Standard modules
+import logging
+import gettext
+
+from pathlib import Path
+
+# Third party modules
+from babel.support import Translations
+
+DOMAIN = 'create_vm_template'
+
+LOG = logging.getLogger(__name__)
+
+__version__ = '1.0.1'
+
+__me__ = Path(__file__).resolve()
+__module_dir__ = __me__.parent
+__lib_dir__ = __module_dir__.parent
+__base_dir__ = __lib_dir__.parent
+LOCALE_DIR = __base_dir__.joinpath('locale')
+if not LOCALE_DIR.is_dir():
+    LOCALE_DIR = __module_dir__.joinpath('locale')
+    if not LOCALE_DIR.is_dir():
+        LOCALE_DIR = None
+
+__mo_file__ = gettext.find(DOMAIN, str(LOCALE_DIR))
+if __mo_file__:
+    try:
+        with open(__mo_file__, 'rb') as F:
+            XLATOR = Translations(F, DOMAIN)
+    except IOError:
+        XLATOR = gettext.NullTranslations()
+else:
+    XLATOR = gettext.NullTranslations()
+
+_ = XLATOR.gettext
+
+# =============================================================================
+
+if __name__ == "__main__":
+
+    print(_("Module directory: {!r}").format(__module_dir__))
+    print(_("Base directory: {!r}").format(__base_dir__))
+    print(_("Locale directory: {!r}").format(LOCALE_DIR))
+    print(_("Locale domain: {!r}").format(DOMAIN))
+    print(_("Found .mo-file: {!r}").format(__mo_file__))
+
+# =============================================================================
+
+# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
diff --git a/locale/create_vm_template.pot b/locale/create_vm_template.pot
new file mode 100644 (file)
index 0000000..373c9e7
--- /dev/null
@@ -0,0 +1,39 @@
+# Translations template for create_vm_template.
+# Copyright (C) 2019 Frank Brehm, Pixelpark GmbH, Berlin
+# This file is distributed under the same license as the create_vm_template project.
+# Frank Brehm <frank.brehm@pixelpark.com>, 2019.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: create_vm_template 1.0.0\n"
+"Report-Msgid-Bugs-To: frank.brehm@pixelpark.com\n"
+"POT-Creation-Date: 2019-02-08 09:56+0100\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <frank.brehm@pixelpark.com>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=utf-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Generated-By: Babel 2.6.0\n"
+
+#: lib/cr_vmware_tpl/xlate.py:54
+msgid "Module directory: {!r}"
+msgstr ""
+
+#: lib/cr_vmware_tpl/xlate.py:55
+msgid "Base directory: {!r}"
+msgstr ""
+
+#: lib/cr_vmware_tpl/xlate.py:56
+msgid "Locale directory: {!r}"
+msgstr ""
+
+#: lib/cr_vmware_tpl/xlate.py:57
+msgid "Locale domain: {!r}"
+msgstr ""
+
+#: lib/cr_vmware_tpl/xlate.py:58
+msgid "Found .mo-file: {!r}"
+msgstr ""
+
diff --git a/locale/de_DE/LC_MESSAGES/create_vm_template.po b/locale/de_DE/LC_MESSAGES/create_vm_template.po
new file mode 100644 (file)
index 0000000..2acfd9e
--- /dev/null
@@ -0,0 +1,40 @@
+# German (Germany) translations for create_vm_template.
+# Copyright (C) 2019 Frank Brehm, Pixelpark GmbH, Berlin
+# This file is distributed under the same license as the create_vm_template project.
+# Frank Brehm <frank.brehm@pixelpark.com>, 2019.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: create_vm_template 1.0.0\n"
+"Report-Msgid-Bugs-To: frank.brehm@pixelpark.com\n"
+"POT-Creation-Date: 2019-02-08 09:56+0100\n"
+"PO-Revision-Date: 2019-02-08 09:56+0100\n"
+"Last-Translator: Frank Brehm <frank.brehm@pixelpark.com>\n"
+"Language: de_DE\n"
+"Language-Team: de_DE <LL@li.org>\n"
+"Plural-Forms: nplurals=2; plural=(n != 1)\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=utf-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Generated-By: Babel 2.6.0\n"
+
+#: lib/cr_vmware_tpl/xlate.py:54
+msgid "Module directory: {!r}"
+msgstr "Modul-Verzeichnis: {!r}"
+
+#: lib/cr_vmware_tpl/xlate.py:55
+msgid "Base directory: {!r}"
+msgstr "Basis-Verzeichnis: {!r}"
+
+#: lib/cr_vmware_tpl/xlate.py:56
+msgid "Locale directory: {!r}"
+msgstr "Verzeichnis für Locales: {!r}"
+
+#: lib/cr_vmware_tpl/xlate.py:57
+msgid "Locale domain: {!r}"
+msgstr "Locale-Domäne: {!r}"
+
+#: lib/cr_vmware_tpl/xlate.py:58
+msgid "Found .mo-file: {!r}"
+msgstr "Gefundene .mo-Datei: {!r}"
+
diff --git a/locale/en_US/LC_MESSAGES/create_vm_template.po b/locale/en_US/LC_MESSAGES/create_vm_template.po
new file mode 100644 (file)
index 0000000..0a2ddee
--- /dev/null
@@ -0,0 +1,40 @@
+# English (United States) translations for create_vm_template.
+# Copyright (C) 2019 Frank Brehm, Pixelpark GmbH, Berlin
+# This file is distributed under the same license as the create_vm_template project.
+# Frank Brehm <frank.brehm@pixelpark.com>, 2019.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: create_vm_template 1.0.0\n"
+"Report-Msgid-Bugs-To: frank.brehm@pixelpark.com\n"
+"POT-Creation-Date: 2019-02-08 09:56+0100\n"
+"PO-Revision-Date: 2019-02-08 09:56+0100\n"
+"Last-Translator: FULL NAME <frank.brehm@pixelpark.com>\n"
+"Language: en_US\n"
+"Language-Team: en_US <LL@li.org>\n"
+"Plural-Forms: nplurals=2; plural=(n != 1)\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=utf-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Generated-By: Babel 2.6.0\n"
+
+#: lib/cr_vmware_tpl/xlate.py:54
+msgid "Module directory: {!r}"
+msgstr ""
+
+#: lib/cr_vmware_tpl/xlate.py:55
+msgid "Base directory: {!r}"
+msgstr ""
+
+#: lib/cr_vmware_tpl/xlate.py:56
+msgid "Locale directory: {!r}"
+msgstr ""
+
+#: lib/cr_vmware_tpl/xlate.py:57
+msgid "Locale domain: {!r}"
+msgstr ""
+
+#: lib/cr_vmware_tpl/xlate.py:58
+msgid "Found .mo-file: {!r}"
+msgstr ""
+
diff --git a/xtract-xlate-msgs.sh b/xtract-xlate-msgs.sh
new file mode 100755 (executable)
index 0000000..6df9d2b
--- /dev/null
@@ -0,0 +1,51 @@
+#!/bin/bash
+
+set -e
+set -u
+
+base_dir=$( dirname $0 )
+cd ${base_dir}
+
+locale_dir=locale
+locale_domain="create_vm_template"
+pot_file="${locale_dir}/${locale_domain}.pot"
+po_with=99
+my_address="${DEBEMAIL:-frank.brehm@pixelpark.com}"
+
+pkg_version=$( cat lib/cr_vmware_tpl/__init__.py | \
+                    grep '^[   ]*__version__' | \
+                    sed -e 's/[        ]*//g' | \
+                    awk -F= '{print $2}' | \
+                    sed -e "s/^'//" -e "s/'\$//" )
+
+mkdir -pv "${locale_dir}"
+
+pybabel extract lib/cr_vmware_tpl \
+    -o "${pot_file}" \
+    -F babel.ini \
+    --width=${po_with} \
+    --sort-by-file \
+    --msgid-bugs-address="${my_address}" \
+    --copyright-holder="Frank Brehm, Pixelpark GmbH, Berlin" \
+    --project="${locale_domain}" \
+    --version="${pkg_version}"
+
+sed -i -e "s/FIRST AUTHOR/Frank Brehm/g" -e "s/<EMAIL@ADDRESS>/<${my_address}>/g" "${pot_file}"
+
+for lang in de_DE en_US ; do
+    if [[ ! -f "${locale_dir}/${lang}/LC_MESSAGES/${locale_domain}.po" ]] ; then
+        pybabel init --domain "${locale_domain}" \
+            --input-file "${pot_file}" \
+            --output-dir "${locale_dir}" \
+            --locale "${lang}" \
+            --width ${po_with}
+    else
+        pybabel update --domain "${locale_domain}" \
+            --input-file "${pot_file}" \
+            --output-dir "${locale_dir}" \
+            --locale "${lang}" \
+            --width ${po_with} \
+            --update-header-comment
+    fi
+            # --ignore-obsolete \
+done