Browse Source

Feature #306 - The internationalization library: Minor, cosmetic changes.

Ivan Tcholakov 15 years ago
parent
commit
ff6f2e3984

+ 62 - 67
main/inc/lib/internationalization.lib.php

@@ -5,7 +5,8 @@
  * Internationalization library for Dokeos 1.8.7 LMS
  * A library implementing internationalization related functions.
  * License: GNU/GPL version 2 or later (Free Software Foundation)
- * @author: Ivan Tcholakov, <ivantcholakov@gmail.com>, September 2009
+ * @author Ivan Tcholakov, <ivantcholakov@gmail.com>, September 2009
+ * @author More authors, mentioned in the correpsonding fragments of this source.
  * @package dokeos.library
  * ==============================================================================
  */
@@ -247,6 +248,65 @@ function api_get_interface_language($purified = false) {
 	return $language_interface;
 }
 
+/**
+ * Checks whether a given language identificator represents supported by *this library* language.
+ * @param string $language		The language identificator to be checked ('english', 'french', 'spanish', ...).
+ * @return bool $language		TRUE if the language is supported, FALSE otherwise.
+ */
+function api_is_language_supported($language) {
+	static $supported = array();
+	if (!isset($supported[$language])) {
+		$supported[$language] = in_array(api_refine_language_id($language), array_keys(_api_non_utf8_encodings()));
+	}
+	return $supported[$language];
+}
+
+/**
+ * Validates the input language identificator in order always to return a language that is enabled in the system.
+ * This function is to be used for data import when provided language identificators should be validated.
+ * @param string $language		The language identificator to be validated.
+ * @return string				Returns the input language identificator. If the input language is not enabled, platform language is returned then.
+ */
+function api_validate_language($language) {
+	static $enabled_languages;
+	if (!isset($enabled_languages)) {
+		$enabled_languages_info = api_get_languages();
+		$enabled_languages = $enabled_languages_info['folder'];
+	}
+	$language = str_replace('_km', '_KM', strtolower(trim($language)));
+	if (empty($language) || !in_array($language, $enabled_languages) || !api_is_language_supported($language)) {
+		$language = api_get_setting('platformLanguage');
+	}
+	return $language;
+}
+
+/**
+ * Returns a purified language id, without possible suffixes that will disturb language identification in certain cases.
+ * @param string $language	The input language identificator, for example 'french_unicode'.
+ * @param string			The same purified or filtered language identificator, for example 'french'.
+ */
+function api_refine_language_id($language) {
+	static $purified = array();
+	if (!isset($purified[$language])) {
+		$purified[$language] = str_replace(array('_unicode', '_latin', '_corporate', '_org', '_km'), '', strtolower($language));
+	}
+	return $purified[$language];
+}
+
+/**
+ * This function check whether a given language can use Latin 1 encoding.
+ * @param string $language	The checked language.
+ * @return bool				TRUE if the given language can use Latin 1 encoding (ISO-8859-15, ISO-8859-1, WINDOWS-1252, ...), FALSE otherwise.
+ */
+function api_is_latin1_compatible($language) {
+	static $latin1_languages;
+	if (!isset($latin1_languages)) {
+		$latin1_languages = _api_get_latin1_compatible_languages();
+	}
+	$language = api_refine_language_id($language);
+	return in_array($language, $latin1_languages);
+}
+
 
 /**
  * ----------------------------------------------------------------------------
@@ -940,6 +1000,7 @@ function api_utf8_decode_xml($string, $to_encoding = null) {
 	return _api_convert_encoding_xml($string, $to_encoding, 'UTF-8');
 }
 
+
 /**
  * ----------------------------------------------------------------------------
  * Common multibyte string functions
@@ -3149,72 +3210,6 @@ function api_is_valid_ascii(&$string) {
 }
 
 
-/**
- * ----------------------------------------------------------------------------
- * Language management functions
- * ----------------------------------------------------------------------------
- */
-
-/**
- * Checks whether a given language identificator represents supported by this library language.
- * @param string $language		The language identificator to be checked ('english', 'french', 'spanish', ...).
- * @return bool $language		TRUE if the language is supported, FALSE otherwise.
- */
-function api_is_language_supported($language) {
-	static $supported = array();
-	if (!isset($supported[$language])) {
-		$supported[$language] = in_array(api_refine_language_id($language), array_keys(_api_non_utf8_encodings()));
-	}
-	return $supported[$language];
-}
-
-/**
- * Validates the input language identificator in order always to return a language that is enabled in the system.
- * This function is to be used for data import when provided language identificators should be validated.
- * @param string $language		The language identificator to be validated.
- * @return string				Returns the input language identificator. If the input language is not enabled, platform language is returned then.
- */
-function api_validate_language($language) {
-	static $enabled_languages;
-	if (!isset($enabled_languages)) {
-		$enabled_languages_info = api_get_languages();
-		$enabled_languages = $enabled_languages_info['folder'];
-	}
-	$language = str_replace('_km', '_KM', strtolower(trim($language)));
-	if (empty($language) || !in_array($language, $enabled_languages) || !api_is_language_supported($language)) {
-		$language = api_get_setting('platformLanguage');
-	}
-	return $language;
-}
-
-/**
- * Returns a purified language id, without possible suffixes that will disturb language identification in certain cases.
- * @param string $language	The input language identificator, for example 'french_unicode'.
- * @param string			The same purified or filtered language identificator, for example 'french'.
- */
-function api_refine_language_id($language) {
-	static $purified = array();
-	if (!isset($purified[$language])) {
-		$purified[$language] = str_replace(array('_unicode', '_latin', '_corporate', '_org', '_km'), '', strtolower($language));
-	}
-	return $purified[$language];
-}
-
-/**
- * This function check whether a given language can use Latin 1 encoding.
- * @param string $language	The checked language.
- * @return bool				TRUE if the given language can use Latin 1 encoding (ISO-8859-15, ISO-8859-1, WINDOWS-1252, ...), FALSE otherwise.
- */
-function api_is_latin1_compatible($language) {
-	static $latin1_languages;
-	if (!isset($latin1_languages)) {
-		$latin1_languages = _api_get_latin1_compatible_languages();
-	}
-	$language = api_refine_language_id($language);
-	return in_array($language, $latin1_languages);
-}
-
-
 /**
  * ----------------------------------------------------------------------------
  * Functions for internal use behind this API.

+ 22 - 28
main/inc/lib/internationalization_internal.lib.php

@@ -2,10 +2,11 @@
 /**
  * ==============================================================================
  * File: internationalization_internal.lib.php
- * Main API extension library for Dokeos 1.8.6+ LMS,
+ * Main API extension library for Dokeos 1.8.7 LMS,
  * contains functions for internal use only.
  * License: GNU/GPL version 2 or later (Free Software Foundation)
- * @author: Ivan Tcholakov, ivantcholakov@gmail.com, 2009
+ * @author Ivan Tcholakov, <ivantcholakov@gmail.com>, September 2009
+ * @author More authors, mentioned in the correpsonding fragments of this source.
  * @package dokeos.library
  * ==============================================================================
  *
@@ -68,6 +69,25 @@ function & _get_lang_purify(& $string, & $language) {
 	return api_html_entity_decode($string, ENT_QUOTES, $system_encoding);
 }
 
+/**
+ * This function returns an array of those languages that can use Latin 1 encoding.
+ * @return array	The array of languages that can use Latin 1 encoding (ISO-8859-15, ISO-8859-1, WINDOWS-1252, ...).
+ * Note: The returned language identificators are purified, without suffixes.
+ */
+function _api_get_latin1_compatible_languages() {
+	static $latin1_languages;
+	if (!isset($latin1_languages)) {
+		$latin1_languages = array();
+		$encodings = & _api_non_utf8_encodings();
+		foreach ($encodings as $key => $value) {
+			if (api_is_latin1($value[0])) {
+				$latin1_languages[] = $key;
+			}
+		}
+	}
+	return $latin1_languages;
+}
+
 
 /**
  * ----------------------------------------------------------------------------
@@ -1080,32 +1100,6 @@ function _api_html_entity_supports($encoding) {
 }
 
 
-/**
- * ----------------------------------------------------------------------------
- * Appendix to "Language management functions"
- * ----------------------------------------------------------------------------
- */
-
-/**
- * This function returns an array of those languages that can use Latin 1 encoding.
- * @return array	The array of languages that can use Latin 1 encoding (ISO-8859-15, ISO-8859-1, WINDOWS-1252, ...).
- * Note: The returned language identificators are purified, without suffixes.
- */
-function _api_get_latin1_compatible_languages() {
-	static $latin1_languages;
-	if (!isset($latin1_languages)) {
-		$latin1_languages = array();
-		$encodings = & _api_non_utf8_encodings();
-		foreach ($encodings as $key => $value) {
-			if (api_is_latin1($value[0])) {
-				$latin1_languages[] = $key;
-			}
-		}
-	}
-	return $latin1_languages;
-}
-
-
 /**
  * ----------------------------------------------------------------------------
  * Upgrading the PHP5 mbstring extension