diff options
author | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-12-29 00:07:21 +0000 |
---|---|---|
committer | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-12-29 00:07:21 +0000 |
commit | 6a7e32601d151dd38af5baee53298523221bbdfa (patch) | |
tree | 92b2c7a494a4d216c6a8169e097afb623e72e85e | |
parent | 320655648e2a04928d17a0be3e9f7f05f7623b69 (diff) | |
download | elgg-6a7e32601d151dd38af5baee53298523221bbdfa.tar.gz elgg-6a7e32601d151dd38af5baee53298523221bbdfa.tar.bz2 |
Cleaned up register_translations().
git-svn-id: http://code.elgg.org/elgg/trunk@7733 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r-- | engine/lib/languages.php | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/engine/lib/languages.php b/engine/lib/languages.php index d34a89707..3065495f0 100644 --- a/engine/lib/languages.php +++ b/engine/lib/languages.php @@ -145,6 +145,8 @@ function elgg_echo($message_key, $args = array(), $language = "") { function register_translations($path, $load_all = false) { global $CONFIG; + $path = sanitise_filepath($path); + // Make a note of this path just incase we need to register this language later if (!isset($CONFIG->language_paths)) { $CONFIG->language_paths = array(); @@ -155,18 +157,36 @@ function register_translations($path, $load_all = false) { $current_language = get_current_language(); elgg_log("Translations loaded from: $path"); - if ($handle = opendir($path)) { - while ($language = readdir($handle)) { - if ( - ((in_array($language, array('en.php', $current_language . '.php'))) ) || - (($load_all) && (strpos($language, '.php') !== false)) - ) { - include_once($path . $language); + // only load these files unless $load_all is true. + $load_language_files = array( + 'en.php', + "$current_language.php" + ); + + $load_language_files = array_unique($load_language_files); + + $handle = opendir($path); + if (!$handle) { + elgg_log("Could not open language path: $path", 'ERROR'); + return false; + } + + $return = true; + while (false !== ($language = readdir($handle))) { + // ignore bad files + if (substr($language, 0, 1) == '.' || substr($language, -4) !== '.php') { + continue; + } + + if (in_array($language, $load_language_files) || $load_all) { + if (!include_once($path . $language)) { + $return = false; + continue; } } - } else { - elgg_log("Missing translation path $path", 'ERROR'); } + + return $return; } /** |