Index: i18n.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/i18n/i18n.inc,v retrieving revision 1.4 diff -u -r1.4 i18n.inc --- i18n.inc 31 Jul 2004 20:02:50 -0000 1.4 +++ i18n.inc 14 Aug 2004 19:25:32 -0000 @@ -34,32 +34,20 @@ } } +// Get the $langeages array // Get language from path, but only if it is in the $languages array function i18n_get_lang_prefix($path){ - global $languages; + + $result = db_query('SELECT locale, name FROM {locales_meta} WHERE enabled = 1 ORDER BY isdefault DESC'); + + while ($row = db_fetch_object($result)) { + $languages[$row->locale] = $row->name; + } + $split=split("/",$path); $maybelang=$split[0]; if($languages[$maybelang]){ return $maybelang; } } - -// This is just an experiment to keep tables in sync. -// Needs some patching to core. -function i18n_db_sync($query){ - global $languages,$i18n_lang; - global $i18n_db_sync,$db_prefix_i18n_sync; - if (preg_match("/^(insert into|delete from)[ ]+\{([\w]+)\}.*/i",$query,$matches) && $db_prefix_i18n_sync[$matches[2]]){ - debug("SYNC:".$sql); - $i18n_db_sync=false; - foreach($languages as $lang => $desc){ - i18n_set_db_prefix($lang); - $result[$lang]=_db_query(db_prefix($args)); - } - i18n_set_db_prefix($locale); - $i18n_db_sync=true; - } - elseif(preg_match("/^REPLACE INTO \{sequences\}.*/i",$sql)){ - } -} ?> \ No newline at end of file Index: i18n.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/i18n/i18n.module,v retrieving revision 1.6 diff -u -r1.6 i18n.module --- i18n.module 31 Jul 2004 20:02:50 -0000 1.6 +++ i18n.module 14 Aug 2004 19:25:34 -0000 @@ -73,7 +73,9 @@ } function i18n_menu() { - global $languages,$i18n_lang; + global $i18n_lang; + + $languages = array_pop(locale_supported_languages()); if (arg(0) == 'node' && is_numeric(arg(1)) && variable_get("i18n_content",0)) { foreach ($languages as $lang => $desc) { @@ -136,7 +138,9 @@ if(!function_exists("i18n_get_lang_prefix")){ function i18n_get_lang_prefix($path){ - global $languages; + + $languages = array_pop(locale_supported_languages()); + $split=split("/",$path); $maybelang=$split[0]; if($languages[$maybelang]){ @@ -198,7 +202,9 @@ function i18n_get_default_lang(){ global $user; - global $languages; + + $languages = array_pop(locale_supported_languages()); + if(!$lang=$user->language){ if(variable_get('i18n_browser',0) && $lang=i18n_get_browser_lang()){ i18n_set_default_lang($lang); @@ -212,8 +218,10 @@ // Set language as default rearranging $languages array function i18n_set_default_lang($lang){ - global $languages; global $i18n_lang; + + $languages = array_pop(locale_supported_languages()); + $i18n_lang=$lang; if(variable_get("i18n_interface",0)){ $deflang=key($languages); @@ -241,7 +249,9 @@ // Get language from browser settings, but only if it is in the $languages array function i18n_get_browser_lang(){ - global $languages; + + $languages = array_pop(locale_supported_languages()); + $accept=explode(",",array_shift( explode(";",$_SERVER["HTTP_ACCEPT_LANGUAGE"]))); foreach($accept as $lang){ $lang=substr($lang,0,2); @@ -265,9 +275,10 @@ */ function theme_i18n_links($flags=1,$names=1,$delim1=" ",$delim2=" "){ - global $languages; global $i18n_lang; + $languages = array_pop(locale_supported_languages()); + foreach($languages as $lang => $langname){ $name= $names ? t($langname): ""; // Should be localized?? $flag= $flags ? _i18n_flag($lang) :""; @@ -405,7 +416,10 @@ } function i18n_foreach_lang($callback){ - global $languages,$i18n_lang; + global $i18n_lang; + + $languages = array_pop(locale_supported_languages()); + $args=func_get_args(); foreach ($languages as $lang => $desc) { if ($lang != $i18n_lang) { @@ -419,6 +433,7 @@ function i18n_get_table($table,$lang){ global $i18n_db_prefix; + if($db_prefix_i18n[$table]) { return str_replace('**',$lang,$db_prefix_i18n[$table]).$table; } elseif(is_array($db_prefix_i18n)){ @@ -430,5 +445,24 @@ } } - +// This is just an experiment to keep tables in sync. +// Needs some patching to core. +function i18n_db_sync($query){ + global $i18n_lang, $i18n_db_sync,$db_prefix_i18n_sync; + + $languages = array_pop(locale_supported_languages()); + + if (preg_match("/^(insert into|delete from)[ ]+\{([\w]+)\}.*/i",$query,$matches) && $db_prefix_i18n_sync[$matches[2]]){ + debug("SYNC:".$sql); + $i18n_db_sync=false; + foreach($languages as $lang => $desc){ + i18n_set_db_prefix($lang); + $result[$lang]=_db_query(db_prefix($args)); + } + i18n_set_db_prefix($locale); + $i18n_db_sync=true; + } + elseif(preg_match("/^REPLACE INTO \{sequences\}.*/i",$sql)){ + } +} ?> \ No newline at end of file