lang-import.sh 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. #!/bin/bash
  2. #
  3. # Version 1.0.1 Build 25
  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. # 11 Feb. 2022, 3d-gussner, Change to python3
  37. #############################################################################
  38. # Config:
  39. if [ -z "$CONFIG_OK" ]; then eval "$(cat config.sh)"; fi
  40. if [ -z "$CONFIG_OK" ] | [ $CONFIG_OK -eq 0 ]; then echo "$(tput setaf 1)Config NG!$(tput sgr 0)" >&2; exit 1; fi
  41. echo "$(tput setaf 2)lang-import.sh started$(tput sgr 0)" >&2
  42. LNG=$1
  43. # if no arguments, 'all' is selected (all po and also pot will be generated)
  44. if [ -z "$LNG" ]; then LNG=all; fi
  45. if [[ ! -z "$COMMUNITY_LANGUAGES" && "$LNG" = "all" ]]; then
  46. LANGUAGES+=" $COMMUNITY_LANGUAGES"
  47. else
  48. LANGUAGES="$LNG"
  49. fi
  50. echo "$(tput setaf 2)lang-import languages:$LANGUAGES$(tput sgr 0)" >&2
  51. # if 'all' is selected, script will generate all po files and also pot file
  52. if [ "$LNG" = "all" ]; then
  53. for lang in $LANGUAGES; do
  54. ./lang-import.sh $lang
  55. done
  56. exit 0
  57. fi
  58. # language code (iso639-1) is equal to LNG
  59. LNGISO=$LNG
  60. # exception for 'cz' (code='cs')
  61. if [ "$LNG" = "cz" ]; then LNGISO=cs; fi
  62. # cd to input folder
  63. cd po/new
  64. # check if input file exists
  65. if ! [ -e $LNGISO.po ]; then
  66. echo "$(tput setaf 1)Input file $LNGISO.po not found!$(tput sgr 0)" >&2
  67. exit -1
  68. fi
  69. #convert '\\e' sequencies to 'x1b' and '\\' to '\'
  70. cat $LNGISO.po | sed 's/\\e/\\x1b/g;s/\\\\/\\/g' > $LNG'_filtered.po'
  71. #replace '\n' with ' ' (single space)
  72. sed -i 's/ \\n/ /g;s/\\n/ /g' $LNG'_filtered.po'
  73. #replace in czech translation
  74. if [ "$LNG" = "cz" ]; then
  75. #replace 'Á' with 'A'
  76. sed -i 's/\xc3\x81/A/g' $LNG'_filtered.po'
  77. #replace 'á' with 'a'
  78. sed -i 's/\xc3\xa1/a/g' $LNG'_filtered.po'
  79. #replace 'Č' with 'C'
  80. sed -i 's/\xc4\x8c/C/g' $LNG'_filtered.po'
  81. #replace 'č' with 'c'
  82. sed -i 's/\xc4\x8d/c/g' $LNG'_filtered.po'
  83. #replace 'Ď' with 'D'
  84. sed -i 's/\xc4\x8e/D/g' $LNG'_filtered.po'
  85. #replace 'ď' with 'd'
  86. sed -i 's/\xc4\x8f/d/g' $LNG'_filtered.po'
  87. #replace 'É' with 'E'
  88. sed -i 's/\xc3\x89/E/g' $LNG'_filtered.po'
  89. #replace 'é' with 'e'
  90. sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
  91. #replace 'Ě' with 'E'
  92. sed -i 's/\xc4\x9a/E/g' $LNG'_filtered.po'
  93. #replace 'ě' with 'e'
  94. sed -i 's/\xc4\x9b/e/g' $LNG'_filtered.po'
  95. #replace 'Í' with 'I'
  96. sed -i 's/\xc3\x8d/I/g' $LNG'_filtered.po'
  97. #replace 'í' with 'i'
  98. sed -i 's/\xc3\xad/i/g' $LNG'_filtered.po'
  99. #replace 'Ň' with 'N'
  100. sed -i 's/\xc5\x87/N/g' $LNG'_filtered.po'
  101. #replace 'ň' with 'n'
  102. sed -i 's/\xc5\x88/n/g' $LNG'_filtered.po'
  103. #replace 'Ó' with 'O'
  104. sed -i 's/\xc3\x93/O/g' $LNG'_filtered.po'
  105. #replace 'ó' with 'o'
  106. sed -i 's/\xc3\xb3/o/g' $LNG'_filtered.po'
  107. #replace 'Ř' with 'R'
  108. sed -i 's/\xc5\x98/R/g' $LNG'_filtered.po'
  109. #replace 'ř' with 'r'
  110. sed -i 's/\xc5\x99/r/g' $LNG'_filtered.po'
  111. #replace 'Š' with 'S'
  112. sed -i 's/\xc5\xa0/S/g' $LNG'_filtered.po'
  113. #replace 'š' with 's'
  114. sed -i 's/\xc5\xa1/s/g' $LNG'_filtered.po'
  115. #replace 'Ť' with 'T'
  116. sed -i 's/\xc5\xa4/T/g' $LNG'_filtered.po'
  117. #replace 'ť' with 't'
  118. sed -i 's/\xc5\xa5/t/g' $LNG'_filtered.po'
  119. #replace 'Ú' with 'U'
  120. sed -i 's/\xc3\x9a/U/g' $LNG'_filtered.po'
  121. #replace 'ú' with 'u'
  122. sed -i 's/\xc3\xba/u/g' $LNG'_filtered.po'
  123. #replace 'Ů' with 'U'
  124. sed -i 's/\xc5\xae/U/g' $LNG'_filtered.po'
  125. #replace 'ů' with 'u'
  126. sed -i 's/\xc5\xaf/u/g' $LNG'_filtered.po'
  127. #replace 'Ý' with 'Y'
  128. sed -i 's/\xc3\x9d/Y/g' $LNG'_filtered.po'
  129. #replace 'ý' with 'y'
  130. sed -i 's/\xc3\xbd/y/g' $LNG'_filtered.po'
  131. #replace 'Ž' with 'Z'
  132. sed -i 's/\xc5\xbd/Z/g' $LNG'_filtered.po'
  133. #replace 'ž' with 'z'
  134. sed -i 's/\xc5\xbe/z/g' $LNG'_filtered.po'
  135. fi
  136. #replace in german translation https://en.wikipedia.org/wiki/German_orthography
  137. if [ "$LNG" = "de" ]; then
  138. #replace UTF-8 'äöüß' to HD44780 A00 'äöüß'
  139. #replace 'ä' with 'A00 ROM ä'
  140. sed -i 's/\xc3\xa4/\\xe1/g' $LNG'_filtered.po'
  141. #replace 'Ä' with 'A00 ROM ä'
  142. sed -i 's/\xc3\x84/\\xe1/g' $LNG'_filtered.po'
  143. #replace 'ü' with 'A00 ROM ü'
  144. sed -i 's/\xc3\xbc/\\xf5/g' $LNG'_filtered.po'
  145. #replace 'Ü' with 'A00 ROM ü'
  146. sed -i 's/\xc3\x9c/\\xf5/g' $LNG'_filtered.po'
  147. #replace 'ö' with 'A00 ROM ö'
  148. sed -i 's/\xc3\xb6/\\xef/g' $LNG'_filtered.po'
  149. #replace 'Ö' with 'A00 ROM ö'
  150. sed -i 's/\xc3\x96/\\xef/g' $LNG'_filtered.po'
  151. #replace 'ß' with 'A00 ROM ß'
  152. sed -i 's/\xc3\x9f/\\xe2/g' $LNG'_filtered.po'
  153. fi
  154. #replace in spain translation
  155. if [ "$LNG" = "es" ]; then
  156. #replace 'á' with 'a'
  157. sed -i 's/\xc3\xa1/a/g' $LNG'_filtered.po'
  158. #replace '¿' with '?'
  159. sed -i 's/\xc2\xbf/?/g' $LNG'_filtered.po'
  160. #replace 'ó' with 'o'
  161. sed -i 's/\xc3\xb3/o/g' $LNG'_filtered.po'
  162. #replace 'é' with 'e'
  163. sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
  164. #replace 'í' with 'i'
  165. sed -i 's/\xc3\xad/i/g' $LNG'_filtered.po'
  166. #replace '!' with '!'
  167. sed -i 's/\xc2\xa1/!/g' $LNG'_filtered.po'
  168. #replace 'n~' with 'n'
  169. sed -i 's/\xc3\xb1/n/g' $LNG'_filtered.po'
  170. fi
  171. #replace in french translation https://en.wikipedia.org/wiki/French_orthography
  172. if [ "$LNG" = "fr" ]; then
  173. #replace 'á' with 'a' (right)
  174. sed -i 's/\xc3\xa1/a/g' $LNG'_filtered.po'
  175. #replace 'Á' with 'A' (right)
  176. sed -i 's/\xc3\x81/A/g' $LNG'_filtered.po'
  177. #replace 'à' with 'a' (left)
  178. sed -i 's/\xc3\xa0/a/g' $LNG'_filtered.po'
  179. #replace 'À' with 'A' (left)
  180. sed -i 's/\xc3\x80/A/g' $LNG'_filtered.po'
  181. #replace 'é' with 'e' (right)
  182. sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
  183. #replace 'É' with 'E' (right)
  184. sed -i 's/\xc3\x89/E/g' $LNG'_filtered.po'
  185. #replace 'è' with 'e' (left)
  186. sed -i 's/\xc3\xa8/e/g' $LNG'_filtered.po'
  187. #replace 'È' with 'E' (left)
  188. sed -i 's/\xc3\x88/E/g' $LNG'_filtered.po'
  189. fi
  190. #replace in italian translation
  191. if [ "$LNG" = "it" ]; then
  192. #replace 'é' with 'e' (left)
  193. sed -i 's/\xc3\xa8/e/g' $LNG'_filtered.po'
  194. #replace 'á' with 'a' (left)
  195. sed -i 's/\xc3\xa0/a/g' $LNG'_filtered.po'
  196. #replace 'ó' with 'o' (left)
  197. sed -i 's/\xc3\xb2/o/g' $LNG'_filtered.po'
  198. #replace 'ú' with 'u' (left)
  199. sed -i 's/\xc3\xb9/u/g' $LNG'_filtered.po'
  200. #replace 'é' with 'e'
  201. sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
  202. #replace 'É' with 'E' (left)
  203. sed -i 's/\xc3\x88/E/g' $LNG'_filtered.po'
  204. fi
  205. #replace in dutch translation according to https://nl.wikipedia.org/wiki/Accenttekens_in_de_Nederlandse_spelling
  206. if [ "$LNG" = "nl" ]; then
  207. #replace 'ë' with 'e'
  208. sed -i 's/\xc3\xab/e/g' $LNG'_filtered.po'
  209. #replace 'ï' with 'i'
  210. sed -i 's/\xc3\xaf/i/g' $LNG'_filtered.po'
  211. #replace 'é' with 'e'
  212. sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
  213. #replace 'è' with 'e' (left)
  214. sed -i 's/\xc3\xa8/e/g' $LNG'_filtered.po'
  215. #replace 'ö' with 'o' (left)
  216. sed -i 's/\xc3\xb6/o/g' $LNG'_filtered.po'
  217. #replace 'ê' with 'e' (left)
  218. sed -i 's/\xc3\xaa/e/g' $LNG'_filtered.po'
  219. #replace 'ü' with 'u' (left)
  220. sed -i 's/\xc3\xbc/u/g' $LNG'_filtered.po'
  221. #replace 'ç' with 'c' (left)
  222. sed -i 's/\xc3\xa7/c/g' $LNG'_filtered.po'
  223. #replace 'á' with 'a' (left)
  224. sed -i 's/\xc3\xa1/a/g' $LNG'_filtered.po'
  225. #replace 'à' with 'a' (left)
  226. sed -i 's/\xc3\xa0/a/g' $LNG'_filtered.po'
  227. #replace 'ä' with 'a' (left)
  228. sed -i 's/\xc3\xa4/a/g' $LNG'_filtered.po'
  229. #replace 'û' with 'u' (left)
  230. sed -i 's/\xc3\xbc/u/g' $LNG'_filtered.po'
  231. #replace 'î' with 'i' (left)
  232. sed -i 's/\xc3\xae/i/g' $LNG'_filtered.po'
  233. #replace 'í' with 'i' (left)
  234. sed -i 's/\xc3\xad/i/g' $LNG'_filtered.po'
  235. #replace 'ô' with 'o' (left)
  236. sed -i 's/\xc3\xb4/o/g' $LNG'_filtered.po'
  237. #replace 'ú' with 'u' (left)
  238. sed -i 's/\xc3\xba/u/g' $LNG'_filtered.po'
  239. #replace 'ñ' with 'n' (left)
  240. sed -i 's/\xc3\xb1/n/g' $LNG'_filtered.po'
  241. #replace 'â' with 'a' (left)
  242. sed -i 's/\xc3\xa2/a/g' $LNG'_filtered.po'
  243. #replace 'Å' with 'A' (left)
  244. sed -i 's/\xc3\x85/A/g' $LNG'_filtered.po'
  245. fi
  246. if [ "$LNG" = "sv" ]; then
  247. #repace 'Å' with 'Aa'
  248. sed -i 's/\xc3\x85/Aa/g' $LNG'_filtered.po'
  249. #repace 'å' with 'aa'
  250. sed -i 's/\xc3\xA5/aa/g' $LNG'_filtered.po'
  251. fi
  252. if [ "$LNG" = "da" ]; then
  253. #repace 'Å' with 'Aa'
  254. sed -i 's/\xc3\x85/Aa/g' $LNG'_filtered.po'
  255. #repace 'å' with 'aa'
  256. sed -i 's/\xc3\xA5/aa/g' $LNG'_filtered.po'
  257. fi
  258. if [ "$LNG" = "sl" ]; then
  259. #replace 'ë' with 'e'
  260. sed -i 's/\xc3\xab/e/g' $LNG'_filtered.po'
  261. #replace 'ä' with 'a' (left)
  262. sed -i 's/\xc3\xa4/a/g' $LNG'_filtered.po'
  263. #replace 'é' with 'e'
  264. sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
  265. fi
  266. if [ "$LNG" = "hu" ]; then # See https://www.fileformat.info/info/charset/UTF-8/list.htm
  267. #replace 'Á' with 'A'(acute)
  268. sed -i 's/\xc3\x81/A/g' $LNG'_filtered.po'
  269. #replace 'á' with 'a'
  270. sed -i 's/\xc3\xa1/a/g' $LNG'_filtered.po'
  271. #replace 'É' with 'E' (acute)
  272. sed -i 's/\xc3\x89/E/g' $LNG'_filtered.po'
  273. #replace 'é' with 'e'
  274. sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
  275. #replace 'Í' with 'I' (acute)
  276. sed -i 's/\xc3\x8d/I/g' $LNG'_filtered.po'
  277. #replace 'i̇́' with 'i'
  278. sed -i 's/\xc3\xad/i/g' $LNG'_filtered.po'
  279. #replace 'Ó' with 'O' (acute)
  280. sed -i 's/\xc3\x93/O/g' $LNG'_filtered.po'
  281. #replace 'ó' with 'o'
  282. sed -i 's/\xc3\xb3/o/g' $LNG'_filtered.po'
  283. #replace 'Ö' with 'O' (diaresis)
  284. sed -i 's/\xc3\x96/O/g' $LNG'_filtered.po'
  285. #replace 'ö' with 'o'
  286. sed -i 's/\xc3\xb6/o/g' $LNG'_filtered.po'
  287. #replace 'Ő' with 'O' (double acute)
  288. sed -i 's/\xc5\x90/O/g' $LNG'_filtered.po'
  289. #replace 'ő' with 'o'
  290. sed -i 's/\xc5\x91/o/g' $LNG'_filtered.po'
  291. #replace 'Ú' with 'U' (acute)
  292. sed -i 's/\xc3\x9a/U/g' $LNG'_filtered.po'
  293. #replace 'ú' with 'u'
  294. sed -i 's/\xc3\xba/u/g' $LNG'_filtered.po'
  295. #replace 'Ü' with 'U' (diaersis)
  296. sed -i 's/\xc3\x9c/U/g' $LNG'_filtered.po'
  297. #replace 'ü' with 'u'
  298. sed -i 's/\xc3\xbc/u/g' $LNG'_filtered.po'
  299. #replace 'Ű' with 'U' (double acute)
  300. sed -i 's/\xc5\xb0/U/g' $LNG'_filtered.po'
  301. #replace 'ű' with 'u'
  302. sed -i 's/\xc5\xb1/u/g' $LNG'_filtered.po'
  303. fi
  304. if [ "$LNG" = "lb" ]; then
  305. #replace 'ë' with 'e'
  306. sed -i 's/\xc3\xab/e/g' $LNG'_filtered.po'
  307. #replace 'ä' with 'a'
  308. sed -i 's/\xc3\xa4/a/g' $LNG'_filtered.po'
  309. #replace 'é' with 'e'
  310. sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
  311. fi
  312. if [ "$LNG" = "hr" ]; then
  313. #replace 'ë' with 'e'
  314. sed -i 's/\xc3\xab/e/g' $LNG'_filtered.po'
  315. #replace 'ä' with 'a'
  316. sed -i 's/\xc3\xa4/a/g' $LNG'_filtered.po'
  317. #replace 'é' with 'e'
  318. sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
  319. fi
  320. if [ "$LNG" = "lt" ]; then
  321. #replace 'ë' with 'e'
  322. sed -i 's/\xc3\xab/e/g' $LNG'_filtered.po'
  323. #replace 'ä' with 'a'
  324. sed -i 's/\xc3\xa4/a/g' $LNG'_filtered.po'
  325. #replace 'é' with 'e'
  326. sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
  327. fi
  328. #replace in polish translation
  329. #if [ "$LNG" = "pl" ]; then
  330. #fi
  331. #replace UTF-8 'μ' to HD44780 A00 'μ'
  332. #replace 'μ' with 'A00 ROM μ'
  333. sed -i 's/\xce\xbc/\\xe4/g' $LNG'_filtered.po'
  334. #check for nonasci characters except HD44780 ROM A00 'äöüß'
  335. if grep --color='auto' -P -n '[^\x00-\x7F]' $LNG'_filtered.po' >nonascii.txt; then
  336. exit
  337. fi
  338. #join lines with multi-line string constants
  339. cat $LNG'_filtered.po' | sed ':a;N;$!ba;s/\x22\n\x22//g' > $LNG'_new.po'
  340. #Get counter from po files
  341. CNTTXT=$(grep '^# MSG' -c $LNGISO.po)
  342. num=1
  343. echo " selected language=$(tput setaf 2)$LNGISO$(tput sgr 0)" >&2
  344. #generate new dictionary
  345. cat ../../lang_en.txt | sed 's/\\/\\\\/g' | while read -r s; do
  346. /bin/echo -e "$s"
  347. #echo "s = $s ." >&2
  348. if [ "${s:0:1}" = "\"" ]; then
  349. # /bin/echo -e "$s"
  350. s=$(/bin/echo -e "$s")
  351. s2=$(grep -F -A1 -B0 "msgid $s" "$LNG"_new.po | tail -n1 | sed 's/^msgstr //')
  352. if [ -z "$s2" ]; then
  353. echo -ne " processing $num of $CNTTXT\033[0K\r" >&2
  354. echo '"\x00"'
  355. num=$((num+1))
  356. else
  357. echo -ne " processing $num of $CNTTXT\033[0K\r" >&2
  358. echo "$s2"
  359. num=$((num+1))
  360. fi
  361. # echo
  362. fi
  363. done > lang_en_$LNG.txt
  364. echo >&2
  365. echo "$(tput setaf 2)Finished with $LNGISO$(tput sgr 0)" >&2
  366. #replace two double quotes to "\x00"
  367. sed -i 's/""/"\\x00"/g' lang_en_$LNG.txt
  368. #remove CR
  369. sed -i "s/\r//g" lang_en_$LNG.txt
  370. #check new lang
  371. python3 ../../lang-check.py $LNG --warn-empty
  372. python3 ../../lang-check.py $LNG --information >$LNG-output.txt
  373. echo >&2
  374. echo "$(tput setaf 2)lang-import.sh finished$(tput sgr 0)">&2