This commit is contained in:
heckflosse 2019-03-31 23:31:44 +02:00
commit db65d11aa1

View File

@ -15,49 +15,56 @@
# #
# Locale files are generated automatically: # Locale files are generated automatically:
# - English (UK) # - English (UK)
# - Polish (Latin Characters)
tmp=temp_file tmp=temp_file
if [[ -w $tmp ]]; then if [[ -w $tmp ]]; then
rm -v "$tmp" rm -v "$tmp"
fi fi
abort () { abort () {
printf "%s\n" "" "Aborting" printf "%s\n" "" "Aborting"
rm -v "$tmp" rm -v "$tmp"
exit 1 exit 1
} }
trap 'abort' HUP INT QUIT ABRT TERM trap 'abort' HUP INT QUIT ABRT TERM
cd "rtdata/languages" || { printf "%s\n" "You must run this script from the root of the project."; exit 1; } 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 # Build array of all interface translation files, or use user-specified ones only
unset langFiles unset langFiles
if [[ $# = 0 ]]; then if [[ $# = 0 ]]; then
while read -r; do while read -r; do
langFiles+=("$REPLY") langFiles+=("$REPLY")
done < <(find . -not -iname "default" -not -iname "LICENSE" -not -iname "README" -not -iname "*.sh" -not -iname ".*" -not -iname "$tmp" -not -iname "English (UK)" -not -iname "Polish (Latin Characters)" | sort) done < <(find . -not -iname "default" \
-not -iname "LICENSE" \
-not -iname "README" \
-not -iname "*.sh" \
-not -iname ".*" \
-not -iname "$tmp" \
-not -iname "English (UK)" \
-not -iname "Polish (Latin Characters)" \
| sort)
else else
langFiles=("$@") langFiles=("$@")
for langFile in "${langFiles[@]}"; do for langFile in "${langFiles[@]}"; do
if [[ ! -w $langFile ]]; then if [[ ! -w $langFile ]]; then
printf "%s\n" "File \"$langFile\" not found or not writable." "" printf "%s\n" "File \"$langFile\" not found or not writable." ""
exit 1 exit 1
fi fi
done done
fi fi
getComments () { getComments () {
grep -E "^#.+" "$1" | sort -Vu grep -E "^#.+" "$1" | sort -Vu
} }
getChanged () { getChanged () {
grep -Ev '^(!|#|$)' "$1" | sort -Vu -t ';' --key=1,1 grep -Ev '^(!|#|$)' "$1" | sort -Vu -t ';' --key=1,1
} }
getUnchanged () { getUnchanged () {
grep -E "^\!.+" "$1" | sort -Vu -t ';' --key=1,1 grep -E "^\!.+" "$1" | sort -Vu -t ';' --key=1,1
} }
# First thing, fix default, so move comments to front, then strip the rest of any "!" and duplicates. # First thing, fix default, so move comments to front, then strip the rest of any "!" and duplicates.
@ -70,31 +77,31 @@ i=1
printf "%s\n" "Digging through ${#langFiles[@]} file(s). This may take a while." printf "%s\n" "Digging through ${#langFiles[@]} file(s). This may take a while."
ttot1="$(date +%s)" ttot1="$(date +%s)"
for file in "${langFiles[@]}"; do for file in "${langFiles[@]}"; do
t1="$(date +%s)" t1="$(date +%s)"
printf "%02d - ${file#.*/}" "$i" printf "%02d - ${file#.*/}" "$i"
dos2unix "$file" 2>/dev/null dos2unix "$file" 2>/dev/null
unset newLines unset newLines
# KEY;String # KEY;String
# Match "default" keys with those in current translation file. If no match, add !KEY;String # Match "default" keys with those in current translation file. If no match, add !KEY;String
while read -r 'defLine'; do while read -r 'defLine'; do
defKey="${defLine%%;*}" defKey="${defLine%%;*}"
if ! grep -q "^${defKey}\;" "$file"; then if ! grep -q "^${defKey}\;" "$file"; then
newLines+=("!${defLine}") newLines+=("!${defLine}")
fi fi
done < <(getChanged default) done < <(getChanged default)
# Form final translation file # Form final translation file
# Start with comments # Start with comments
if [[ -n "$(getComments "$file")" ]]; then if [[ -n "$(getComments "$file")" ]]; then
printf "%s\n" "$(getComments "$file")" "" >> "$tmp" printf "%s\n" "$(getComments "$file")" "" >> "$tmp"
fi fi
# Add already-translated lines # Add already-translated lines
getChanged "$file" >> "$tmp" getChanged "$file" >> "$tmp"
printf '%s\n' "" >> "$tmp" printf '%s\n' "" >> "$tmp"
# End with new, untranslated lines # End with new, untranslated lines
if [[ -n "${newLines[@]}" ]]; then if [[ -n "${newLines[@]}" ]]; then
printf "%s\n" "!!!!!!!!!!!!!!!!!!!!!!!!!" "! Untranslated keys follow; remove the ! prefix after an entry is translated." "!!!!!!!!!!!!!!!!!!!!!!!!!" "" "${newLines[@]}" >> "$tmp" printf "%s\n" "!!!!!!!!!!!!!!!!!!!!!!!!!" "! Untranslated keys follow; remove the ! prefix after an entry is translated." "!!!!!!!!!!!!!!!!!!!!!!!!!" "" "${newLines[@]}" >> "$tmp"
fi fi
mv "$tmp" "$file" mv "$tmp" "$file"
t2="$(date +%s)" t2="$(date +%s)"
@ -104,21 +111,23 @@ for file in "${langFiles[@]}"; do
done done
case "${langFiles[@]}" in case "${langFiles[@]}" in
*"./English (US)"*) printf "%s\n" "Creating English (UK) file" *"./English (US)"*) printf "%s\n" "Creating English (UK) file"
getComments "English (US)" > "English (UK)" getComments "English (US)" > "English (UK)"
grep -Ei ".+;.*(color|behavior|center).*" default | \ grep -Ei ".+;.*(color|behavior|center).*" default | \
sed -e '/^#/d' -e 'h;s/^[^;]*;//; s/olor/olour/g; x;s/;.*//;G;s/\n/;/' \ sed -e '/^#/d' -e 'h;s/^[^;]*;//; s/olor/olour/g; x;s/;.*//;G;s/\n/;/' \
-e 'h;s/^[^;]*;//; s/ehavior/ehaviour/g; x;s/;.*//;G;s/\n/;/' \ -e 'h;s/^[^;]*;//; s/ehavior/ehaviour/g; x;s/;.*//;G;s/\n/;/' \
-e 'h;s/^[^;]*;//; s/center/centre/g; x;s/;.*//;G;s/\n/;/' \ -e 'h;s/^[^;]*;//; s/center/centre/g; x;s/;.*//;G;s/\n/;/' \
-e 'h;s/^[^;]*;//; s/Center/Centre/g; x;s/;.*//;G;s/\n/;/' >> English\ \(UK\) -e 'h;s/^[^;]*;//; s/Center/Centre/g; x;s/;.*//;G;s/\n/;/' >> English\ \(UK\)
grep -Evi ".+;.*(color|behavior|center).*" "English (US)" | grep -Ev "^#" >> "English (UK)" grep -Evi ".+;.*(color|behavior|center).*" "English (US)" | grep -Ev "^#" >> "English (UK)"
;;& ;;&
*"./Polish"*) printf "%s\n" "Creating Polish (Latin Characters) file" *"./Polish"*) printf "%s\n" "Creating Polish (Latin Characters) file"
sed 'y/ĄĆĘŁŃÓŚŹŻąćęłńóśźż/ACELNOSZZacelnoszz/' < Polish > "Polish (Latin Characters)" sed 'y/ĄĆĘŁŃÓŚŹŻąćęłńóśźż/ACELNOSZZacelnoszz/' < Polish > "Polish (Latin Characters)"
;;& ;;&
esac esac
ttot2="$(date +%s)" ttot2="$(date +%s)"
ttot=$((ttot2-ttot1)) ttot=$((ttot2-ttot1))
tsec=$((ttot%60)) tsec=$((ttot%60))
tmin=$((ttot/60)) tmin=$((ttot/60))
printf "%s\n" "Finished updating ${#langFiles[@]} files." "Total time: ${tmin}m ${tsec}s" printf "%s\n" "Finished updating ${#langFiles[@]} files." "Total time: ${tmin}m ${tsec}s"