diff options
Diffstat (limited to 'engine/lib/languages.php')
-rw-r--r-- | engine/lib/languages.php | 312 |
1 files changed, 156 insertions, 156 deletions
diff --git a/engine/lib/languages.php b/engine/lib/languages.php index bca0466ea..dd97d0927 100644 --- a/engine/lib/languages.php +++ b/engine/lib/languages.php @@ -1,51 +1,51 @@ -<?php
-
- /**
- * Elgg language module
- * Functions to manage language and translations.
- *
- * @package Elgg
- * @subpackage Core
+<?php - * @author Curverider Ltd
+ /** + * Elgg language module + * Functions to manage language and translations. + * + * @package Elgg + * @subpackage Core + + * @author Curverider Ltd + + * @link http://elgg.org/ + */ + + /** + * Add a translation. + * + * Translations are arrays in the Zend Translation array format, eg: + * + * $english = array('message1' => 'message1', 'message2' => 'message2'); + * $german = array('message1' => 'Nachricht1','message2' => 'Nachricht2'); + * + * @param string $country_code Standard country code (eg 'en', 'nl', 'es') + * @param array $language_array Formatted array of strings + * @return true|false Depending on success + */ - * @link http://elgg.org/
- */
-
- /**
- * Add a translation.
- *
- * Translations are arrays in the Zend Translation array format, eg:
- *
- * $english = array('message1' => 'message1', 'message2' => 'message2');
- * $german = array('message1' => 'Nachricht1','message2' => 'Nachricht2');
- *
- * @param string $country_code Standard country code (eg 'en', 'nl', 'es')
- * @param array $language_array Formatted array of strings
- * @return true|false Depending on success
- */
-
- function add_translation($country_code, $language_array) {
-
- 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 != "") {
-
- if (!isset($CONFIG->translations[$country_code])) {
- $CONFIG->translations[$country_code] = $language_array;
- } else {
- $CONFIG->translations[$country_code] = $language_array + $CONFIG->translations[$country_code];
- }
-
- return true;
-
- }
- return false;
-
+ function add_translation($country_code, $language_array) { + + 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 != "") { + + if (!isset($CONFIG->translations[$country_code])) { + $CONFIG->translations[$country_code] = $language_array; + } else { + $CONFIG->translations[$country_code] = $language_array + $CONFIG->translations[$country_code]; + } + + return true; + + } + return false; + } /** @@ -62,130 +62,130 @@ $language = 'en'; return $language; - }
-
- /**
- * 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;
-
+ } + + /** + * 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; + $user = get_loggedin_user(); - $language = false;
-
- if (($user) && ($user->language))
- $language = $user->language;
-
- if ((!$language) && (isset($CONFIG->language)) && ($CONFIG->language))
+ $language = false; + + if (($user) && ($user->language)) + $language = $user->language; + + if ((!$language) && (isset($CONFIG->language)) && ($CONFIG->language)) $language = $CONFIG->language; - if ($language) {
- return $language;
- }
- return false;
-
- }
-
- /**
- * Given a message shortcode, returns an appropriately translated full-text string
- *
- * @param string $message_key The short message code
- * @param string $language Optionally, the standard language code (defaults to the site default, then English)
- * @return string Either the translated string, or the original English string, or an empty string
- */
- function elgg_echo($message_key, $language = "") {
-
+ if ($language) { + return $language; + } + return false; + + } + + /** + * Given a message shortcode, returns an appropriately translated full-text string + * + * @param string $message_key The short message code + * @param string $language Optionally, the standard language code (defaults to the site default, then English) + * @return string Either the translated string, or the original English string, or an empty string + */ + function elgg_echo($message_key, $language = "") { + global $CONFIG; static $CURRENT_LANGUAGE; - if ((!$CURRENT_LANGUAGE) && (!$language))
+ if ((!$CURRENT_LANGUAGE) && (!$language)) $CURRENT_LANGUAGE = $language = get_language(); else - $language = $CURRENT_LANGUAGE;
-
- if (isset($CONFIG->translations[$language][$message_key])) {
- return $CONFIG->translations[$language][$message_key];
- } else if (isset($CONFIG->translations["en"][$message_key])) {
- return $CONFIG->translations["en"][$message_key];
- }
-
- return $message_key;
-
- }
-
- /**
- * 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
- */
+ $language = $CURRENT_LANGUAGE; + + if (isset($CONFIG->translations[$language][$message_key])) { + return $CONFIG->translations[$language][$message_key]; + } else if (isset($CONFIG->translations["en"][$message_key])) { + return $CONFIG->translations["en"][$message_key]; + } + + return $message_key; + + } + + /** + * 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, $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] = true;
-
- // 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");
+ + // 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] = true; + + // 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('en.php', $current_language . '.php'))) /*&& (!is_dir($path . $language))*/) ||
- (($load_all) && (strpos($language, '.php')!==false)/* && (!is_dir($path . $language))*/)
- )
- include_once($path . $language);
-
- }
+ if ($handle = opendir($path)) { + while ($language = readdir($handle)) { + + 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;
-
- static $LANG_RELOAD_ALL_RUN;
- if ($LANG_RELOAD_ALL_RUN) return null;
-
- foreach ($CONFIG->language_paths as $path => $dummy)
- register_translations($path, true);
-
- $LANG_RELOAD_ALL_RUN = true;
- }
+ 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; + + static $LANG_RELOAD_ALL_RUN; + if ($LANG_RELOAD_ALL_RUN) return null; + + foreach ($CONFIG->language_paths as $path => $dummy) + register_translations($path, true); + + $LANG_RELOAD_ALL_RUN = true; + } /** * Return an array of installed translations as an associative array "two letter code" => "native language name". */ function get_installed_translations() { - global $CONFIG;
-
- // Ensure that all possible translations are loaded
+ global $CONFIG; + + // Ensure that all possible translations are loaded reload_all_translations(); - $installed = array();
+ $installed = array(); foreach ($CONFIG->translations as $k => $v) { @@ -204,9 +204,9 @@ */ function get_language_completeness($language) { - global $CONFIG;
-
- // Ensure that all possible translations are loaded
+ global $CONFIG; + + // Ensure that all possible translations are loaded reload_all_translations(); $language = sanitise_string($language); @@ -227,9 +227,9 @@ */ function get_missing_language_keys($language) { - global $CONFIG;
-
- // Ensure that all possible translations are loaded
+ global $CONFIG; + + // Ensure that all possible translations are loaded reload_all_translations(); $missing = array(); @@ -248,5 +248,5 @@ } register_translations(dirname(dirname(dirname(__FILE__))) . "/languages/"); -
+ ?>
\ No newline at end of file |