]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Cleaned up register_translations().
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Wed, 29 Dec 2010 00:07:21 +0000 (00:07 +0000)
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Wed, 29 Dec 2010 00:07:21 +0000 (00:07 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@7733 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/lib/languages.php

index d34a89707ae9c0ed11c5a63a33db00eab6a8c9ee..3065495f034609ae3c8adf151cd0a491c9ee5cc2 100644 (file)
@@ -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;
 }
 
 /**