lang-import.sh 7.7 KB

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