lang-import.sh 9.3 KB

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