|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +CONTENT_DIR="package/contents" |
| 5 | +TRANSLATE_DIR="./translate" |
| 6 | +PACKAGE_NAME="luisbocanegra.smart.video.wallpaper.reborn" |
| 7 | + |
| 8 | +# https://api.kde.org/frameworks/ki18n/html/prg_guide.html |
| 9 | +EXTOPTS=( |
| 10 | + "--from-code=UTF-8 --kde --c++ -ci18n" |
| 11 | + "-ki18n:1 -ki18nc:1c,2 -ki18np:1,2 -ki18ncp:1c,2,3" |
| 12 | + "-kki18n:1 -kki18nc:1c,2 -kki18np:1,2 -kki18ncp:1c,2,3" |
| 13 | + "-kkli18n:1 -kkli18nc:1c,2 -kkli18np:1,2 -kkli18ncp:1c,2,3" |
| 14 | + "-kI18N_NOOP:1 -kI18NC_NOOP:1c,2" |
| 15 | + "--package-name=$PACKAGE_NAME" |
| 16 | +) |
| 17 | + |
| 18 | +extract() { |
| 19 | + find "$CONTENT_DIR" -name "*.qml" -print0 | sort -z | xargs -0 xgettext ${EXTOPTS[@]} --sort-by-file --output="$TRANSLATE_DIR/template.pot" |
| 20 | + for po in "$TRANSLATE_DIR"/*.po; do |
| 21 | + [ -f "$po" ] && msgmerge --quiet --update --backup=off "$po" "$TRANSLATE_DIR/template.pot" |
| 22 | + done |
| 23 | + |
| 24 | + echo "✅ Extraction completed!" |
| 25 | +} |
| 26 | + |
| 27 | +check() { |
| 28 | + if [ ! -f "$TRANSLATE_DIR/template.pot" ]; then |
| 29 | + echo "template.pot not found. Run extract first." |
| 30 | + exit 1 |
| 31 | + fi |
| 32 | + |
| 33 | + new_pot=$(mktemp) |
| 34 | + find "$CONTENT_DIR" -name "*.qml" -print0 | sort -z | xargs -0 xgettext ${EXTOPTS[@]} --sort-by-file --output="$new_pot" |
| 35 | + if ! diff <(grep -v '^"POT-Creation-Date' "$TRANSLATE_DIR/template.pot") <(grep -v '^"POT-Creation-Date' "$new_pot") > /dev/null; then |
| 36 | + echo "❌ template.pot is not up to date with the source files. You should run i18n extract." |
| 37 | + diff <(grep -v '^"POT-Creation-Date' "$TRANSLATE_DIR/template.pot") <(grep -v '^"POT-Creation-Date' "$new_pot") |
| 38 | + rm "$new_pot" |
| 39 | + exit 1 |
| 40 | + fi |
| 41 | + echo "✅ template.pot is up to date with the source files." |
| 42 | + |
| 43 | + rm "$new_pot" |
| 44 | + for po in "$TRANSLATE_DIR"/*.po; do |
| 45 | + if [ -f "$po" ]; then |
| 46 | + lang=$(basename "$po" .po) |
| 47 | + stats=$(msgfmt --statistics -o /dev/null "$po" 2>&1) |
| 48 | + untranslated=$(echo "$stats" | grep -o '[0-9]* untranslated' | cut -d' ' -f1) |
| 49 | + [ -z "$untranslated" ] && untranslated=0 |
| 50 | + fuzzy=$(echo "$stats" | grep -o '[0-9]* fuzzy' | cut -d' ' -f1) |
| 51 | + [ -z "$fuzzy" ] && fuzzy=0 |
| 52 | + |
| 53 | + if [ "$untranslated" != "0" ] || [ "$fuzzy" != "0" ]; then |
| 54 | + echo "⚠️ $lang: $untranslated untranslated, $fuzzy fuzzy" |
| 55 | + else |
| 56 | + echo "✅ $lang: complete" |
| 57 | + fi |
| 58 | + fi |
| 59 | + done |
| 60 | +} |
| 61 | + |
| 62 | +compile() { |
| 63 | + for po in "$TRANSLATE_DIR"/*.po; do |
| 64 | + if [ -f "$po" ]; then |
| 65 | + lang=$(basename "$po" .po) |
| 66 | + mkdir -p "$CONTENT_DIR/locale/$lang/LC_MESSAGES" |
| 67 | + msgfmt "$po" -o "$CONTENT_DIR/locale/$lang/LC_MESSAGES/plasma_wallpaper_$PACKAGE_NAME.mo" |
| 68 | + echo "✅ $lang: compiled" |
| 69 | + fi |
| 70 | + done |
| 71 | +} |
| 72 | + |
| 73 | +init() { |
| 74 | + if [ -z "$LANG" ]; then |
| 75 | + echo "Usage: $0 init <lang>" |
| 76 | + exit 1 |
| 77 | + fi |
| 78 | + if [ ! -f "$TRANSLATE_DIR/template.pot" ]; then |
| 79 | + echo "❌ template.pot not found. Run extract first." |
| 80 | + exit 1 |
| 81 | + fi |
| 82 | + if [ -f "$TRANSLATE_DIR/$LANG.po" ]; then |
| 83 | + echo "⚠️ $LANG.po already exists" |
| 84 | + exit 1 |
| 85 | + fi |
| 86 | + msginit --no-translator --input="$TRANSLATE_DIR/template.pot" --locale="$LANG" --output-file="$TRANSLATE_DIR/$LANG.po" |
| 87 | + echo "✅ $LANG.po created" |
| 88 | +} |
| 89 | + |
| 90 | +COMMAND="$1" |
| 91 | +LANG="$2" |
| 92 | + |
| 93 | +if ! command -v xgettext >/dev/null 2>&1; then |
| 94 | + echo "❌ xgettext not found. Please install gettext." |
| 95 | + exit 1 |
| 96 | +fi |
| 97 | + |
| 98 | +case "$COMMAND" in |
| 99 | + extract) extract ;; |
| 100 | + check) check ;; |
| 101 | + compile) compile ;; |
| 102 | + init) init ;; |
| 103 | + *) echo "Usage: $0 {extract|check|compile|init} [lang]" ; exit 1 ;; |
| 104 | +esac |
0 commit comments