lang-import.sh 13 KB

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