65 lines
2.3 KiB
Bash
Executable File
65 lines
2.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# This script iterates through interface translation files,
|
|
# moves comments to the front, puts translated strings next,
|
|
# and finally looks for untranslated/missing strings by matching
|
|
# against "default" which it then adds to the translation, each
|
|
# line prepended by "!".
|
|
#
|
|
# Developers should run it from the project root after receiving
|
|
# a translation file from a translator:
|
|
# cp /tmp/new_japanese_translation rtdata/languages/Japanese
|
|
# ./tools/generateTranslationDiffs "Japanese"
|
|
#
|
|
# Running the script without an argument iterates through all files.
|
|
|
|
tmp=temp_file
|
|
|
|
cd "rtdata/languages" || { printf "%s\n" "You must run this script from the root of the project."; exit 1; }
|
|
# Build array of all interface translation files, or use user-specified ones only
|
|
unset langFiles
|
|
if [[ $# = 0 ]]; then
|
|
while read -r -d $'\0'; do
|
|
langFiles+=("$REPLY")
|
|
done < <(find . -not -iname "default" -not -iname "LICENSE" -not -iname "README" -not -iname "*.sh" -not -iname ".*" -not -iname "$tmp" -print0)
|
|
else
|
|
langFiles=("$@")
|
|
for langFile in "${langFiles[@]}"; do
|
|
if [[ ! -w $langFile ]]; then
|
|
printf "%s\n" "File \"$langFile\" not found or not writable." ""
|
|
exit 1
|
|
fi
|
|
done
|
|
fi
|
|
|
|
# First thing, fix default, so move comments to front, then strip the rest of any "!" and duplicates.
|
|
grep "^#.*" default > "$tmp"
|
|
grep -Ev '^[!|#]' default | sort -Vu >> "$tmp"
|
|
mv "$tmp" "default"
|
|
|
|
for file in "${langFiles[@]}"; do
|
|
t1="$(date +%s)"
|
|
printf "%s" "Processing $file"
|
|
dos2unix "$file" 2>/dev/null
|
|
# printf "%s\n" "Searching $file for changed strings"
|
|
|
|
unset trLines newLines
|
|
|
|
# Fill trLines with translated text
|
|
trLines+=("$(grep -Ev '^($|#|\!)' "$file" | sort -Vu)")
|
|
|
|
# KEY;String
|
|
# Match "default" keys with those in current translation file. If no match, add !KEY;String
|
|
while read -r 'defLine'; do
|
|
if [[ ! "${trLines[@]}" =~ "${defLine%%;*}" ]]; then
|
|
newLines+=("!${defLine}")
|
|
fi
|
|
done < <(grep "^[[:alnum:]].*" default)
|
|
|
|
# Form final translation file
|
|
printf "%s\n" "$(grep '^#' "$file" | sort -Vu)" "" "${trLines[@]}" "" "!!!!!!!!!!!!!!!!!!!!!!!!!" "! Untranslated keys follow; remove the ! prefix after an entry is translated." "!!!!!!!!!!!!!!!!!!!!!!!!!" "" "${newLines[@]}" > "$file"
|
|
t2="$(date +%s)"
|
|
tt=$((t2-t1))
|
|
printf "%s\n" " - took $tt seconds"
|
|
done
|