home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / phpMyAdmin / lang / sync_lang.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2008-06-23  |  7.7 KB  |  283 lines

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