lang-import.sh 5.9 KB

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