🧑💻 Improve missing translations script (#25841)
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
This commit is contained in:
parent
772e19aab9
commit
a3eace117c
|
@ -9,6 +9,29 @@
|
|||
# If no language codes are specified then all languages will be checked
|
||||
#
|
||||
|
||||
langname() {
|
||||
case "$1" in
|
||||
an ) echo "Aragonese" ;; bg ) echo "Bulgarian" ;;
|
||||
ca ) echo "Catalan" ;; cz ) echo "Czech" ;;
|
||||
da ) echo "Danish" ;; de ) echo "German" ;;
|
||||
el ) echo "Greek" ;; el_CY ) echo "Greek (Cyprus)" ;;
|
||||
el_gr) echo "Greek (Greece)" ;; en ) echo "English" ;;
|
||||
es ) echo "Spanish" ;; eu ) echo "Basque-Euskera" ;;
|
||||
fi ) echo "Finnish" ;; fr ) echo "French" ;;
|
||||
fr_na) echo "French (no accent)" ;; gl ) echo "Galician" ;;
|
||||
hr ) echo "Croatian (Hrvatski)" ;; hu ) echo "Hungarian / Magyar" ;;
|
||||
it ) echo "Italian" ;; jp_kana) echo "Japanese (Kana)" ;;
|
||||
ko_KR) echo "Korean" ;; nl ) echo "Dutch" ;;
|
||||
pl ) echo "Polish" ;; pt ) echo "Portuguese" ;;
|
||||
pt_br) echo "Portuguese (Brazil)" ;; ru ) echo "Russian" ;;
|
||||
sk ) echo "Slovak" ;; sv ) echo "Swedish" ;;
|
||||
test ) echo "TEST" ;; tr ) echo "Turkish" ;;
|
||||
uk ) echo "Ukrainian" ;; vi ) echo "Vietnamese" ;;
|
||||
zh_CN) echo "Simplified Chinese" ;; zh_TW ) echo "Traditional Chinese" ;;
|
||||
* ) echo "<unknown>" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
LANGHOME="Marlin/src/lcd/language"
|
||||
|
||||
[ -d $LANGHOME ] && cd $LANGHOME
|
||||
|
@ -20,7 +43,7 @@ TEST_LANGS=""
|
|||
if [[ -n $@ ]]; then
|
||||
for K in "$@"; do
|
||||
for F in $FILES; do
|
||||
[[ "$F" != "${F%$K*}" ]] && TEST_LANGS+="$F "
|
||||
[[ $F == $K ]] && TEST_LANGS+="$F "
|
||||
done
|
||||
done
|
||||
[[ -z $TEST_LANGS ]] && { echo "No languages matching $@." ; exit 0 ; }
|
||||
|
@ -28,20 +51,54 @@ else
|
|||
TEST_LANGS=$FILES
|
||||
fi
|
||||
|
||||
echo "Missing strings for $TEST_LANGS..."
|
||||
echo "Finding all missing strings for $TEST_LANGS..."
|
||||
|
||||
WORD_LINES=() # Complete lines for all words (or, grep out of en at the end instead)
|
||||
ALL_MISSING=() # All missing languages for each missing word
|
||||
#NEED_WORDS=() # All missing words across all specified languages
|
||||
|
||||
WORD_COUNT=0
|
||||
|
||||
# Go through all strings in the English language file
|
||||
# For each word, query all specified languages for the word
|
||||
# If the word is missing, add its language to the list
|
||||
for WORD in $(awk '/LSTR/{print $2}' language_en.h); do
|
||||
# Skip MSG_MARLIN
|
||||
[[ $WORD == "MSG_MARLIN" ]] && break
|
||||
LANG_LIST=""
|
||||
|
||||
((WORD_COUNT++))
|
||||
|
||||
# Find all selected languages that lack the string
|
||||
LANG_MISSING=" "
|
||||
for LANG in $TEST_LANGS; do
|
||||
if [[ $(grep -c -E "^ *LSTR +$WORD\b" language_${LANG}.h) -eq 0 ]]; then
|
||||
INHERIT=$(awk '/using namespace/{print $3}' language_${LANG}.h | sed -E 's/Language_([a-zA-Z_]+)\s*;/\1/')
|
||||
if [[ -z $INHERIT || $INHERIT == "en" ]]; then
|
||||
LANG_LIST+=" $LANG"
|
||||
LANG_MISSING+="$LANG "
|
||||
elif [[ $(grep -c -E "^ *LSTR +$WORD\b" language_${INHERIT}.h) -eq 0 ]]; then
|
||||
LANG_LIST+=" $LANG"
|
||||
LANG_MISSING+="$LANG "
|
||||
fi
|
||||
fi
|
||||
done
|
||||
[[ -n $LANG_LIST ]] && printf "%-38s :%s\n" "$WORD" "$LANG_LIST"
|
||||
# For each word store all the missing languages
|
||||
if [[ $LANG_MISSING != " " ]]; then
|
||||
WORD_LINES+=("$(grep -m 1 -E "$WORD\b" language_en.h)")
|
||||
ALL_MISSING+=("$LANG_MISSING")
|
||||
#NEED_WORDS+=($WORD)
|
||||
fi
|
||||
done
|
||||
|
||||
echo
|
||||
echo "${#WORD_LINES[@]} out of $WORD_COUNT LCD strings need translation"
|
||||
|
||||
for LANG in $TEST_LANGS; do
|
||||
HED=0 ; IND=0
|
||||
for WORDLANGS in "${ALL_MISSING[@]}"; do
|
||||
# If the current word is missing from the current language then print it
|
||||
if [[ $WORDLANGS =~ " $LANG " ]]; then
|
||||
[[ $HED == 0 ]] && { echo ; echo "Missing strings for language_$LANG.h ($(langname $LANG)):" ; HED=1 ; }
|
||||
echo "${WORD_LINES[$IND]}"
|
||||
fi
|
||||
((IND++))
|
||||
done
|
||||
done
|
||||
|
|
Loading…
Reference in a new issue