lang-import.sh 7.6 KB

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