aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--i18n.md30
-rw-r--r--tools/po-compile.sh17
-rwxr-xr-xtools/po-update.sh67
3 files changed, 114 insertions, 0 deletions
diff --git a/i18n.md b/i18n.md
new file mode 100644
index 0000000..2049415
--- /dev/null
+++ b/i18n.md
@@ -0,0 +1,30 @@
+# Translating IsoDumper
+
+First, make sure you have installed the `gettext` package.
+
+Here are the steps to add/update a translation (you should run all scripts from
+the source root):
+
+1. Get an up-to-date copy of the source files. Preferrably, make a clone on
+ GitHub and clone it locally on your machine; this way you can later make a
+ pull request to the main project.
+
+2. Run `./tools/po-update.sh <language>`; it will create/update the file
+ `./po/<language>.po`.
+
+3. Edit `./po/<language>.po` with your favourite editor (just make sure it saves
+ the file with the UTF-8 encoding). For each string in english (msgid), edit
+ the translation (msgstr); if you leave msgstr empty, the string will remain
+ untranslated.
+
+ Alternatively, you can use the excellent `poedit`.
+
+4. Run `./tools/po-compile.sh`. It will bring up-to-date all the compiled
+ language files, necessary at runtime.
+
+5. Start IsoDumper (`./bin/isodumper`). By default it will pick up the system languge
+ from your environment; to start it in another language, run
+ `LANGUAGE=<language> ./bin/isodumper`.
+
+You can edit the translation iteratively, just repeat from step 3.
+If the upstream changes, do a `git pull` and then repeat from step 2.
diff --git a/tools/po-compile.sh b/tools/po-compile.sh
new file mode 100644
index 0000000..2b4d364
--- /dev/null
+++ b/tools/po-compile.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+set -e
+
+cd "$(readlink -f "$(dirname "$0")/..")"
+
+find "$PWD/po" -type f -name '*.po' | \
+while read po_file; do
+ language="$(basename "$po_file")"
+ language="${language%.po}"
+ target="$PWD/po/$language/LC_MESSAGES/isodumper.mo"
+ /bin/mkdir --parents "$(dirname "$target")"
+ /usr/bin/msgfmt \
+ --check \
+ --output-file="$target" \
+ "$po_file"
+done
diff --git a/tools/po-update.sh b/tools/po-update.sh
new file mode 100755
index 0000000..27c2606
--- /dev/null
+++ b/tools/po-update.sh
@@ -0,0 +1,67 @@
+#!/bin/sh
+
+if test -z "$1"; then
+ echo "Use: $0 <locale>"
+ exit 2
+fi
+LL_CC="$1"
+shift
+
+set -e
+
+cd "$(readlink -f "$(dirname "$0")/..")"
+
+VERSION=(0.1)
+DOMAIN=(isodumper)
+
+SOURCE_FILES=$(/bin/mktemp --tmpdir $DOMAIN-po-update-XXXXXX)
+find "lib" -name '*.py' >"$SOURCE_FILES"
+
+POT_DIR="$PWD/po"
+test -d "$POT_DIR"
+
+POT_FILE="$POT_DIR/$DOMAIN.pot"
+
+/usr/bin/xgettext \
+ --package-name "$DOMAIN" \
+ --package-version "$VERSION" \
+ --default-domain="$L_NAME" \
+ --language=Python --from-code=UTF-8 --files-from="$SOURCE_FILES" \
+ --no-escape --indent --add-location --sort-by-file \
+ --add-comments=I18N \
+ --output="$POT_FILE"
+
+/bin/sed --in-place --expression="s/charset=CHARSET/charset=UTF-8/" "$POT_FILE"
+
+PO_FILE="$POT_DIR/$LL_CC.po"
+
+test -r "$PO_FILE" || /usr/bin/msginit \
+ --no-translator --locale="$LL_CC" \
+ --input="$POT_FILE" \
+ --output-file="$PO_FILE"
+
+#unfmt() {
+# local SOURCE="/usr/share/locale/$LL_CC/LC_MESSAGES/$1.mo"
+# if [ ! -f $SOURCE ]
+# then
+# local SOURCE="/usr/share/locale-langpack/$LL_CC/LC_MESSAGES/$1.mo"
+# fi
+# local TARGET="$(mktemp --tmpdir $1-$LL_CC-XXXXXX.po)"
+# /usr/bin/msgunfmt \
+# --no-escape --indent \
+# --output-file="$TARGET" \
+# "$SOURCE"
+# echo "$TARGET"
+#}
+
+#/usr/bin/msgmerge \
+# --update --no-fuzzy-matching \
+# --no-escape --indent --add-location --sort-by-file \
+# --lang="$LL_CC" \
+# --compendium="$(unfmt gtk30)" \
+# --compendium="$(unfmt gtk30-properties)" \
+# "$PO_FILE" "$POT_FILE"
+
+# /bin/sed --in-place --expression="s/Language: \\\\n/Language: $L_NAME\\\\n/" "$PO_FILE"
+
+echo "Language file is $PO_FILE"