lang-import.sh 5.2 KB

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