findMissingTranslations.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/usr/bin/env bash
  2. #
  3. # findMissingTranslations.sh
  4. #
  5. # Locate all language strings needing an update based on English
  6. #
  7. # Usage: findMissingTranslations.sh [language codes]
  8. #
  9. # If no language codes are specified then all languages will be checked
  10. #
  11. langname() {
  12. case "$1" in
  13. an ) echo "Aragonese" ;; bg ) echo "Bulgarian" ;;
  14. ca ) echo "Catalan" ;; cz ) echo "Czech" ;;
  15. da ) echo "Danish" ;; de ) echo "German" ;;
  16. el ) echo "Greek" ;; el_CY ) echo "Greek (Cyprus)" ;;
  17. el_gr) echo "Greek (Greece)" ;; en ) echo "English" ;;
  18. es ) echo "Spanish" ;; eu ) echo "Basque-Euskera" ;;
  19. fi ) echo "Finnish" ;; fr ) echo "French" ;;
  20. fr_na) echo "French (no accent)" ;; gl ) echo "Galician" ;;
  21. hr ) echo "Croatian (Hrvatski)" ;; hu ) echo "Hungarian / Magyar" ;;
  22. it ) echo "Italian" ;; jp_kana) echo "Japanese (Kana)" ;;
  23. ko_KR) echo "Korean" ;; nl ) echo "Dutch" ;;
  24. pl ) echo "Polish" ;; pt ) echo "Portuguese" ;;
  25. pt_br) echo "Portuguese (Brazil)" ;; ro ) echo "Romanian" ;;
  26. ru ) echo "Russian" ;; sk ) echo "Slovak" ;;
  27. sv ) echo "Swedish" ;; tr ) echo "Turkish" ;;
  28. uk ) echo "Ukrainian" ;; vi ) echo "Vietnamese" ;;
  29. zh_CN) echo "Simplified Chinese" ;; zh_TW ) echo "Traditional Chinese" ;;
  30. * ) echo "<unknown>" ;;
  31. esac
  32. }
  33. LANGHOME="Marlin/src/lcd/language"
  34. [ -d $LANGHOME ] && cd $LANGHOME
  35. FILES=$(ls language_*.h | grep -v -E "(_en|_test)\.h" | sed -E 's/language_([^\.]+)\.h/\1/' | tr '\n' ' ')
  36. # Get files matching the given arguments
  37. TEST_LANGS=""
  38. if [[ -n $@ ]]; then
  39. for K in "$@"; do
  40. for F in $FILES; do
  41. [[ $F == $K ]] && TEST_LANGS+="$F "
  42. done
  43. done
  44. [[ -z $TEST_LANGS ]] && { echo "No languages matching $@." ; exit 0 ; }
  45. else
  46. TEST_LANGS=$FILES
  47. fi
  48. echo "Finding all missing strings for $TEST_LANGS..."
  49. WORD_LINES=() # Complete lines for all words (or, grep out of en at the end instead)
  50. ALL_MISSING=() # All missing languages for each missing word
  51. #NEED_WORDS=() # All missing words across all specified languages
  52. WORD_COUNT=0
  53. # Go through all strings in the English language file
  54. # For each word, query all specified languages for the word
  55. # If the word is missing, add its language to the list
  56. for WORD in $(awk '/LSTR/{print $2}' language_en.h); do
  57. # Skip MSG_MARLIN
  58. [[ $WORD == "MSG_MARLIN" ]] && break
  59. ((WORD_COUNT++))
  60. # Find all selected languages that lack the string
  61. LANG_MISSING=" "
  62. for LANG in $TEST_LANGS; do
  63. if [[ $(grep -c -E "^ *LSTR +$WORD\b" language_${LANG}.h) -eq 0 ]]; then
  64. INHERIT=$(awk '/using namespace/{print $3}' language_${LANG}.h | sed -E 's/Language_([a-zA-Z_]+)\s*;/\1/')
  65. if [[ -z $INHERIT || $INHERIT == "en" ]]; then
  66. LANG_MISSING+="$LANG "
  67. elif [[ $(grep -c -E "^ *LSTR +$WORD\b" language_${INHERIT}.h) -eq 0 ]]; then
  68. LANG_MISSING+="$LANG "
  69. fi
  70. fi
  71. done
  72. # For each word store all the missing languages
  73. if [[ $LANG_MISSING != " " ]]; then
  74. WORD_LINES+=("$(grep -m 1 -E "$WORD\b" language_en.h)")
  75. ALL_MISSING+=("$LANG_MISSING")
  76. #NEED_WORDS+=($WORD)
  77. fi
  78. done
  79. echo
  80. echo "${#WORD_LINES[@]} out of $WORD_COUNT LCD strings need translation"
  81. for LANG in $TEST_LANGS; do
  82. HED=0 ; IND=0
  83. for WORDLANGS in "${ALL_MISSING[@]}"; do
  84. # If the current word is missing from the current language then print it
  85. if [[ $WORDLANGS =~ " $LANG " ]]; then
  86. [[ $HED == 0 ]] && { echo ; echo "Missing strings for language_$LANG.h ($(langname $LANG)):" ; HED=1 ; }
  87. echo "${WORD_LINES[$IND]}"
  88. fi
  89. ((IND++))
  90. done
  91. done