Optimized generateTranslationDiffs, 5x faster, changed from parameter expansion to grep.

This commit is contained in:
Beep6581
2015-11-27 17:29:09 +01:00
parent 3bf8a1f3f6
commit 56c0762256

View File

@@ -73,26 +73,26 @@ 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 trLines newLines unset newLines
# Fill trLines with previously translated text
trLines+=("$(getChanged "$file")")
# 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 [[ ! "${trLines[@]}" =~ ${defKey}\; ]]; 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
if [[ -n "$(getComments "$file")" ]]; then if [[ -n "$(getComments "$file")" ]]; then
printf "%s\n" "$(getComments "$file")" "" >> "$tmp" printf "%s\n" "$(getComments "$file")" "" >> "$tmp"
fi fi
if [[ -n "${trLines[@]}" ]]; then # Add already-translated lines
printf "%s\n" "${trLines[@]}" "" >> "$tmp" getChanged "$file" >> "$tmp"
fi printf '%s\n' "" >> "$tmp"
# 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