[ Index ]
 

Code source de phpMyAdmin 2.10.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/lang/ -> sync_lang.sh (source)

   1  #!/bin/sh
   2  # $Id: sync_lang.sh 9375 2006-08-29 15:33:28Z nijel $
   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-windows-1250
  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-iso-8859-1
 112  japanese-utf-8
 113  korean-utf-8
 114  latvian-windows-1257
 115  lithuanian-windows-1257
 116  malay-iso-8859-1
 117  norwegian-iso-8859-1
 118  persian-windows-1256
 119  polish-iso-8859-2
 120  portuguese-iso-8859-1
 121  romanian-iso-8859-1
 122  russian-windows-1251
 123  serbian_cyrillic-windows-1251
 124  serbian_latin-windows-1250
 125  slovenian-iso-8859-2
 126  slovak-utf-8
 127  spanish-iso-8859-1
 128  swedish-iso-8859-1
 129  tatarish-iso-8859-9
 130  thai-utf-8
 131  turkish-utf-8
 132  ukrainian-windows-1251"
 133  
 134  ##
 135  # which translations should not be translated to utf-8
 136  ##
 137  # List here any translation that should not be converted to utf-8. The name is
 138  # same as above.
 139  #
 140  IGNORE_UTF=""
 141  
 142  ##
 143  # which translations should not be automatically generated
 144  ##
 145  # List here any translation should not be automatically generated from base
 146  # translation for that language (usually for those which are not correctly
 147  # supported by convertor).
 148  #
 149  IGNORE_TRANSLATIONS="
 150  russian-cp-866"
 151  
 152  ##
 153  # end of configuration, you hopefully won't need to edit anything bellow
 154  ##
 155  
 156  TEMPFILE=`mktemp /tmp/pma-sync-lang.XXXXXX`
 157  
 158  cleanup() {
 159      rm -f $TEMPFILE
 160  }
 161  
 162  trap cleanup INT ABRT TERM
 163  
 164  FAILED=""
 165  
 166  echo "-------------------------------------------------------------------"
 167  # go through all file we should process
 168  for base in $BASE_TRANSLATIONS ; do
 169      if [ "$#" -gt 0 ] ; then
 170          if ( echo $base | grep -q "$@" ) ; then
 171              true
 172          else
 173              continue
 174          fi
 175      fi
 176      # grep language from basename
 177      lang=$(echo $base|sed 's%-.*%%')
 178      # which files will we create from current?
 179      create_files=$(ls --color=none -1 $lang*.inc.php|grep -v $base.inc.php)
 180  
 181      for ignore in $IGNORE_TRANSLATIONS ; do
 182          create_files=$(echo "$create_files" | grep -v $ignore)
 183      done
 184  
 185      # charset of source file
 186      src_charset=$(grep '\$charset' $base.inc.php | sed "s%^[^'\"]*['\"]\\([^'\"]*\\)['\"][^'\"]*$%\\1%")
 187      replace_charset=$src_charset
 188      # special case for hebrew
 189      if [ $src_charset = 'iso-8859-8-i' ] ; then
 190          src_charset=iso-8859-8
 191      fi
 192      echo -n "$base [charset $src_charset]"
 193  
 194      # do we already have utf-8 translation?
 195      if [ $src_charset = 'utf-8' ] ; then
 196          is_utf=yes
 197      else
 198          is_utf=no
 199      fi
 200  
 201      # at first update existing translations
 202      for file in $create_files ; do
 203          # charset of destination file
 204  
 205          # grepping from file causes problems when it is empty...
 206          charset=$(grep '\$charset' $file | sed "s%^[^'\"]*['\"]\\([^'\"]*\\)['\"][^'\"]*$%\\1%")
 207          if [ -z "$charset" ] ; then
 208              charset=$(echo $file | sed -e 's/^[^-]*-//' -e 's/\.inc\.php\?$//')
 209          fi
 210  
 211          if [ $charset = 'utf-8' ] ; then
 212              is_utf=yes
 213          fi
 214  
 215          # check whether we need to update translation
 216          if [ ! "$base.inc.php" -nt "$file" -a "$FORCE" -eq 0 -a -s "$file" ] ; then
 217              echo -n " ($file:ok)"
 218              continue
 219          fi
 220  
 221          echo -n " ($file:to $charset:"
 222          if [ $charset = 'utf-8' ] ; then
 223              # if we convert to utf-8, we should add allow_recoding
 224              is_utf=yes
 225              $CONVERTOR $(printf "$CONVERTOR_PARAMS" $src_charset $charset) < $base.inc.php| sed -e "s/$replace_charset/$charset/" -e '/\$charset/a\
 226  $allow_recoding = TRUE;' > $TEMPFILE
 227          elif [ $src_charset = 'utf-8' ] ; then
 228              is_utf=yes
 229              # if we convert from utf-8, we should remove allow_recoding
 230              $CONVERTOR $(printf "$CONVERTOR_PARAMS" $src_charset $charset) < $base.inc.php| grep -v allow_recoding | sed "s/$replace_charset/$charset/" > $TEMPFILE
 231          else
 232              # just convert
 233              $CONVERTOR $(printf "$CONVERTOR_PARAMS" $src_charset $charset) < $base.inc.php| sed "s/$replace_charset/$charset/" > $TEMPFILE
 234          fi
 235          if [ -s $TEMPFILE ] ; then
 236              sed "s/\\\\';[[:space:]]\+$/\\\\\\\\';/" $TEMPFILE > $file
 237              echo -n 'done)'
 238          else
 239              FAILED="$FAILED $file"
 240              echo -n 'FAILED)'
 241          fi
 242      done
 243  
 244      # now check whether we found utf-8 translation
 245      if [ $is_utf = no ] ; then
 246          if ( echo $IGNORE_UTF | grep -q $base ) ; then
 247              # utf-8 should not be created
 248              true
 249          else
 250              # we should create utf-8 translation
 251              charset=utf-8
 252              file=$lang-$charset.inc.php
 253              echo -n " [$file:$charset:"
 254              $CONVERTOR $(printf "$CONVERTOR_PARAMS" $src_charset $charset) < $base.inc.php| sed -e "s/$replace_charset/$charset/" -e '/\$charset/a\
 255  $allow_recoding = TRUE;' > $TEMPFILE
 256              if [ -s $TEMPFILE ] ; then
 257                  cat $TEMPFILE > $file
 258                  echo -n 'done)'
 259              else
 260                  FAILED="$FAILED $file"
 261                  echo -n 'FAILED)'
 262              fi
 263          fi
 264      fi
 265      echo
 266  done
 267  
 268  echo "-------------------------------------------------------------------"
 269  
 270  if [ -z "$FAILED" ] ; then
 271      echo "Everything seems to went okay"
 272  else
 273      echo "!!!SOME CONVERSION FAILED!!!"
 274      echo "Following file were NOT updated:"
 275      echo
 276      echo "$FAILED"
 277      echo
 278      echo "!!!SOME CONVERSION FAILED!!!"
 279  fi
 280  
 281  cleanup


Généré le : Mon Nov 26 15:18:20 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics