home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / sync_lang.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2004-06-06  |  7.5 KB  |  278 lines

  1. #!/bin/sh
  2. # $Id: sync_lang.sh,v 2.3.2.1 2004/06/07 10:24:45 rabus Exp $
  3. ##
  4. # Shell script that synchronises all translations in phpMyAdmin
  5. ##
  6. # Any parameters (except --iconv/--recode) will be passed to grep to filter
  7. # processed translation, for example: './sync_lang.sh czech' will process only
  8. # czech translation, './sync_lang.sh -e czech -e english' will process czech
  9. # and english translations.
  10. ##
  11. # Written by Michal Cihar <nijel at users.sourceforge.net>
  12. ##
  13. # Changes:
  14. # 2003-11-18
  15. #   * switch php3 -> php
  16. # 2003-04-14
  17. #   * convert only files that are needed to convert (checks mtime), --force to
  18. #     avoid this checking
  19. #   * get charset from filename when reading from file failed
  20. #   * report failed translations at the end
  21. # 2002-09-18
  22. #   * now accepts parameters --iconv/--recode for specifying which convertor
  23. #     to use
  24. # 2002-08-13
  25. #   * support for synchronisation only for selected language(s)
  26. # 2002-07-18
  27. #   * can exclude some languages from conversion
  28. # 2002-07-17
  29. #   * support for multiple convertors (recode added)
  30. ##
  31.  
  32. ##
  33. # convertor setup
  34. ##
  35. # CONVERTOR_PARAMS is used for printf and it also receives two params: source
  36. # and target charset
  37. #
  38.  
  39. case "$1" in
  40.     --iconv)
  41.         echo Using iconv on user request
  42.         CONVERTOR=iconv
  43.         # the space on following is REQUIRED
  44.         CONVERTOR_PARAMS=" -f %s -t %s"
  45.         shift
  46.         ;;
  47.     --recode)
  48.         echo Using recode on user request
  49.         CONVERTOR=recode
  50.         CONVERTOR_PARAMS=" -f %s..%s"
  51.         shift
  52.         ;;
  53.     *)
  54.         echo Using recode as default, force with --iconv/--recode
  55.         CONVERTOR=recode
  56.         CONVERTOR_PARAMS=" -f %s..%s"
  57.         ;;
  58. esac
  59.  
  60. if [ "$1" = "--force" ] ; then
  61.     FORCE=1
  62.     shift
  63. else
  64.     FORCE=0
  65. fi
  66.  
  67.  
  68. ##
  69. # names of translations to process
  70. ##
  71. # Here should be listed all translations for which conversion should be done.
  72. # The name is filename without inc.php.
  73. #
  74. BASE_TRANSLATIONS=`cat <<EOT
  75. afrikaans-iso-8859-1
  76. albanian-iso-8859-1
  77. arabic-windows-1256
  78. azerbaijani-iso-8859-9
  79. basque-iso-8859-1
  80. bosnian-windows-1250
  81. brazilian_portuguese-iso-8859-1
  82. bulgarian-windows-1251
  83. catalan-iso-8859-1
  84. chinese_big5-utf-8
  85. chinese_gb
  86. croatian-iso-8859-2
  87. czech-utf-8
  88. danish-iso-8859-1
  89. dutch-iso-8859-1
  90. english-iso-8859-1
  91. estonian-iso-8859-1
  92. finnish-iso-8859-1
  93. french-iso-8859-1
  94. galician-iso-8859-1
  95. german-iso-8859-1
  96. greek-iso-8859-7
  97. hebrew-iso-8859-8-i
  98. hungarian-iso-8859-2
  99. indonesian-iso-8859-1
  100. italian-iso-8859-1
  101. japanese-euc
  102. korean-ks_c_5601-1987
  103. latvian-windows-1257
  104. lithuanian-windows-1257
  105. malay-iso-8859-1
  106. norwegian-iso-8859-1
  107. persian-windows-1256
  108. polish-iso-8859-2
  109. portuguese-iso-8859-1
  110. romanian-iso-8859-1
  111. russian-windows-1251
  112. serbian_cyrillic-windows-1251
  113. serbian_latin-windows-1250
  114. slovenian-iso-8859-2
  115. slovak-iso-8859-2
  116. spanish-iso-8859-1
  117. swedish-iso-8859-1
  118. thai-tis-620
  119. turkish-iso-8859-9
  120. ukrainian-windows-1251
  121. EOT`
  122.  
  123. ##
  124. # which translations should not be translated to utf-8
  125. ##
  126. # List here any translation that should not be converted to utf-8. The name is
  127. # same as above.
  128. #
  129. IGNORE_UTF=`cat <<EOT
  130. hebrew-iso-8859-8-i
  131. korean-ks_c_5601-1987
  132. EOT`
  133.  
  134. ##
  135. # which translations should not be automatically generated
  136. ##
  137. # List here any translation should not be automatically generated from base
  138. # translation for that language (usually for those which are not correctly
  139. # supported by convertor).
  140. #
  141. IGNORE_TRANSLATIONS=`cat <<EOT
  142. japanese-sjis
  143. russian-dos-866
  144. EOT`
  145.  
  146. ##
  147. # end of configuration, you hopefully won't need to edit anything bellow
  148. ##
  149.  
  150. TEMPFILE=`mktemp /tmp/pma-sync-lang.XXXXXX`
  151.  
  152. cleanup() {
  153.     rm -f $TEMPFILE
  154. }
  155.  
  156. trap cleanup INT ABRT TERM
  157.  
  158. FAILED=""
  159.  
  160. echo "-------------------------------------------------------------------"
  161. # go through all file we should process
  162. for base in $BASE_TRANSLATIONS ; do
  163.     if [ "$#" -gt 0 ] ; then
  164.         if ( echo $base | grep -q "$@" ) ; then
  165.             true
  166.         else
  167.             continue
  168.         fi
  169.     fi
  170.     # grep language from basename
  171.     lang=$(echo $base|sed 's%-.*%%')
  172.     # which files will we create from current?
  173.     create_files=$(ls --color=none -1 $lang*.inc.php|grep -v $base.inc.php)
  174.  
  175.     for ignore in $IGNORE_TRANSLATIONS ; do
  176.         create_files=$(echo "$create_files" | grep -v $ignore)
  177.     done
  178.  
  179.     # charset of source file
  180.     src_charset=$(grep '\$charset' $base.inc.php | sed "s%^[^'\"]*['\"]\\([^'\"]*\\)['\"][^'\"]*$%\\1%")
  181.     echo "$base [charset $src_charset]"
  182.  
  183.     is_utf=no
  184.  
  185.     # at first update existing translations
  186.     for file in $create_files ; do
  187.         # charset of destination file
  188.  
  189.         # grepping from file causes problems when it is empty...
  190.         charset=$(grep '\$charset' $file | sed "s%^[^'\"]*['\"]\\([^'\"]*\\)['\"][^'\"]*$%\\1%")
  191.         if [ -z "$charset" ] ; then
  192.             charset=$(echo $file | sed -e 's/^[^-]*-//' -e 's/\.inc\.php\?$//')
  193.         fi
  194.  
  195.         # check whether we need to update translation
  196.         if [ ! "$base.inc.php" -nt "$file" -a "$FORCE" -eq 0 -a -s "$file" ] ; then
  197.             if [ $charset = 'utf-8' ] ; then
  198.                 is_utf=yes
  199.             fi
  200.             echo " $file is not needed to update"
  201.             continue
  202.         fi
  203.  
  204.         echo -n " to $charset..."
  205.         if [ $charset = 'utf-8' ] ; then
  206.             # if we convert to utf-8, we should add allow_recoding
  207.             is_utf=yes
  208.             $CONVERTOR $(printf "$CONVERTOR_PARAMS" $src_charset $charset) < $base.inc.php| sed -e "s/$src_charset/$charset/" -e '/\$charset/a\
  209. $allow_recoding = TRUE;' > $TEMPFILE
  210.             if [ -s $TEMPFILE ] ; then
  211.                 cat $TEMPFILE > $file
  212.                 echo done
  213.             else
  214.                 FAILED="$FAILED $file"
  215.                 echo FAILED
  216.             fi
  217.         elif [ $src_charset = 'utf-8' ] ; then
  218.             is_utf=yes
  219.             # if we convert from utf-8, we should remove allow_recoding
  220.             $CONVERTOR $(printf "$CONVERTOR_PARAMS" $src_charset $charset) < $base.inc.php| grep -v allow_recoding | sed "s/$src_charset/$charset/" > $TEMPFILE
  221.             if [ -s $TEMPFILE ] ; then
  222.                 cat $TEMPFILE > $file
  223.                 echo done
  224.             else
  225.                 FAILED="$FAILED $file"
  226.                 echo FAILED
  227.             fi
  228.         else
  229.             # just convert
  230.             $CONVERTOR $(printf "$CONVERTOR_PARAMS" $src_charset $charset) < $base.inc.php| sed "s/$src_charset/$charset/" > $TEMPFILE
  231.             if [ -s $TEMPFILE ] ; then
  232.                 cat $TEMPFILE > $file
  233.                 echo done
  234.             else
  235.                 FAILED="$FAILED $file"
  236.                 echo FAILED
  237.             fi
  238.         fi
  239.     done
  240.  
  241.     # now check whether we found utf-8 translation
  242.     if [ $is_utf = no ] ; then
  243.         if ( echo $IGNORE_UTF | grep -q $base ) ; then
  244.             # utf-8 should not be created
  245.             true
  246.         else
  247.             # we should create utf-8 translation
  248.             echo -n " creating utf-8 translation ... "
  249.             charset=utf-8
  250.             file=$lang-$charset.inc.php
  251.             $CONVERTOR $(printf "$CONVERTOR_PARAMS" $src_charset $charset) < $base.inc.php| sed -e "s/$src_charset/$charset/" -e '/\$charset/a\
  252. $allow_recoding = TRUE;' > $TEMPFILE
  253.             if [ -s $TEMPFILE ] ; then
  254.                 cat $TEMPFILE > $file
  255.                 echo done
  256.             else
  257.                 FAILED="$FAILED $file"
  258.                 echo FAILED
  259.             fi
  260.         fi
  261.     fi
  262.     echo "$lang processing finished."
  263.     echo "-------------------------------------------------------------------"
  264. done
  265.  
  266. if [ -z "$FAILED" ] ; then
  267.     echo "Everything seems to went okay"
  268. else
  269.     echo "!!!SOME CONVERSION FAILED!!!"
  270.     echo "Following file were NOT updated:"
  271.     echo
  272.     echo "$FAILED"
  273.     echo
  274.     echo "!!!SOME CONVERSION FAILED!!!"
  275. fi
  276.  
  277. cleanup
  278.