lang-import.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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
  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. 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 'é' with 'e'
  68. sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
  69. #replace 'É' with 'E'
  70. sed -i 's/\xc3\x89/E/g' $LNG'_filtered.po'
  71. #replace 'é' with 'e' (left)
  72. sed -i 's/\xc3\xa8/e/g' $LNG'_filtered.po'
  73. #replace 'á' with 'a' (left)
  74. sed -i 's/\xc3\xa0/a/g' $LNG'_filtered.po'
  75. fi
  76. #replace in italian translation
  77. if [ "$LNG" = "it" ]; then
  78. #replace 'é' with 'e' (left)
  79. sed -i 's/\xc3\xa8/e/g' $LNG'_filtered.po'
  80. #replace 'á' with 'a' (left)
  81. sed -i 's/\xc3\xa0/a/g' $LNG'_filtered.po'
  82. #replace 'ó' with 'o' (left)
  83. sed -i 's/\xc3\xb2/o/g' $LNG'_filtered.po'
  84. #replace 'ú' with 'u' (left)
  85. sed -i 's/\xc3\xb9/u/g' $LNG'_filtered.po'
  86. #replace 'é' with 'e'
  87. sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
  88. #replace 'É' with 'E' (left)
  89. sed -i 's/\xc3\x88/E/g' $LNG'_filtered.po'
  90. fi
  91. #replace in polish translation
  92. #if [ "$LNG" = "pl" ]; then
  93. #fi
  94. #check for nonasci characters
  95. if grep --color='auto' -P -n '[^\x00-\x7F]' $LNG'_filtered.po' >nonasci.txt; then
  96. exit
  97. fi
  98. #join lines with multi-line string constants
  99. cat $LNG'_filtered.po' | sed ':a;N;$!ba;s/\x22\n\x22//g' > $LNG'_new.po'
  100. #generate new dictionary
  101. cat ../../lang_en.txt | sed 's/\\/\\\\/g' | while read -r s; do
  102. /bin/echo -e "$s"
  103. if [ "${s:0:1}" = "\"" ]; then
  104. # /bin/echo -e "$s"
  105. s=$(/bin/echo -e "$s")
  106. s2=$(grep -F -A1 -B0 "$s" "$LNG"_new.po | tail -n1 | sed 's/^msgstr //')
  107. if [ -z "$s2" ]; then
  108. echo '"\x00"'
  109. else
  110. echo "$s2"
  111. fi
  112. # echo
  113. fi
  114. done > lang_en_$LNG.txt