aboutsummaryrefslogtreecommitdiff
path: root/engine
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
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')
-rw-r--r--engine/lib/languages.php84
-rw-r--r--engine/lib/sessions.php12
-rw-r--r--engine/start.php10
3 files changed, 74 insertions, 32 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();
diff --git a/engine/lib/sessions.php b/engine/lib/sessions.php
index 468bc2233..411fe4b73 100644
--- a/engine/lib/sessions.php
+++ b/engine/lib/sessions.php
@@ -98,8 +98,11 @@
function get_loggedin_user()
{
global $SESSION;
-
- return $SESSION['user'];
+
+ if (isset($SESSION))
+ return $SESSION['user'];
+
+ return false;
}
/**
@@ -461,7 +464,10 @@
{
session_destroy();
return false;
- }
+ }
+
+ // Since we have loaded a new user, this user may have different language preferences
+ register_translations(dirname(dirname(dirname(__FILE__))) . "/languages/");
return true;
diff --git a/engine/start.php b/engine/start.php
index d1484cafd..067e6c9b0 100644
--- a/engine/start.php
+++ b/engine/start.php
@@ -43,6 +43,11 @@
exit;
}
+ if (!@include_once(dirname(__FILE__) . "/lib/sessions.php")) {
+ echo ("Error in installation: Elgg could not load the Sessions library");
+ exit;
+ }
+
if (!@include_once(dirname(__FILE__) . "/lib/languages.php")) { // Languages library
echo "Error in installation: could not load the languages library.";
exit;
@@ -63,10 +68,7 @@
exit;
}
- if (!@include_once(dirname(__FILE__) . "/lib/sessions.php")) {
- echo ("Error in installation: Elgg could not load the Sessions library");
- exit;
- }
+
// Use fallback view until sanitised
$oldview = get_input('view');