10 * Get the language setting directly from system variables, bypassing get_config()
11 * as database may not yet be configured.
13 * If possible, we use the value from the browser.
18 if(! function_exists('get_language')) {
19 function get_language() {
21 if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
22 // break up string into pieces (languages and q factors)
23 preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i',
24 $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse);
26 if (count($lang_parse[1])) {
27 // create a list like "en" => 0.8
28 $langs = array_combine($lang_parse[1], $lang_parse[4]);
30 // set default to 1 for any without q factor
31 foreach ($langs as $lang => $val) {
32 if ($val === '') $langs[$lang] = 1;
35 // sort list based on value
36 arsort($langs, SORT_NUMERIC);
40 if(isset($langs) && count($langs)) {
41 foreach ($langs as $lang => $v) {
42 if(file_exists("view/$lang") && is_dir("view/$lang")) {
53 return ((isset($a->config['system']['language'])) ? $a->config['system']['language'] : 'en');
57 function push_lang($language) {
62 if($language === $lang)
65 if(isset($a->strings) && count($a->strings)) {
66 $a->stringsave = $a->strings;
68 $a->strings = array();
69 load_translation_table($language);
76 if($lang === $a->langsave)
79 if(isset($a->stringsave))
80 $a->strings = $a->stringsave;
82 $a->strings = array();
88 // load string translation table for alternate language
90 if(! function_exists('load_translation_table')) {
91 function load_translation_table($lang) {
94 if(file_exists("view/$lang/strings.php")) {
95 include("view/$lang/strings.php");
98 $a->strings = array();
101 // translate string if translation exists
103 if(! function_exists('t')) {
108 if(x($a->strings,$s)) {
109 $t = $a->strings[$s];
110 return is_array($t)?$t[0]:$t;
115 if(! function_exists('tt')){
116 function tt($singular, $plural, $count){
120 if(x($a->strings,$singular)) {
121 $t = $a->strings[$singular];
122 $f = 'string_plural_select_' . str_replace('-','_',$lang);
123 if(! function_exists($f))
124 $f = 'string_plural_select_default';
126 return is_array($t)?$t[$k]:$t;
136 // provide a fallback which will not collide with
137 // a function defined in any language file
139 if(! function_exists('string_plural_select_default')) {
140 function string_plural_select_default($n) {