2007-07-05 05:41:18 +00:00
< ? php
2009-07-11 19:45:57 +00:00
// not used in a single language version
2009-06-21 23:20:32 +00:00
2008-07-10 15:39:24 +00:00
$langs = array (
2011-02-08 18:58:33 +00:00
'en' => 'English' , // Jakub Vrána - http://www.vrana.cz
'cs' => 'Čeština' , // Jakub Vrána - http://www.vrana.cz
2010-02-17 16:47:50 +00:00
'sk' => 'Slovenčina' , // Ivan Suchy - http://www.ivansuchy.com, Juraj Krivda - http://www.jstudio.cz
2008-01-08 14:01:29 +00:00
'nl' => 'Nederlands' , // Maarten Balliauw - http://blog.maartenballiauw.be
2008-05-07 07:49:59 +00:00
'es' => 'Español' , // Klemens Häckel - http://clickdimension.wordpress.com
2008-05-15 14:38:15 +00:00
'de' => 'Deutsch' , // Klemens Häckel - http://clickdimension.wordpress.com
2010-08-06 09:02:19 +00:00
'fr' => 'Français' , // Francis Gagné, Aurélien Royer
2009-04-10 12:01:43 +00:00
'it' => 'Italiano' , // Alessandro Fiorotto, Paolo Asperti
2008-09-01 09:35:51 +00:00
'et' => 'Eesti' , // Priit Kallas
2010-10-07 14:03:22 +00:00
'hu' => 'Magyar' , // Borsos Szilárd (Borsosfi) - http://www.borsosfi.hu, info@borsosfi.hu
2011-03-08 13:13:09 +00:00
'pl' => 'Polski' , // Radosław Kowalewski - http://srsbiz.pl/
2010-10-15 14:39:18 +00:00
'ca' => 'Català' , // Joan Llosas
2011-10-22 14:37:10 +00:00
'pt' => 'Português' , // Gian Live - gian@live.com, Davi Alexandre davi@davialexandre.com.br
2011-02-03 20:56:30 +00:00
'sl' => 'Slovenski' , // Matej Ferlan - www.itdinamik.com, matej.ferlan@itdinamik.com
2011-04-17 02:49:50 +00:00
'lt' => 'Lietuvių' , // Paulius Leščinskas - http://www.lescinskas.lt
2011-02-08 18:57:06 +00:00
'tr' => 'Türkçe' , // Bilgehan Korkmaz - turktron.com
2011-06-07 12:18:17 +00:00
'ro' => 'Limba Română' , // .nick .messing - dot.nick.dot.messing@gmail.com
2012-06-19 17:21:40 +00:00
'id' => 'Bahasa Indonesia' , // Ivan Lanin - http://ivan.lanin.org
2009-07-02 15:21:16 +00:00
'ru' => 'Русский язык' , // Maksim Izmaylov
2012-03-22 05:36:07 +00:00
'uk' => 'Українська' , // Valerii Kryzhov
2012-09-01 15:47:29 +00:00
'sr' => 'Српски' , // Nikola Radovanović - cobisimo@gmail.com
2009-08-21 10:38:49 +00:00
'zh' => '简体中文' , // Mr. Lodar
'zh-tw' => '繁體中文' , // http://tzangms.com
2010-04-25 07:25:55 +00:00
'ja' => '日本語' , // Hitoshi Ozawa - http://sourceforge.jp/projects/oss-ja-jpn/releases/
2010-09-27 09:28:02 +00:00
'ta' => 'தமிழ்' , // G. Sampath Kumar, Chennai, India, sampathkumar11@gmail.com
2012-06-29 19:13:03 +00:00
'bn' => 'বাংলা' , // Dipak Kumar - dipak.ndc@gmail.com
2010-11-10 16:30:34 +00:00
'ar' => 'العربية' , // Y.M Amine - Algeria - nbr7@live.fr
2011-08-23 12:02:14 +00:00
'fa' => 'فارسی' , // mojtaba barghbani - Iran - mbarghbani@gmail.com
2013-02-01 06:44:47 +00:00
'ko' => '한국어' , // dalli - skcha67@gmail.com
2007-07-17 14:04:29 +00:00
);
2010-12-30 12:53:39 +00:00
/** Get current language
* @ return string
*/
function get_lang () {
global $LANG ;
return $LANG ;
}
/** Translate string
* @ param string
* @ param int
* @ return string
*/
2007-07-17 14:04:29 +00:00
function lang ( $idf , $number = null ) {
global $LANG , $translations ;
2012-09-03 22:59:05 +00:00
$translation = ( $translations [ $idf ] ? $translations [ $idf ] : $idf );
2011-07-11 15:33:55 +00:00
if ( is_array ( $translation )) {
2011-05-06 15:11:51 +00:00
$pos = ( $number == 1 ? 0
2011-05-06 21:08:11 +00:00
: ( $LANG == 'cs' || $LANG == 'sk' ? ( $number && $number < 5 ? 1 : 2 ) // different forms for 1, 2-4, other
: ( $LANG == 'fr' ? ( ! $number ? 0 : 1 ) // different forms for 0-1, other
2011-05-06 15:11:51 +00:00
: ( $LANG == 'pl' ? ( $number % 10 > 1 && $number % 10 < 5 && $number / 10 % 10 != 1 ? 1 : 2 ) // different forms for 1, 2-4, other
: ( $LANG == 'sl' ? ( $number % 100 == 1 ? 0 : ( $number % 100 == 2 ? 1 : ( $number % 100 == 3 || $number % 100 == 4 ? 2 : 3 ))) // different forms for 1, 2, 3-4, other
: ( $LANG == 'lt' ? ( $number % 10 == 1 && $number % 100 != 11 ? 0 : ( $number % 10 > 1 && $number / 10 % 10 != 1 ? 1 : 2 )) // different forms for 1, 12-19, other
2012-08-24 09:52:10 +00:00
: ( $LANG == 'ru' || $LANG == 'sr' || $LANG == 'uk' ? ( $number % 10 == 1 && $number % 100 != 11 ? 0 : ( $number % 10 > 1 && $number % 10 < 5 && $number / 10 % 10 != 1 ? 1 : 2 )) // different forms for 1, 2-4, other
2011-05-06 15:11:51 +00:00
: 1
2012-03-27 06:24:58 +00:00
))))))); // http://www.gnu.org/software/gettext/manual/html_node/Plural-forms.html
2009-06-01 16:05:51 +00:00
$translation = $translation [ $pos ];
2007-07-05 10:46:44 +00:00
}
2007-07-25 10:19:00 +00:00
$args = func_get_args ();
array_shift ( $args );
2012-06-05 00:44:04 +00:00
$format = str_replace ( " %d " , " %s " , $translation );
if ( $format != $translation ) {
$args [ 0 ] = number_format ( $number , 0 , " . " , lang ( ',' ));
}
return vsprintf ( $format , $args );
2007-07-05 10:46:44 +00:00
}
function switch_lang () {
2012-09-22 13:22:44 +00:00
global $LANG , $langs ;
2012-09-07 06:32:42 +00:00
echo " <form action='' method='post'> \n <div id='lang'> " ;
2012-09-07 06:07:31 +00:00
echo lang ( 'Language' ) . " : " . html_select ( " lang " , $langs , $LANG , " this.form.submit(); " );
2009-10-28 13:42:51 +00:00
echo " <input type='submit' value=' " . lang ( 'Use' ) . " ' class='hidden'> \n " ;
2012-09-22 13:22:44 +00:00
echo " <input type='hidden' name='token' value=' $_SESSION[token] '> \n " ; // $token may be empty in auth.inc.php
2009-10-02 13:21:34 +00:00
echo " </div> \n </form> \n " ;
2007-07-05 10:46:44 +00:00
}
2012-09-07 06:32:42 +00:00
if ( isset ( $_POST [ " lang " ]) && $_SESSION [ " token " ] == $_POST [ " token " ]) { // $token and $error not yet available
cookie ( " adminer_lang " , $_POST [ " lang " ]);
$_SESSION [ " lang " ] = $_POST [ " lang " ]; // cookies may be disabled
2012-09-16 13:08:00 +00:00
$_SESSION [ " translations " ] = array (); // used in compiled version
2012-09-07 06:32:42 +00:00
redirect ( remove_from_uri ());
2007-07-05 05:41:18 +00:00
}
2007-07-09 15:28:37 +00:00
2008-07-10 15:39:24 +00:00
$LANG = " en " ;
2009-06-21 23:31:12 +00:00
if ( isset ( $langs [ $_COOKIE [ " adminer_lang " ]])) {
2009-09-09 20:49:30 +00:00
cookie ( " adminer_lang " , $_COOKIE [ " adminer_lang " ]);
2009-06-21 23:31:12 +00:00
$LANG = $_COOKIE [ " adminer_lang " ];
2007-08-04 19:36:22 +00:00
} elseif ( isset ( $langs [ $_SESSION [ " lang " ]])) {
2007-07-27 11:43:01 +00:00
$LANG = $_SESSION [ " lang " ];
2007-07-09 15:28:37 +00:00
} else {
2007-07-25 11:19:40 +00:00
$accept_language = array ();
2009-08-05 11:30:16 +00:00
preg_match_all ( '~([-a-z]+)(;q=([0-9.]+))?~' , str_replace ( " _ " , " - " , strtolower ( $_SERVER [ " HTTP_ACCEPT_LANGUAGE " ])), $matches , PREG_SET_ORDER );
2007-07-25 11:19:40 +00:00
foreach ( $matches as $match ) {
2009-08-05 11:30:16 +00:00
$accept_language [ $match [ 1 ]] = ( isset ( $match [ 3 ]) ? $match [ 3 ] : 1 );
2007-07-25 11:19:40 +00:00
}
arsort ( $accept_language );
2009-01-29 13:23:59 +00:00
foreach ( $accept_language as $key => $q ) {
if ( isset ( $langs [ $key ])) {
$LANG = $key ;
2007-07-25 11:19:40 +00:00
break ;
}
2009-01-29 13:23:59 +00:00
$key = preg_replace ( '~-.*~' , '' , $key );
if ( ! isset ( $accept_language [ $key ]) && isset ( $langs [ $key ])) {
$LANG = $key ;
2007-07-25 11:19:40 +00:00
break ;
2007-07-09 15:28:37 +00:00
}
}
}