From 21ffb589034396fe7517cf65eef932b6db91ebff Mon Sep 17 00:00:00 2001 From: Bruno Lopes Date: Fri, 15 Mar 2024 18:51:48 -0300 Subject: [PATCH] Issue #811: Make each language a component for the Installer In the process, make the Installer localization process less 'masochist' (in other words: less manual). The custom '.xml' was the only way since the iso-codes, Dammed Lies and Inno namings don't match. --- build/windows/gitlab-ci/4_dist-gimp-inno.ps1 | 39 +- build/windows/installer/base_gimp3264.iss | 50 +-- .../windows/installer/lang/iso_639_custom.xml | 351 ++++++++++++++++++ .../installer/lang/list-installer-langs.sh | 74 ++++ build/windows/installer/lang/meson.build | 30 ++ .../installer/lang/test-installer-langs.sh | 29 +- 6 files changed, 477 insertions(+), 96 deletions(-) create mode 100644 build/windows/installer/lang/iso_639_custom.xml create mode 100644 build/windows/installer/lang/list-installer-langs.sh diff --git a/build/windows/gitlab-ci/4_dist-gimp-inno.ps1 b/build/windows/gitlab-ci/4_dist-gimp-inno.ps1 index a90b16b03c..27c14f6ecf 100644 --- a/build/windows/gitlab-ci/4_dist-gimp-inno.ps1 +++ b/build/windows/gitlab-ci/4_dist-gimp-inno.ps1 @@ -74,35 +74,21 @@ function download_lang_official ([string]$langfile) #New-Item -ItemType Directory -Path "$INNOPATH/Languages/" -Force + # Download Unofficial translations (of unknown quality and maintenance) # Cf. https://jrsoftware.org/files/istrans/ -function download_lang ([string]$langfile) -{ - if (Test-Path -Path "$langfile" -PathType Leaf) - { - Remove-Item -Path "$langfile" -Force - } - Invoke-WebRequest -URI "https://raw.githubusercontent.com/jrsoftware/issrc/main/Files/Languages/Unofficial/${langfile}" -OutFile "$INNOPATH/Languages/Unofficial/${langfile}" -} - New-Item -ItemType Directory -Path "$INNOPATH/Languages/Unofficial/" -Force -download_lang Basque.isl -download_lang Belarusian.isl -download_lang ChineseSimplified.isl -download_lang ChineseTraditional.isl -download_lang EnglishBritish.isl -download_lang Esperanto.isl -download_lang Galician.isl -download_lang Georgian.isl -download_lang Greek.isl -download_lang Indonesian.isl -download_lang Latvian.isl -download_lang Lithuanian.isl -download_lang Malaysian.isl -download_lang Marathi.islu -download_lang Romanian.isl -download_lang Swedish.isl -download_lang Vietnamese.isl + +$xmlObject = New-Object XML +$xmlObject.Load("$PWD\build\windows\installer\lang\iso_639_custom.xml") +$langsArray = $xmlObject.iso_639_entries.iso_639_entry | + Select-Object -ExpandProperty inno_code | Where-Object { $_ -like "*Unofficial*" } + +foreach ($langfile in $langsArray) + { + $langfileUnix = $langfile.Replace('\\', '/') + Invoke-WebRequest -URI "https://raw.githubusercontent.com/jrsoftware/issrc/main/Files/$langfileUnix" -OutFile "$INNOPATH/$langfileUnix" + } $gen_path = Resolve-Path -Path "_build-*\build\windows\installer" | Select-Object -ExpandProperty Path @@ -110,6 +96,7 @@ if (Test-Path -Path $gen_path) { # Copy generated language files into the source directory Copy-Item $gen_path\lang\*isl build\windows\installer\lang\ + Copy-Item $gen_path\*list build\windows\installer\ # Copy generated images into the source directory Copy-Item $gen_path\*bmp build\windows\installer\ diff --git a/build/windows/installer/base_gimp3264.iss b/build/windows/installer/base_gimp3264.iss index 89f2cb9cba..26f69e5160 100644 --- a/build/windows/installer/base_gimp3264.iss +++ b/build/windows/installer/base_gimp3264.iss @@ -217,50 +217,7 @@ UninstallFilesDir={app}\uninst [Languages] Name: "en"; MessagesFile: "compiler:Default.isl,lang\en.setup.isl" -Name: "be"; MessagesFile: "compiler:Languages\Unofficial\Belarusian.isl,lang\be.setup.isl" -Name: "bg"; MessagesFile: "compiler:Languages\Bulgarian.isl,lang\bg.setup.isl" -Name: "ca"; MessagesFile: "compiler:Languages\Catalan.isl,lang\ca.setup.isl" -Name: "cs"; MessagesFile: "compiler:Languages\Czech.isl,lang\cs.setup.isl" -Name: "da"; MessagesFile: "compiler:Languages\Danish.isl,lang\da.setup.isl" -Name: "de"; MessagesFile: "compiler:Languages\German.isl,lang\de.setup.isl" -Name: "el"; MessagesFile: "compiler:Languages\Unofficial\Greek.isl,lang\el.setup.isl" -Name: "en_GB"; MessagesFile: "compiler:Languages\Unofficial\EnglishBritish.isl,lang\en_GB.setup.isl" -Name: "eo"; MessagesFile: "compiler:Languages\Unofficial\Esperanto.isl,lang\eo.setup.isl" -Name: "es"; MessagesFile: "compiler:Languages\Spanish.isl,lang\es.setup.isl" -Name: "eu"; MessagesFile: "compiler:Languages\Unofficial\Basque.isl,lang\eu.setup.isl" -Name: "fi"; MessagesFile: "compiler:Languages\Finnish.isl,lang\fi.setup.isl" -Name: "fr"; MessagesFile: "compiler:Languages\French.isl,lang\fr.setup.isl" -Name: "gl"; MessagesFile: "compiler:Languages\Unofficial\Galician.isl,lang\gl.setup.isl" -Name: "he"; MessagesFile: "compiler:Languages\Hebrew.isl,lang\he.setup.isl" -Name: "hu"; MessagesFile: "compiler:Languages\Hungarian.isl,lang\hu.setup.isl" -;Name: "hr"; MessagesFile: "compiler:Languages\Unofficial\Croatian.isl,lang\hr.setup.isl" -Name: "id"; MessagesFile: "compiler:Languages\Unofficial\Indonesian.isl,lang\id.setup.isl" -Name: "is"; MessagesFile: "compiler:Languages\Icelandic.isl,lang\is.setup.isl" -Name: "it"; MessagesFile: "compiler:Languages\Italian.isl,lang\it.setup.isl" -Name: "ja"; MessagesFile: "compiler:Languages\Japanese.isl,lang\ja.setup.isl" -Name: "ka"; MessagesFile: "compiler:Languages\Unofficial\Georgian.isl,lang\ka.setup.isl" -Name: "kab"; MessagesFile: "compiler:Default.isl,lang\kab.isl,lang\kab.setup.isl" -Name: "ko"; MessagesFile: "compiler:Languages\Korean.isl,lang\ko.setup.isl" -Name: "lt"; MessagesFile: "compiler:Languages\Unofficial\Lithuanian.isl,lang\lt.setup.isl" -Name: "lv"; MessagesFile: "compiler:Languages\Unofficial\Latvian.isl,lang\lv.setup.isl" -Name: "mr"; MessagesFile: "compiler:Languages\Unofficial\Marathi.islu,lang\mr.setup.isl" -Name: "ms"; MessagesFile: "compiler:Languages\Unofficial\Malaysian.isl,lang\ms.setup.isl" -Name: "nl"; MessagesFile: "compiler:Languages\Dutch.isl,lang\nl.setup.isl" -Name: "nn"; MessagesFile: "compiler:Languages\Norwegian.isl,lang\nn.setup.isl" -Name: "pl"; MessagesFile: "compiler:Languages\Polish.isl,lang\pl.setup.isl" -Name: "pt"; MessagesFile: "compiler:Languages\Portuguese.isl,lang\pt.setup.isl" -Name: "pt_BR"; MessagesFile: "compiler:Languages\BrazilianPortuguese.isl,lang\pt_BR.setup.isl" -Name: "ro"; MessagesFile: "compiler:Languages\Unofficial\Romanian.isl,lang\ro.setup.isl" -Name: "ru"; MessagesFile: "compiler:Languages\Russian.isl,lang\ru.setup.isl" -Name: "sk"; MessagesFile: "compiler:Languages\Slovak.isl,lang\sk.setup.isl" -Name: "sl"; MessagesFile: "compiler:Languages\Slovenian.isl,lang\sl.setup.isl" -Name: "sv"; MessagesFile: "compiler:Languages\Unofficial\Swedish.isl,lang\sv.setup.isl" -Name: "tr"; MessagesFile: "compiler:Languages\Turkish.isl,lang\tr.setup.isl" -Name: "uk"; MessagesFile: "compiler:Languages\Ukrainian.isl,lang\uk.setup.isl" -Name: "vi"; MessagesFile: "compiler:Languages\Unofficial\Vietnamese.isl,lang\vi.setup.isl" -Name: "zh_CN"; MessagesFile: "compiler:Languages\Unofficial\ChineseSimplified.isl,lang\zh_CN.setup.isl" -Name: "zh_TW"; MessagesFile: "compiler:Languages\Unofficial\ChineseTraditional.isl,lang\zh_TW.setup.isl" -;Name: "ro"; MessagesFile: "Romanian.islu,ro.setup.islu" +#include "base_po-msg.list" [Types] ;Name: normal; Description: "{cm:TypeTypical}" @@ -288,6 +245,7 @@ Name: gs; Description: "{cm:ComponentsGhostscript}"; Types: full custom ;Locales Name: loc; Description: "{cm:ComponentsTranslations}"; Types: full custom +#include "base_po-cmp.list" #ifdef LUA Name: lua; Description: "{cm:ComponentsLua}"; Types: full custom @@ -336,8 +294,8 @@ Source: "{#DEPS_DIR32}\share\*"; DestDir: "{app}\share"; Excludes: "{#OMISSIONS} ;Optional neutral components (complete install) Source: "{#DEPS_DIR32}\share\ghostscript\*"; DestDir: "{app}\share\ghostscript"; Components: gs and ({#GIMP_ARCHS}); Flags: recursesubdirs restartreplace uninsrestartdelete ignoreversion -Source: "{#GIMP_DIR32}\share\locale\*"; DestDir: "{app}\share\locale"; Components: loc; Flags: recursesubdirs restartreplace uninsrestartdelete ignoreversion -Source: "{#DEPS_DIR32}\share\locale\*"; DestDir: "{app}\share\locale"; Components: loc; Flags: recursesubdirs restartreplace uninsrestartdelete ignoreversion +Source: "{#GIMP_DIR32}\share\locale\*"; DestDir: "{app}\share\locale"; Components: loc; Flags: dontcopy recursesubdirs restartreplace uninsrestartdelete ignoreversion +#include "base_po-files.list" #ifdef LUA Source: "{#GIMP_DIR32}\lib\gimp\{#GIMP_API_VERSION}\interpreters\lua.interp"; DestDir: "{app}\lib\gimp\{#GIMP_API_VERSION}\interpreters"; Components: lua and ({#GIMP_ARCHS}); Flags: recursesubdirs restartreplace uninsrestartdelete ignoreversion Source: "{#DEPS_DIR32}\share\lua\*"; DestDir: "{app}\share\lua"; Components: lua and ({#GIMP_ARCHS}); Flags: recursesubdirs restartreplace ignoreversion uninsrestartdelete diff --git a/build/windows/installer/lang/iso_639_custom.xml b/build/windows/installer/lang/iso_639_custom.xml new file mode 100644 index 0000000000..194ed5afb6 --- /dev/null +++ b/build/windows/installer/lang/iso_639_custom.xml @@ -0,0 +1,351 @@ + + + + + + + +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build/windows/installer/lang/list-installer-langs.sh b/build/windows/installer/lang/list-installer-langs.sh new file mode 100644 index 0000000000..4ae08db188 --- /dev/null +++ b/build/windows/installer/lang/list-installer-langs.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +if [ "$1" = 'cmp' ]; then + ## Get list of GIMP supported languages + PO_ARRAY=($(echo $(ls ../po/*.po | + sed -e 's|../po/||g' -e 's|.po||g' | sort) | + tr '\n\r' ' ')) + + ## Create list of lang [Components] + for PO in "${PO_ARRAY[@]}"; do + CMP_LINE='Name: loc\PO_CLEAN; Description: "DESC"; Types: full custom' + # Change po + PO_CLEAN=$(echo $PO | sed "s/@/_/g") + CMP_LINE=$(sed "s/PO_CLEAN/$PO_CLEAN/g" <<< $CMP_LINE) + # Change desc + DESC=$(echo "cat //iso_639_entries/iso_639_entry[@dl_code=\"$PO\"]/@name" | + xmllint --shell ../build/windows/installer/lang/iso_639_custom.xml | + awk -F'[="]' '!/>/{print $(NF-1)}') + CMP_LINE=$(sed "s/DESC/$DESC/g" <<< $CMP_LINE) + # Create line + NL=$'\n' + CMP_LIST+="${CMP_LINE}${NL}" + done + echo "$CMP_LIST" > build/windows/installer/base_po-cmp.list +fi + + +if [ "$1" = 'files' ]; then + ## Get list of GIMP supported languages + PO_ARRAY=($(echo $(ls ../po/*.po | + sed -e 's|../po/||g' -e 's|.po||g' | sort) | + tr '\n\r' ' ')) + + ## Create list of lang [Files] + for PO in "${PO_ARRAY[@]}"; do + FILES_LINE='Source: "{#GIMP_DIR32}\share\locale\PO\*"; DestDir: "{app}\share\locale\PO"; Components: loc\PO_CLEAN; Flags: recursesubdirs restartreplace uninsrestartdelete ignoreversion' + # Change po + PO_CLEAN=$(echo $PO | sed "s/@/_/g") + FILES_LINE=$(sed "s/PO_CLEAN/$PO_CLEAN/g" <<< $FILES_LINE) + FILES_LINE=$(sed "s/PO/$PO/g" <<< $FILES_LINE) + # Create line + NL=$'\n' + FILES_LIST+="${FILES_LINE}${NL}" + done + echo "$FILES_LIST" > build/windows/installer/base_po-files.list +fi + + +if [ "$1" = 'msg' ]; then + ## Get list of Inno supported languages + PO_INNO_ARRAY=($(echo $(ls ../po-windows-installer/*.po | + sed -e 's|../po-windows-installer/||g' -e 's|.po||g' | sort) | + tr '\n\r' ' ')) + + ## Create list of lang [Languages] + if [ "$1" = 'msg' ]; then + for PO in "${PO_INNO_ARRAY[@]}"; do + MSG_LINE='Name: "PO"; MessagesFile: "compiler:INNO_CODE,lang\PO.setup.isl"' + # Change po + MSG_LINE=$(sed "s/PO/$PO/g" <<< $MSG_LINE) + # Change isl + INNO_CODE=$(echo "cat //iso_639_entries/iso_639_entry[@dl_code=\"$PO\"]/@inno_code" | + xmllint --shell ../build/windows/installer/lang/iso_639_custom.xml | + awk -F'[="]' '!/>/{print $(NF-1)}') + MSG_LINE=$(sed "s/INNO_CODE/$INNO_CODE/g" <<< $MSG_LINE) + # Create line + if [ "$INNO_CODE" != '' ]; then + NL=$'\n' + MSG_LIST+="${MSG_LINE}${NL}" + fi + done + echo "$MSG_LIST" > build/windows/installer/base_po-msg.list + fi +fi \ No newline at end of file diff --git a/build/windows/installer/lang/meson.build b/build/windows/installer/lang/meson.build index fe724158c4..0ea927a324 100644 --- a/build/windows/installer/lang/meson.build +++ b/build/windows/installer/lang/meson.build @@ -99,6 +99,36 @@ foreach language : languages endif endforeach +# Generate lang lists for Inno +gen_list = find_program('list-installer-langs.sh') + +custom_target('base_po-cmp', + input : [ 'iso_639_custom.xml' ], + output: [ 'base_po-cmp.list', ], + command: [ + gen_list, 'cmp', + ], + build_by_default: true, +) + +custom_target('base_po-files', + input : [ 'iso_639_custom.xml' ], + output: [ 'base_po-files.list', ], + command: [ + gen_list, 'files', + ], + build_by_default: true, +) + +custom_target('base_po-msg', + input : [ 'iso_639_custom.xml' ], + output: [ 'base_po-msg.list', ], + command: [ + gen_list, 'msg', + ], + build_by_default: true, +) + test('windows-installer-langs', find_program('test-installer-langs.sh'), env: [ diff --git a/build/windows/installer/lang/test-installer-langs.sh b/build/windows/installer/lang/test-installer-langs.sh index 894ad9c52d..a24a373834 100755 --- a/build/windows/installer/lang/test-installer-langs.sh +++ b/build/windows/installer/lang/test-installer-langs.sh @@ -4,7 +4,7 @@ # translations present. This check step is necessary to not forget new # installer translations because we have a manual step. -INSTALLER_LANGS=`grep -rI '^Name:.*MessagesFile' ${GIMP_TESTING_ABS_TOP_SRCDIR}/build/windows/installer/base_gimp3264.iss | \ +INSTALLER_LANGS=`grep -rI '^Name:.*MessagesFile' build/windows/installer/base_po-msg.list | \ sed 's/^Name: *"\([a-zA-Z_]*\)".*$/\1/' | sort` # 'en' doesn't have a gettext file because it is the default. INSTALLER_LANGS=`echo "$INSTALLER_LANGS" | tr '\n\r' ' ' | sed 's/\ //'` @@ -14,16 +14,15 @@ PO_LANGS=`ls ${GIMP_TESTING_ABS_TOP_SRCDIR}/po-windows-installer/*.po | \ PO_LANGS=`echo "$PO_LANGS" | tr '\n\r' ' '` if [ "$PO_LANGS" != "$INSTALLER_LANGS" ]; then - echo "Error: languages listed in the Windows installer script do not match the .po files in po-windows-installer/." + echo "Error: languages listed in generated 'base_po-msg.list' do not match the .po files in po-windows-installer/." echo "- PO languages: $PO_LANGS" echo "- Installer languages: $INSTALLER_LANGS" - echo "Please verify: build/windows/installer/base_gimp3264.iss" - echo "Base language files can be found in: https://github.com/jrsoftware/issrc/tree/main/Files/Languages" - echo "If a new language is in Unofficial/, also edit/download it from:" - echo "build/windows/gitlab-ci/4_dist-gimp-inno.ps1" + echo "Please verify: build/windows/installer/lang/iso_639_custom.xml" + echo "You probably will need to add an 'inno_path' to the faulting lang" exit 1 fi + MESON_LANGS=`grep "'code':" ${GIMP_TESTING_ABS_TOP_SRCDIR}/build/windows/installer/lang/meson.build | \ sed "s/^.*'code': *'\([^']*\)'.*$/\1/" |sort` MESON_LANGS=`echo "$MESON_LANGS" | tr '\n\r' ' ' | sed 's/\ //'` @@ -35,21 +34,3 @@ if [ "$PO_LANGS" != "$MESON_LANGS" ]; then echo "Please verify: build/windows/installer/lang/meson.build" exit 1 fi - -INSTALLER_LANGS=`grep -rI '^Name:.*MessagesFile.*Unofficial' ${GIMP_TESTING_ABS_TOP_SRCDIR}/build/windows/installer/base_gimp3264.iss | \ - sed 's/^.*Unofficial\\\\\([a-zA-Z_.]*\),.*$/\1/' | sort` -INSTALLER_LANGS=`echo "$INSTALLER_LANGS" | tr '\n\r' ' '` - -PULLED_UNOFFICIAL=`grep '^download_lang [^(]' ${GIMP_TESTING_ABS_TOP_SRCDIR}/build/windows/gitlab-ci/4_dist-gimp-inno.ps1 | \ - sed 's$^download_lang \([^.]*.isl.\?\)$\1$' | sort` -PULLED_UNOFFICIAL=`echo "$PULLED_UNOFFICIAL" | tr '\n\r' ' '` - -if [ "$INSTALLER_LANGS" = "$PULLED_UNOFFICIAL" ]; then - exit 0 -else - echo "Error: unofficial languages listed in the Windows installer script do not match the pulled InnoSetup files." - echo "- Pulled files: $PULLED_UNOFFICIAL" - echo "- Installer languages: $INSTALLER_LANGS" - echo "Please verify: build/windows/gitlab-ci/4_dist-gimp-inno.ps1" - exit 1 -fi