lang-import.sh 5.9 KB

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