lang-import.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #!/bin/sh
  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 https://en.wikipedia.org/wiki/German_orthography
  40. if [ "$LNG" = "de" ]; then
  41. #replace 'ä' with 'ae'
  42. sed -i 's/\xc3\xa4/ae/g' $LNG'_filtered.po'
  43. #replace 'Ä' with 'Ae'
  44. sed -i 's/\xc3\x84/Ae/g' $LNG'_filtered.po'
  45. #replace 'ü' with 'ue'
  46. sed -i 's/\xc3\xbc/ue/g' $LNG'_filtered.po'
  47. #replace 'Ü' with 'Ue'
  48. sed -i 's/\xc3\x9c/Ue/g' $LNG'_filtered.po'
  49. #replace 'ö' with 'oe'
  50. sed -i 's/\xc3\xb6/oe/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 https://en.wikipedia.org/wiki/French_orthography
  74. if [ "$LNG" = "fr" ]; then
  75. #replace 'á' with 'a' (right)
  76. sed -i 's/\xc3\xa1/a/g' $LNG'_filtered.po'
  77. #replace 'Á' with 'A' (right)
  78. sed -i 's/\xc3\x81/A/g' $LNG'_filtered.po'
  79. #replace 'à' with 'a' (left)
  80. sed -i 's/\xc3\xa0/a/g' $LNG'_filtered.po'
  81. #replace 'À' with 'A' (left)
  82. sed -i 's/\xc3\x80/A/g' $LNG'_filtered.po'
  83. #replace 'é' with 'e' (right)
  84. sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
  85. #replace 'É' with 'E' (right)
  86. sed -i 's/\xc3\x89/E/g' $LNG'_filtered.po'
  87. #replace 'è' with 'e' (left)
  88. sed -i 's/\xc3\xa8/e/g' $LNG'_filtered.po'
  89. #replace 'È' with 'E' (left)
  90. sed -i 's/\xc3\x88/E/g' $LNG'_filtered.po'
  91. fi
  92. #replace in italian translation
  93. if [ "$LNG" = "it" ]; then
  94. #replace 'é' with 'e' (left)
  95. sed -i 's/\xc3\xa8/e/g' $LNG'_filtered.po'
  96. #replace 'á' with 'a' (left)
  97. sed -i 's/\xc3\xa0/a/g' $LNG'_filtered.po'
  98. #replace 'ó' with 'o' (left)
  99. sed -i 's/\xc3\xb2/o/g' $LNG'_filtered.po'
  100. #replace 'ú' with 'u' (left)
  101. sed -i 's/\xc3\xb9/u/g' $LNG'_filtered.po'
  102. #replace 'é' with 'e'
  103. sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
  104. #replace 'É' with 'E' (left)
  105. sed -i 's/\xc3\x88/E/g' $LNG'_filtered.po'
  106. fi
  107. #replace in polish translation
  108. #if [ "$LNG" = "pl" ]; then
  109. #fi
  110. #check for nonasci characters
  111. if grep --color='auto' -P -n '[^\x00-\x7F]' $LNG'_filtered.po' >nonasci.txt; then
  112. exit
  113. fi
  114. #join lines with multi-line string constants
  115. cat $LNG'_filtered.po' | sed ':a;N;$!ba;s/\x22\n\x22//g' > $LNG'_new.po'
  116. #generate new dictionary
  117. cat ../../lang_en.txt | sed 's/\\/\\\\/g' | while read -r s; do
  118. /bin/echo -e "$s"
  119. if [ "${s:0:1}" = "\"" ]; then
  120. # /bin/echo -e "$s"
  121. s=$(/bin/echo -e "$s")
  122. s2=$(grep -F -A1 -B0 "$s" "$LNG"_new.po | tail -n1 | sed 's/^msgstr //')
  123. if [ -z "$s2" ]; then
  124. echo '"\x00"'
  125. else
  126. echo "$s2"
  127. fi
  128. # echo
  129. fi
  130. done > lang_en_$LNG.txt