public function registerTranslations($path, $load_all = false, $language = null)
{
$path = sanitise_filepath($path);
// Make a note of this path just incase we need to register this language later
if (!isset($GLOBALS['_ELGG']->language_paths)) {
$GLOBALS['_ELGG']->language_paths = array();
}
$GLOBALS['_ELGG']->language_paths[$path] = true;
_elgg_services()->logger->info("Translations loaded from: {$path}");
if ($language) {
$load_language_files = array("{$language}.php");
$load_all = false;
} else {
// Get the current language based on site defaults and user preference
$current_language = $this->getCurrentLanguage();
$load_language_files = array('en.php', "{$current_language}.php");
$load_language_files = array_unique($load_language_files);
}
$handle = opendir($path);
if (!$handle) {
_elgg_services()->logger->error("Could not open language path: {$path}");
return false;
}
$return = true;
while (false !== ($language_file = readdir($handle))) {
// ignore bad files
if (substr($language_file, 0, 1) == '.' || substr($language_file, -4) !== '.php') {
continue;
}
if (in_array($language_file, $load_language_files) || $load_all) {
$result = (include_once $path . $language_file);
if ($result === false) {
$return = false;
continue;
} elseif (is_array($result)) {
$this->addTranslation(basename($language_file, '.php'), $result);
}
}
}
return $return;
}