lang-import.sh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 polish translation
  119. #if [ "$LNG" = "pl" ]; then
  120. #fi
  121. #check for nonasci characters
  122. if grep --color='auto' -P -n '[^\x00-\x7F]' $LNG'_filtered.po' >nonasci.txt; then
  123. exit
  124. fi
  125. #join lines with multi-line string constants
  126. cat $LNG'_filtered.po' | sed ':a;N;$!ba;s/\x22\n\x22//g' > $LNG'_new.po'
  127. #generate new dictionary
  128. cat ../../lang_en.txt | sed 's/\\/\\\\/g' | while read -r s; do
  129. /bin/echo -e "$s"
  130. if [ "${s:0:1}" = "\"" ]; then
  131. # /bin/echo -e "$s"
  132. s=$(/bin/echo -e "$s")
  133. s2=$(grep -F -A1 -B0 "$s" "$LNG"_new.po | tail -n1 | sed 's/^msgstr //')
  134. if [ -z "$s2" ]; then
  135. echo '"\x00"'
  136. else
  137. echo "$s2"
  138. fi
  139. # echo
  140. fi
  141. done > lang_en_$LNG.txt