lang-import.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 in czech translation
  21. if [ "$LNG" = "cz" ]; then
  22. #replace 'ž' with 'z'
  23. sed -i 's/\xc5\xbe/z/g' $LNG'_filtered.po'
  24. #replace 'ì' with 'e'
  25. sed -i 's/\xc4\x9b/e/g' $LNG'_filtered.po'
  26. #replace 'í' with 'i'
  27. sed -i 's/\xc3\xad/i/g' $LNG'_filtered.po'
  28. #replace 'ø' with 'r'
  29. sed -i 's/\xc5\x99/r/g' $LNG'_filtered.po'
  30. #replace 'è' with 'c'
  31. sed -i 's/\xc4\x8d/c/g' $LNG'_filtered.po'
  32. #replace 'á' with 'a'
  33. sed -i 's/\xc3\xa1/a/g' $LNG'_filtered.po'
  34. #replace 'é' with 'e'
  35. sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
  36. fi
  37. #replace in german translation
  38. if [ "$LNG" = "de" ]; then
  39. #replace '\n' with ' ' (single space)
  40. sed -i 's/ \\n/ /g;s/\\n/ /g' $LNG'_filtered.po'
  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. fi
  48. #replace in spain translation
  49. if [ "$LNG" = "es" ]; then
  50. #replace 'á' with 'a'
  51. sed -i 's/\xc3\xa1/a/g' $LNG'_filtered.po'
  52. #replace '?' with '?'
  53. sed -i 's/\xc2\xbf/?/g' $LNG'_filtered.po'
  54. #replace 'ó' with 'o'
  55. sed -i 's/\xc3\xb3/o/g' $LNG'_filtered.po'
  56. #replace 'é' with 'e'
  57. sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
  58. #replace 'í' with 'i'
  59. sed -i 's/\xc3\xad/i/g' $LNG'_filtered.po'
  60. #replace '!' with '!'
  61. sed -i 's/\xc2\xa1/!/g' $LNG'_filtered.po'
  62. #replace 'n~' with 'n'
  63. sed -i 's/\xc3\xb1/n/g' $LNG'_filtered.po'
  64. fi
  65. #replace in french translation
  66. if [ "$LNG" = "fr" ]; then
  67. #replace '\n' with ' ' (single space)
  68. sed -i 's/ \\n/ /g;s/\\n/ /g' $LNG'_filtered.po'
  69. #replace 'é' with 'e'
  70. sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
  71. #replace 'É' with 'E'
  72. sed -i 's/\xc3\x89/E/g' $LNG'_filtered.po'
  73. #replace 'é' with 'e' (left)
  74. sed -i 's/\xc3\xa8/e/g' $LNG'_filtered.po'
  75. #replace 'á' with 'a' (left)
  76. sed -i 's/\xc3\xa0/a/g' $LNG'_filtered.po'
  77. fi
  78. #replace in italian translation
  79. if [ "$LNG" = "it" ]; then
  80. #replace 'é' with 'e' (left)
  81. sed -i 's/\xc3\xa8/e/g' $LNG'_filtered.po'
  82. #replace 'á' with 'a' (left)
  83. sed -i 's/\xc3\xa0/a/g' $LNG'_filtered.po'
  84. #replace 'ó' with 'o' (left)
  85. sed -i 's/\xc3\xb2/o/g' $LNG'_filtered.po'
  86. #replace 'ú' with 'u' (left)
  87. sed -i 's/\xc3\xb9/u/g' $LNG'_filtered.po'
  88. #replace 'é' with 'e'
  89. sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
  90. #replace 'É' with 'E' (left)
  91. sed -i 's/\xc3\x88/E/g' $LNG'_filtered.po'
  92. fi
  93. #replace in polish translation
  94. #if [ "$LNG" = "pl" ]; then
  95. #fi
  96. #check for nonasci characters
  97. if grep --color='auto' -P -n '[^\x00-\x7F]' $LNG'_filtered.po' >nonasci.txt; then
  98. exit
  99. fi
  100. #join lines with multi-line string constants
  101. cat $LNG'_filtered.po' | sed ':a;N;$!ba;s/\x22\n\x22//g' > $LNG'_new.po'
  102. #generate new dictionary
  103. cat ../../lang_en.txt | sed 's/\\/\\\\/g' | while read -r s; do
  104. /bin/echo -e "$s"
  105. if [ "${s:0:1}" = "\"" ]; then
  106. # /bin/echo -e "$s"
  107. s=$(/bin/echo -e "$s")
  108. s2=$(grep -F -A1 -B0 "$s" "$LNG"_new.po | tail -n1 | sed 's/^msgstr //')
  109. if [ -z "$s2" ]; then
  110. echo '"\x00"'
  111. else
  112. echo "$s2"
  113. fi
  114. # echo
  115. fi
  116. done > lang_en_$LNG.txt