lang-import.sh 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. #!/bin/bash
  2. #
  3. # Version 1.0.1 Build 24
  4. #
  5. # lang-import.sh - multi-language support script
  6. # for importing translated xx.po
  7. #
  8. #############################################################################
  9. # Change log:
  10. # 9 Nov. 2018, XPila, Initial
  11. # 21 Nov. 2018, XPila, fix - replace '\n' with space in all languages
  12. # 10 Dec. 2018, jhoblitt, make all shell scripts executable
  13. # 21 Aug. 2019, 3d-gussner, Added "All" argument and it is default in nothing is chosen
  14. # Added few German/French diacritical characters
  15. # 6 Sep. 2019, DRracer, change to bash
  16. # 14 Sep. 2019, 3d-gussner, Prepare adding new language
  17. # 1 Mar. 2019, 3d-gussner, Move `Dutch` language parts
  18. # Add templates for future community languages
  19. # 17 Dec. 2021, 3d-gussner, Use one config file for all languages
  20. # Fix missing last translation
  21. # Add counter
  22. # replace two double quotes with `\x00`
  23. # 21 Dec. 2021, 3d-gussner, Add Swedish, Danish, Slovanian, Hungarian,
  24. # Luxembourgish, Croatian
  25. # 3 Jan. 2022, 3d-gussner, Add Lithuanian
  26. # Cleanup outaded code
  27. # 11 Jan. 2022, 3d-gussner, Added version and Change log
  28. # colored output
  29. # Add Community language support
  30. # Use `git rev-list --count HEAD lang-import.sh`
  31. # to get Build Nr
  32. # 14 Jan. 2022, 3d-gussner, Replace German UTF-8 'äöüß' to HD44780 A00 ROM 'äöüß'
  33. # 28 Jan. 2022, 3d-gussner, Run lang-check and output `xx-output.txt` file to review
  34. # translations
  35. # new argruments `--information` `--import-check`
  36. #############################################################################
  37. # Config:
  38. if [ -z "$CONFIG_OK" ]; then eval "$(cat config.sh)"; fi
  39. if [ -z "$CONFIG_OK" ] | [ $CONFIG_OK -eq 0 ]; then echo "$(tput setaf 1)Config NG!$(tput sgr 0)" >&2; exit 1; fi
  40. echo "$(tput setaf 2)lang-import.sh started$(tput sgr 0)" >&2
  41. LNG=$1
  42. # if no arguments, 'all' is selected (all po and also pot will be generated)
  43. if [ -z "$LNG" ]; then LNG=all; fi
  44. if [[ ! -z "$COMMUNITY_LANGUAGES" && "$LNG" = "all" ]]; then
  45. LANGUAGES+=" $COMMUNITY_LANGUAGES"
  46. else
  47. LANGUAGES="$LNG"
  48. fi
  49. echo "$(tput setaf 2)lang-import languages:$LANGUAGES$(tput sgr 0)" >&2
  50. # if 'all' is selected, script will generate all po files and also pot file
  51. if [ "$LNG" = "all" ]; then
  52. for lang in $LANGUAGES; do
  53. ./lang-import.sh $lang
  54. done
  55. exit 0
  56. fi
  57. # language code (iso639-1) is equal to LNG
  58. LNGISO=$LNG
  59. # exception for 'cz' (code='cs')
  60. if [ "$LNG" = "cz" ]; then LNGISO=cs; fi
  61. # cd to input folder
  62. cd po/new
  63. # check if input file exists
  64. if ! [ -e $LNGISO.po ]; then
  65. echo "$(tput setaf 1)Input file $LNGISO.po not found!$(tput sgr 0)" >&2
  66. exit -1
  67. fi
  68. #convert '\\e' sequencies to 'x1b' and '\\' to '\'
  69. cat $LNGISO.po | sed 's/\\e/\\x1b/g;s/\\\\/\\/g' > $LNG'_filtered.po'
  70. #replace '\n' with ' ' (single space)
  71. sed -i 's/ \\n/ /g;s/\\n/ /g' $LNG'_filtered.po'
  72. #replace in czech translation
  73. if [ "$LNG" = "cz" ]; then
  74. #replace 'ž' with 'z'
  75. sed -i 's/\xc5\xbe/z/g' $LNG'_filtered.po'
  76. #replace 'ì' with 'e'
  77. sed -i 's/\xc4\x9b/e/g' $LNG'_filtered.po'
  78. #replace 'í' with 'i'
  79. sed -i 's/\xc3\xad/i/g' $LNG'_filtered.po'
  80. #replace 'ø' with 'r'
  81. sed -i 's/\xc5\x99/r/g' $LNG'_filtered.po'
  82. #replace 'è' with 'c'
  83. sed -i 's/\xc4\x8d/c/g' $LNG'_filtered.po'
  84. #replace 'á' with 'a'
  85. sed -i 's/\xc3\xa1/a/g' $LNG'_filtered.po'
  86. #replace 'é' with 'e'
  87. sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
  88. fi
  89. #replace in german translation https://en.wikipedia.org/wiki/German_orthography
  90. if [ "$LNG" = "de" ]; then
  91. #replace UTF-8 'äöüß' to HD44780 A00 'äöüß'
  92. #replace 'ä' with 'A00 ROM ä'
  93. sed -i 's/\xc3\xa4/\\xe1/g' $LNG'_filtered.po'
  94. #replace 'Ä' with 'A00 ROM ä'
  95. sed -i 's/\xc3\x84/\\xe1/g' $LNG'_filtered.po'
  96. #replace 'ü' with 'A00 ROM ü'
  97. sed -i 's/\xc3\xbc/\\xf5/g' $LNG'_filtered.po'
  98. #replace 'Ü' with 'A00 ROM ü'
  99. sed -i 's/\xc3\x9c/\\xf5/g' $LNG'_filtered.po'
  100. #replace 'ö' with 'A00 ROM ö'
  101. sed -i 's/\xc3\xb6/\\xef/g' $LNG'_filtered.po'
  102. #replace 'Ö' with 'A00 ROM ö'
  103. sed -i 's/\xc3\x96/\\xef/g' $LNG'_filtered.po'
  104. #replace 'ß' with 'A00 ROM ß'
  105. sed -i 's/\xc3\x9f/\\xe2/g' $LNG'_filtered.po'
  106. fi
  107. #replace in spain translation
  108. if [ "$LNG" = "es" ]; then
  109. #replace 'á' with 'a'
  110. sed -i 's/\xc3\xa1/a/g' $LNG'_filtered.po'
  111. #replace '¿' with '?'
  112. sed -i 's/\xc2\xbf/?/g' $LNG'_filtered.po'
  113. #replace 'ó' with 'o'
  114. sed -i 's/\xc3\xb3/o/g' $LNG'_filtered.po'
  115. #replace 'é' with 'e'
  116. sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
  117. #replace 'í' with 'i'
  118. sed -i 's/\xc3\xad/i/g' $LNG'_filtered.po'
  119. #replace '!' with '!'
  120. sed -i 's/\xc2\xa1/!/g' $LNG'_filtered.po'
  121. #replace 'n~' with 'n'
  122. sed -i 's/\xc3\xb1/n/g' $LNG'_filtered.po'
  123. fi
  124. #replace in french translation https://en.wikipedia.org/wiki/French_orthography
  125. if [ "$LNG" = "fr" ]; then
  126. #replace 'á' with 'a' (right)
  127. sed -i 's/\xc3\xa1/a/g' $LNG'_filtered.po'
  128. #replace 'Á' with 'A' (right)
  129. sed -i 's/\xc3\x81/A/g' $LNG'_filtered.po'
  130. #replace 'à' with 'a' (left)
  131. sed -i 's/\xc3\xa0/a/g' $LNG'_filtered.po'
  132. #replace 'À' with 'A' (left)
  133. sed -i 's/\xc3\x80/A/g' $LNG'_filtered.po'
  134. #replace 'é' with 'e' (right)
  135. sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
  136. #replace 'É' with 'E' (right)
  137. sed -i 's/\xc3\x89/E/g' $LNG'_filtered.po'
  138. #replace 'è' with 'e' (left)
  139. sed -i 's/\xc3\xa8/e/g' $LNG'_filtered.po'
  140. #replace 'È' with 'E' (left)
  141. sed -i 's/\xc3\x88/E/g' $LNG'_filtered.po'
  142. fi
  143. #replace in italian translation
  144. if [ "$LNG" = "it" ]; then
  145. #replace 'é' with 'e' (left)
  146. sed -i 's/\xc3\xa8/e/g' $LNG'_filtered.po'
  147. #replace 'á' with 'a' (left)
  148. sed -i 's/\xc3\xa0/a/g' $LNG'_filtered.po'
  149. #replace 'ó' with 'o' (left)
  150. sed -i 's/\xc3\xb2/o/g' $LNG'_filtered.po'
  151. #replace 'ú' with 'u' (left)
  152. sed -i 's/\xc3\xb9/u/g' $LNG'_filtered.po'
  153. #replace 'é' with 'e'
  154. sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
  155. #replace 'É' with 'E' (left)
  156. sed -i 's/\xc3\x88/E/g' $LNG'_filtered.po'
  157. fi
  158. #replace in dutch translation according to https://nl.wikipedia.org/wiki/Accenttekens_in_de_Nederlandse_spelling
  159. if [ "$LNG" = "nl" ]; then
  160. #replace 'ë' with 'e'
  161. sed -i 's/\xc3\xab/e/g' $LNG'_filtered.po'
  162. #replace 'ï' with 'i'
  163. sed -i 's/\xc3\xaf/i/g' $LNG'_filtered.po'
  164. #replace 'é' with 'e'
  165. sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
  166. #replace 'è' with 'e' (left)
  167. sed -i 's/\xc3\xa8/e/g' $LNG'_filtered.po'
  168. #replace 'ö' with 'o' (left)
  169. sed -i 's/\xc3\xb6/o/g' $LNG'_filtered.po'
  170. #replace 'ê' with 'e' (left)
  171. sed -i 's/\xc3\xaa/e/g' $LNG'_filtered.po'
  172. #replace 'ü' with 'u' (left)
  173. sed -i 's/\xc3\xbc/u/g' $LNG'_filtered.po'
  174. #replace 'ç' with 'c' (left)
  175. sed -i 's/\xc3\xa7/c/g' $LNG'_filtered.po'
  176. #replace 'á' with 'a' (left)
  177. sed -i 's/\xc3\xa1/a/g' $LNG'_filtered.po'
  178. #replace 'à' with 'a' (left)
  179. sed -i 's/\xc3\xa0/a/g' $LNG'_filtered.po'
  180. #replace 'ä' with 'a' (left)
  181. sed -i 's/\xc3\xa4/a/g' $LNG'_filtered.po'
  182. #replace 'û' with 'u' (left)
  183. sed -i 's/\xc3\xbc/u/g' $LNG'_filtered.po'
  184. #replace 'î' with 'i' (left)
  185. sed -i 's/\xc3\xae/i/g' $LNG'_filtered.po'
  186. #replace 'í' with 'i' (left)
  187. sed -i 's/\xc3\xad/i/g' $LNG'_filtered.po'
  188. #replace 'ô' with 'o' (left)
  189. sed -i 's/\xc3\xb4/o/g' $LNG'_filtered.po'
  190. #replace 'ú' with 'u' (left)
  191. sed -i 's/\xc3\xba/u/g' $LNG'_filtered.po'
  192. #replace 'ñ' with 'n' (left)
  193. sed -i 's/\xc3\xb1/n/g' $LNG'_filtered.po'
  194. #replace 'â' with 'a' (left)
  195. sed -i 's/\xc3\xa2/a/g' $LNG'_filtered.po'
  196. #replace 'Å' with 'A' (left)
  197. sed -i 's/\xc3\x85/A/g' $LNG'_filtered.po'
  198. fi
  199. if [ "$LNG" = "sv" ]; then
  200. #repace 'Å' with 'Aa'
  201. sed -i 's/\xc3\x85/Aa/g' $LNG'_filtered.po'
  202. #repace 'å' with 'aa'
  203. sed -i 's/\xc3\xA5/aa/g' $LNG'_filtered.po'
  204. fi
  205. if [ "$LNG" = "da" ]; then
  206. #repace 'Å' with 'Aa'
  207. sed -i 's/\xc3\x85/Aa/g' $LNG'_filtered.po'
  208. #repace 'å' with 'aa'
  209. sed -i 's/\xc3\xA5/aa/g' $LNG'_filtered.po'
  210. fi
  211. if [ "$LNG" = "sl" ]; then
  212. #replace 'ë' with 'e'
  213. sed -i 's/\xc3\xab/e/g' $LNG'_filtered.po'
  214. #replace 'ä' with 'a' (left)
  215. sed -i 's/\xc3\xa4/a/g' $LNG'_filtered.po'
  216. #replace 'é' with 'e'
  217. sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
  218. fi
  219. if [ "$LNG" = "hu" ]; then
  220. #replace 'ë' with 'e'
  221. sed -i 's/\xc3\xab/e/g' $LNG'_filtered.po'
  222. #replace 'ä' with 'a'
  223. sed -i 's/\xc3\xa4/a/g' $LNG'_filtered.po'
  224. #replace 'é' with 'e'
  225. sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
  226. fi
  227. if [ "$LNG" = "lb" ]; then
  228. #replace 'ë' with 'e'
  229. sed -i 's/\xc3\xab/e/g' $LNG'_filtered.po'
  230. #replace 'ä' with 'a'
  231. sed -i 's/\xc3\xa4/a/g' $LNG'_filtered.po'
  232. #replace 'é' with 'e'
  233. sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
  234. fi
  235. if [ "$LNG" = "hr" ]; then
  236. #replace 'ë' with 'e'
  237. sed -i 's/\xc3\xab/e/g' $LNG'_filtered.po'
  238. #replace 'ä' with 'a'
  239. sed -i 's/\xc3\xa4/a/g' $LNG'_filtered.po'
  240. #replace 'é' with 'e'
  241. sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
  242. fi
  243. if [ "$LNG" = "lt" ]; then
  244. #replace 'ë' with 'e'
  245. sed -i 's/\xc3\xab/e/g' $LNG'_filtered.po'
  246. #replace 'ä' with 'a'
  247. sed -i 's/\xc3\xa4/a/g' $LNG'_filtered.po'
  248. #replace 'é' with 'e'
  249. sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
  250. fi
  251. #replace in polish translation
  252. #if [ "$LNG" = "pl" ]; then
  253. #fi
  254. #check for nonasci characters excpet HD44780 ROM A00 'äöüß'
  255. if grep --color='auto' -P -n '[^\x00-\x7F]' $LNG'_filtered.po' >nonascii.txt; then
  256. exit
  257. fi
  258. #join lines with multi-line string constants
  259. cat $LNG'_filtered.po' | sed ':a;N;$!ba;s/\x22\n\x22//g' > $LNG'_new.po'
  260. #Get counter from po files
  261. CNTTXT=$(grep '^# MSG' -c $LNGISO.po)
  262. num=1
  263. echo " selected language=$(tput setaf 2)$LNGISO$(tput sgr 0)" >&2
  264. #generate new dictionary
  265. cat ../../lang_en.txt | sed 's/\\/\\\\/g' | while read -r s; do
  266. /bin/echo -e "$s"
  267. #echo "s = $s ." >&2
  268. if [ "${s:0:1}" = "\"" ]; then
  269. # /bin/echo -e "$s"
  270. s=$(/bin/echo -e "$s")
  271. s2=$(grep -F -A1 -B0 "msgid $s" "$LNG"_new.po | tail -n1 | sed 's/^msgstr //')
  272. if [ -z "$s2" ]; then
  273. echo -ne " processing $num of $CNTTXT\033[0K\r" >&2
  274. echo '"\x00"'
  275. num=$((num+1))
  276. else
  277. echo -ne " processing $num of $CNTTXT\033[0K\r" >&2
  278. echo "$s2"
  279. num=$((num+1))
  280. fi
  281. # echo
  282. fi
  283. done > lang_en_$LNG.txt
  284. echo >&2
  285. echo "$(tput setaf 2)Finished with $LNGISO$(tput sgr 0)" >&2
  286. #replace two double quotes to "\x00"
  287. sed -i 's/""/"\\x00"/g' lang_en_$LNG.txt
  288. #remove CR
  289. sed -i "s/\r//g" lang_en_$LNG.txt
  290. #check new lang
  291. ./../../lang-check.py $LNG --warn-empty
  292. ./../../lang-check.py $LNG --information >$LNG-output.txt
  293. echo >&2
  294. echo "$(tput setaf 2)lang-import.sh finished$(tput sgr 0)">&2