aboutsummaryrefslogtreecommitdiffstats
path: root/include/language.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/language.php')
-rw-r--r--include/language.php64
1 files changed, 35 insertions, 29 deletions
diff --git a/include/language.php b/include/language.php
index 853b6ebee..2e7ad5ff1 100644
--- a/include/language.php
+++ b/include/language.php
@@ -15,35 +15,33 @@
*
*/
-
-if(! function_exists('get_browser_language')) {
function get_browser_language() {
$langs = array();
if (x($_SERVER,'HTTP_ACCEPT_LANGUAGE')) {
- // break up string into pieces (languages and q factors)
- preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i',
+ // break up string into pieces (languages and q factors)
+ preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i',
$_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse);
- if (count($lang_parse[1])) {
- // create a list like "en" => 0.8
- $langs = array_combine($lang_parse[1], $lang_parse[4]);
-
- // set default to 1 for any without q factor
- foreach ($langs as $lang => $val) {
- if ($val === '') $langs[$lang] = 1;
- }
-
- // sort list based on value
- arsort($langs, SORT_NUMERIC);
- }
+ if (count($lang_parse[1])) {
+ // create a list like "en" => 0.8
+ $langs = array_combine($lang_parse[1], $lang_parse[4]);
+
+ // set default to 1 for any without q factor
+ foreach ($langs as $lang => $val) {
+ if ($val === '') $langs[$lang] = 1;
+ }
+
+ // sort list based on value
+ arsort($langs, SORT_NUMERIC);
+ }
}
else
$langs['en'] = 1;
return $langs;
-}}
+}
function get_best_language() {
@@ -62,7 +60,7 @@ function get_best_language() {
if(isset($preferred))
return $preferred;
- $a = get_app();
+ $a = get_app();
return ((isset($a->config['system']['language'])) ? $a->config['system']['language'] : 'en');
}
@@ -101,15 +99,25 @@ function pop_lang() {
// load string translation table for alternate language
-if(! function_exists('load_translation_table')) {
-function load_translation_table($lang) {
+function load_translation_table($lang, $install = false) {
global $a;
+ $a->strings = array();
if(file_exists("view/$lang/strings.php")) {
include("view/$lang/strings.php");
}
- else
- $a->strings = array();
+
+ if(! $install) {
+ $plugins = q("SELECT name FROM addon WHERE installed=1;");
+ if ($plugins!==false) {
+ foreach($plugins as $p) {
+ $name = $p['name'];
+ if(file_exists("addon/$name/lang/$lang/strings.php")) {
+ include("addon/$name/lang/$lang/strings.php");
+ }
+ }
+ }
+ }
// Allow individual strings to be over-ridden on this site
// Either for the default language or for all languages
@@ -118,11 +126,10 @@ function load_translation_table($lang) {
include("view/local-$lang/strings.php");
}
-}}
+}
// translate string if translation exists
-if(! function_exists('t')) {
function t($s) {
global $a;
@@ -132,9 +139,9 @@ function t($s) {
return is_array($t)?$t[0]:$t;
}
return $s;
-}}
+}
+
-if(! function_exists('tt')){
function tt($singular, $plural, $count){
$a = get_app();
@@ -152,15 +159,14 @@ function tt($singular, $plural, $count){
} else {
return $singular;
}
-}}
+}
// provide a fallback which will not collide with
// a function defined in any language file
-if(! function_exists('string_plural_select_default')) {
function string_plural_select_default($n) {
return ($n != 1);
-}}
+}