Commit a11b14ba authored by Peter Serwylo's avatar Peter Serwylo

Update i18n-ed .po files when the English version changes.

parent a00ff88b
......@@ -44,6 +44,10 @@ When a new `.md` file is added to the `_docs/` or `_posts/` directory, then you
This will extract the strings from all Markdown files in these two directories and output them to either `po/_docs.po` or `po/_posts.po`.
These will then subsequently be translated by Weblate into additional files such as `po/_docs.fr.po`.
In addition, the script will update any already existing translations such as `po/_docs.fr.po`.
It does so by using the [msgmerge](https://www.gnu.org/software/gettext/manual/html_node/msgmerge-Invocation.html) program from GNU gettext.
This takes care of fuzzy string matches, new strings, and deleted strings.
## Configuring Weblate
The translation setup is designed to work with three different Weblate Components:
......@@ -77,6 +81,7 @@ As such, this will only document the process for Documentation.
For Website News, do the same, but wherever you see `_docs` replace it with `_posts`.
* **File mask:** `po/_docs.*.po`
* **Edit base file:** No
* **Base file for new translations:** `po/_docs.po`
* **File format:** Gettext PO file
......
......@@ -22,13 +22,16 @@ function md2po {
echo "Converting .md source into .po files"
if [ -d ${DIR_BUILD} ]; then rm -r ${DIR_BUILD}; fi
generate_po_files _docs
generate_po_files _posts
generate_po_file _docs
generate_po_file _posts
rm -r ${DIR_BUILD}
update_po_files _docs
update_po_files _posts
}
#
# Usage: generate_po_files SRC_TYPE
# Usage: generate_po_file SRC_TYPE
#
# Where SRC_TYPE is either _posts or _docs (i.e. directories with .md files that are translated into a single .po file)
#
......@@ -38,7 +41,7 @@ function md2po {
# * Once all .md files have had their strings extracted, they are combined into a single .po file using msgcat.
# * This .po file is the thing which will end up getting translated.
#
function generate_po_files {
function generate_po_file {
SRC_TYPE=$1
SRC_SUBDIR=${DIR_SRC}/${SRC_TYPE}
BUILD_SUBDIR=${DIR_BUILD}/${SRC_TYPE}/md
......@@ -64,6 +67,21 @@ function generate_po_files {
msgcat -o ${OUT_PO_FILE} ${DIR_BUILD_PO}/*.pot
}
#
# Updates each translated .po file with new/changed strings from the original English .po file.
# Uses `msgmerge` and supports fuzzy string matching.
#
function update_po_files {
SRC_TYPE=$1
PO=${DIR_PO}/${SRC_TYPE}.po
for I18N_PO in ${DIR_PO}/${SRC_TYPE}.*.po; do
# The VERSION_CONTROL environment variable prevents a backup file from being written to ${SRC_TYPE}.LANG.po~
echo "Updating ${I18N_PO} with any changes from main .po file ${PO}."
VERSION_CONTROL=none msgmerge -U ${I18N_PO} ${PO}
done
}
########################################
# Generate Markdown from i18n PO files #
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment