index : archinstall32 | |
Archlinux32 installer | gitolite user |
summaryrefslogtreecommitdiff |
author | Daniel Girtler <blackrabbit256@gmail.com> | 2023-09-28 08:44:18 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-28 08:44:18 +1000 |
commit | 1e296b263714017596beeca27744a51c75f29504 (patch) | |
tree | 6b7fefcc5fccd62450911717f417db800ecf232e /archinstall/locales | |
parent | 72856ed5ec869012c8d2ab0f1d17467653156556 (diff) |
-rw-r--r-- | archinstall/locales/README.md | 10 | ||||
-rwxr-xr-x | archinstall/locales/locales_generator.sh | 43 |
diff --git a/archinstall/locales/README.md b/archinstall/locales/README.md index e1266209..de1aa83a 100644 --- a/archinstall/locales/README.md +++ b/archinstall/locales/README.md @@ -14,15 +14,15 @@ can be set with `setfont LatGrkCyr-8x16` ## Adding new languages -New languages can be added simply by creating a new folder with the proper language abbreviation (see list `languages.json` if unsure). +New languages can be added simply by creating a new folder with the proper language abbreviation (see list `languages.json` if unsure). Run the following command to create a new template for a language ``` mkdir -p <abbr>/LC_MESSAGES/ && touch <abbr>/LC_MESSAGES/base.po ``` -After that run the script `./locales_generator.sh` it will automatically populate the new `base.po` file with the strings that -need to be translated into the new language. -For example the `base.po` might contain something like the following now +After that run the script `./locales_generator.sh <lang_abbr>` it will automatically populate the new `base.po` file with the strings that +need to be translated into the new language. +For example the `base.po` might contain something like the following now ``` #: lib/user_interaction.py:82 msgid "Do you really want to abort?" @@ -30,7 +30,7 @@ msgstr "" ``` The `msgid` is the identifier of the string in the code as well as the default text to be displayed, meaning that if no -translation is provided for a language then this is the text that is going to be shown. +translation is provided for a language then this is the text that is going to be shown. To perform translations for a language this file can be edited manually or the neat `poedit` can be used (https://poedit.net/). If editing the file manually, write the translation in the `msgstr` part diff --git a/archinstall/locales/locales_generator.sh b/archinstall/locales/locales_generator.sh index cdd5be31..5386c3e6 100755 --- a/archinstall/locales/locales_generator.sh +++ b/archinstall/locales/locales_generator.sh @@ -2,11 +2,48 @@ cd $(dirname "$0")/.. -find . -type f -iname "*.py" | xargs xgettext --join-existing --no-location --omit-header -d base -o locales/base.pot +function update_lang() { + file=$1 -for file in $(find locales/ -name "base.po"); do echo "Updating: $file" path=$(dirname $file) msgmerge --quiet --no-location --width 512 --backup none --update $file locales/base.pot msgfmt -o $path/base.mo $file -done +} + + +function generate_all() { + for file in $(find locales/ -name "base.po"); do + update_lang "$file" + done +} + +function generate_single_lang() { + lang_file="locales/$1/LC_MESSAGES/base.po" + + if [ ! -f "$lang_file" ]; then + echo "Language files not found: $lang_file" + exit 1 + fi + + update_lang "$lang_file" +} + + + +if [ $# -eq 0 ] + then + echo "Usage: locales_generator.sh <language_abbr>" + exit 1 +fi + +lang=$1 + +# Update the base file containing all translatable string +find . -type f -iname "*.py" | xargs xgettext --join-existing --no-location --omit-header -d base -o locales/base.pot + +case "$lang" in + "all") generate_all + ;; + *) generate_single_lang "$lang" +esac |