#!/bin/sh # shellcheck disable=SC1090 # The installer-translations package contains translations of messages displayed by 0configuration # scripts included in the Slint installer, thanks to the translators of the Slint project. # We get the translations from the repository https://github.com/DidierSpaier/slint-translations # As the PO files are stored initially in https://crowdin.com/project/slint/translations # make sure that the files in https://github.com/DidierSpaier/slint-translations be up to date # before running this scripts. # This script also allows to prepare translations for alternative unofficial installers for # Salix and Slackware. [ "$#" -ne 1 ] && distribution=slint [ ! "$distribution" ] && distribution="$1" if [ ! "$distribution" = salix ] && [ ! "$distribution" = slackware ] && [ ! "$distribution" = slint ]; then echo "$distribution is not a supported distribution" exit fi [ "$distribution" = slint ] && Dist=Slint [ "$distribution" = slackware ] && Dist=Slackware [ "$distribution" = salix ] && Dist=Salix PRGNAM=installer-translations-"$distribution" BUILD=$(date -u +%Y%m%d)slint ARCH=noarch VERSION=15.0 CWD=$(pwd) PKG=$CWD/package-$PRGNAM OUTPUT=$CWD rm -rf $PKG mkdir -p "$PKG"/wip export LANG=en_US.utf8 # Get the files rm -rf slint-translations git clone https://github.com/DidierSpaier/slint-translations.git SLINTDOCS=$CWD/slint-translations rm -f SeTlocales # Get te file SeTlocales from https://github.com/DidierSpaier/build_ISO/tree/main/misc wget https://raw.githubusercontent.com/DidierSpaier/build_ISO/refs/heads/main/misc/SeTlocales # Build the PO files # We first need to format the PO files in such a way that msggrep will # work. msggrep ignores references like: # File: , line: # But expects instead: #: : # # shellcheck disable=SC1090 . "$CWD"/SeTlocales cd "$SLINTDOCS/po/auto" || exit 1 DOMAINNAME=auto for i in *po; do sed "s@Slint@$Dist@g" "$i" > bof mv bof "$i" sed "/^#/{s/# File: /#: /;s/, line:[ ]*/:/}" "$i" > "$PKG"/wip/"$i" msggrep -o "$PKG"/"${i%%.*}"."${DOMAINNAME}".po -N ./*auto "$PKG"/wip/"$i" done cd "$SLINTDOCS/po/rc.S" || exit 1 DOMAINNAME=rc.S for i in *po; do sed "s@Slint@$Dist@g" "$i" > bof mv bof "$i" sed "/^#/{s/# File: /#: /;s/, line:[ ]*/:/}" "$i" > "$PKG"/wip/"$i" msggrep -o "$PKG"/"${i%%.*}"."${DOMAINNAME}".po -N ./*rc.S "$PKG"/wip/"$i" done cd "$SLINTDOCS/po/SeTkeymap" || exit 1 DOMAINNAME=SeTkeymap for i in *SeTkeymap.po; do sed "/^#/{s/# File: /#: /;s/, line:[ ]*/:/}" "$i" > "$PKG"/wip/"$i" msggrep -o "$PKG"/"${j%%.*}"."${DOMAINNAME}".po -N ./*SeTkeymap "$PKG"/wip/"$i" done cd "$SLINTDOCS/po/slint-scripts" || exit 1 DOMAINNAME=slint-scripts for i in *slint-scripts.po; do sed "/^#/{s/# File: /#: /;s/, line:[ ]*/:/}" "$i" > "$PKG"/wip/"$i" msggrep -o "$PKG"/"${j%%.*}"."${DOMAINNAME}".po -N ./*slint-scripts "$PKG"/wip/"$i" done cd "$PKG"/wip || exit 1 # Compile the message catalogs # We will use translated strings tagged fuzzy. #for k in auto rc.S SeTkeymap slint-scripts; do for k in auto rc.S SeTkeymap slint-scripts; do DOMAINNAME=$k for j in *"$k".po; do ll_TT="${j%%.*}" SeTLocaleDir # running SeTLocaleDir sets LocaleDir # shellcheck disable=SC2154 if [ "$LocaleDir" = "missing" ]; then printf %b "I don't know where to install the message catalog for ${ll_TT}.\n" printf %b "Please request that the file $CWD/files-ib-initrd/SeTlocales be completed\n" exit fi MO_DIR="$PKG"/usr/share/locale/"$LocaleDir"/LC_MESSAGES mkdir -p "$MO_DIR" msgfmt --strict -c -v -f --statistics -o "$MO_DIR"/"${DOMAINNAME}".mo "$j" 2>&1|tee error if ! grep -q " translated messages" error; then translated=0 else grep "^.*$j: " error > stat$j grep "^.*$j: " error > stat translated=$(sed "s@.*: @@;s@ .*@@" stat) fi if ! grep -q "untranslated" stat; then untranslated=0 else untranslated=$(sed "s@.* translated message[s]\{0,1\}, @@;s@ .*@@" stat) total=$((translated+untranslated)) percentage=$((translated*100/total)) if [ $percentage -lt 85 ]; then rm "$MO_DIR"/"${DOMAINNAME}".mo echo "$j rejected, only ${percentage}% translated." fi fi done done cd "$CWD" || exit 1 rm -rf "$PKG"/wip rm -f "$PKG"/*po mkdir -p "$PKG"/install cat << EOF > "$PKG"/install/slack-desc |-----handy-ruler------------------------------------------------------| installer-translations: installer-translations (translations of messages in Slint installer) installer-translations: installer-translations: This package contains translations of messages displayed by installer-translations: configurations scripts included in the Slint installer, thanks to the installer-translations: translators of the Slint project. Visit our website: http://slint.fr installer-translations: installer-translations: installer-translations: installer-translations: installer-translations: EOF rm -f "$OUTPUT"/"$PRGNAM"*txz ( cd $PKG || exit 1 /sbin/makepkg -l y -c n "$OUTPUT"/"$PRGNAM"-"$VERSION"-"$ARCH"-"${BUILD}".txz )