aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/languages.php
diff options
context:
space:
mode:
authormarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-02-16 13:52:47 +0000
committermarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-02-16 13:52:47 +0000
commitebe86f345e11852251fd48956e1704297950416f (patch)
tree3b10b69c8d07aed47d549d409d5a5b585f3b1481 /engine/lib/languages.php
parent254d24bef4f9bc84da8496f4014e65763bdcffd9 (diff)
downloadelgg-ebe86f345e11852251fd48956e1704297950416f.tar.gz
elgg-ebe86f345e11852251fd48956e1704297950416f.tar.bz2
Closes #429: Language loading now no longer loads all possible translations - only english + user's preferred language/site preference
git-svn-id: https://code.elgg.org/elgg/trunk@2762 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/languages.php')
-rw-r--r--engine/lib/languages.php84
1 files changed, 59 insertions, 25 deletions
diff --git a/engine/lib/languages.php b/engine/lib/languages.php
index 3b05f6753..d40953ee0 100644
--- a/engine/lib/languages.php
+++ b/engine/lib/languages.php
@@ -30,7 +30,7 @@
global $CONFIG;
if (!isset($CONFIG->translations))
$CONFIG->translations = array();
-
+
$country_code = strtolower($country_code);
$country_code = trim($country_code);
if (is_array($language_array) && sizeof($language_array) > 0 && $country_code != "") {
@@ -40,6 +40,7 @@
} else {
$CONFIG->translations[$country_code] = array_merge($CONFIG->translations[$country_code],$language_array);
}
+
return true;
}
@@ -55,37 +56,30 @@
{
global $CONFIG;
- $user = get_loggedin_user();
-
- if ((isset($user)) && ($user->language))
- $language = $user->language;
-
- if ((empty($language)) && (isset($CONFIG->language)))
- $language = $CONFIG->language;
+ $language = get_language();
- if (empty($language))
+ if (!$language)
$language = 'en';
return $language;
}
/**
- * Gets the current language in use by the system or user
+ * Gets the current language in use by the system or user.
+ *
+ * [Marcus Povey 20090216: Not sure why this func is necessary.]
*
* @return string The language code (eg "en")
*/
function get_language() {
global $CONFIG;
- static $lang;
-
- if (isset($lang)) return $lang;
-
- $user = get_loggedin_user();
+
+ $user = get_loggedin_user();
- if ((empty($language)) && (isset($user)) && ($user->language))
+ if ((empty($language)) && ($user) && ($user->language))
$language = $user->language;
-
+
if ((empty($language)) && (isset($CONFIG->language)))
$language = $CONFIG->language;
@@ -124,21 +118,52 @@
* When given a full path, finds translation files and loads them
*
* @param string $path Full path
+ * @param bool $load_all If true all languages are loaded, if false only the current language + en are loaded
*/
- function register_translations($path) {
+ function register_translations($path, $load_all = false) {
global $CONFIG;
+ // Make a note of this path just incase we need to register this language later
+ if(!isset($CONFIG->language_paths)) $CONFIG->language_paths = array();
+ $CONFIG->language_paths[] = $path;
+
+ // Get the current language based on site defaults and user preference
+ $current_language = get_current_language();
+
if (isset($CONFIG->debug) && $CONFIG->debug == true) error_log("Translations loaded from : $path");
-
+
if ($handle = opendir($path)) {
while ($language = readdir($handle)) {
- if (!in_array($language,array('.','..','.svn','CVS', '.DS_Store', 'Thumbs.db',)) && !is_dir($path . $language)) {
- @include($path . $language);
- }
+
+ if (
+ ((in_array($language, array('en.php', $current_language . '.php'))) && (!is_dir($path . $language))) ||
+ (($load_all) && (strpos($language, '.php')!==false) && (!is_dir($path . $language)))
+ )
+ @include_once($path . $language);
+
}
}
else
error_log("Missing translation path $path");
+
+ }
+
+ /**
+ * Reload all translations from all registered paths.
+ *
+ * This is only called by functions which need to know all possible translations, namely the
+ * statistic gathering ones.
+ *
+ * TODO: Better on demand loading based on language_paths array
+ *
+ * @return bool
+ */
+ function reload_all_translations()
+ {
+ global $CONFIG;
+
+ foreach ($CONFIG->language_paths as $path)
+ register_translations($path, true);
}
/**
@@ -146,7 +171,10 @@
*/
function get_installed_translations()
{
- global $CONFIG;
+ global $CONFIG;
+
+ // Ensure that all possible translations are loaded
+ reload_all_translations();
$installed = array();
@@ -167,7 +195,10 @@
*/
function get_language_completeness($language)
{
- global $CONFIG;
+ global $CONFIG;
+
+ // Ensure that all possible translations are loaded
+ reload_all_translations();
$language = sanitise_string($language);
@@ -187,7 +218,10 @@
*/
function get_missing_language_keys($language)
{
- global $CONFIG;
+ global $CONFIG;
+
+ // Ensure that all possible translations are loaded
+ reload_all_translations();
$missing = array();