summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorMichael Tänzer <neo@nhng.de>2014-06-21 19:15:48 +0200
committerMichael Tänzer <neo@nhng.de>2014-06-21 19:15:48 +0200
commitda9630f06ea699f746002a41d167c09a42e7406f (patch)
treef76876387baf5a3a6ad6db340a3a38d64eb3c6e2 /includes
parent99f5de02f0204eb8876cbb897389bebceeb71c17 (diff)
downloadcacert-devel-da9630f06ea699f746002a41d167c09a42e7406f.tar.gz
cacert-devel-da9630f06ea699f746002a41d167c09a42e7406f.tar.xz
cacert-devel-da9630f06ea699f746002a41d167c09a42e7406f.zip
bug 1280: Implement normalisation in of language codes in the L10n classbug-1280
and use it (in set_translation() and the Assurer contact form) Signed-off-by: Michael Tänzer <neo@nhng.de>
Diffstat (limited to 'includes')
-rw-r--r--includes/lib/l10n.php53
1 files changed, 34 insertions, 19 deletions
diff --git a/includes/lib/l10n.php b/includes/lib/l10n.php
index 98e6e4a..e325add 100644
--- a/includes/lib/l10n.php
+++ b/includes/lib/l10n.php
@@ -226,6 +226,37 @@ class L10n {
}
/**
+ * Normalise the translation code (e.g. from the old codes to the new)
+ *
+ * @return string
+ * a translation code or the empty string if it can't be normalised
+ */
+ public static function normalise_translation($translation_code) {
+ // check $translation_code against whitelist
+ if (array_key_exists($translation_code, self::$translations) ) {
+ return $translation_code;
+ }
+
+ // maybe it's a locale as previously used in the system? e.g. en_AU
+ if (preg_match('/^([a-z][a-z])_([A-Z][A-Z])$/', $translation_code, $matches) !== 1) {
+ return '';
+ }
+
+ $lang_code = $matches[1];
+ $region_code = strtolower($matches[2]);
+
+ if (array_key_exists("${lang_code}-${region_code}", self::$translations)) {
+ return "${lang_code}-${region_code}";
+ }
+
+ if (array_key_exists($lang_code, self::$translations)) {
+ return $lang_code;
+ }
+
+ return '';
+ }
+
+ /**
* Get the set translation
*
* @return string
@@ -255,25 +286,9 @@ class L10n {
* </ul>
*/
public static function set_translation($translation_code) {
- // check $translation_code against whitelist
- if ( !array_key_exists($translation_code, self::$translations) ) {
- // maybe it's a locale as previously used in the system? e.g. en_AU
- if ( preg_match('/^([a-z][a-z])_([A-Z][A-Z])$/', $translation_code,
- $matches) !== 1 ) {
- return false;
- }
-
- $lang_code = $matches[1];
- $region_code = strtolower($matches[2]);
-
- if ( array_key_exists("${lang_code}-${region_code}",
- self::$translations) ) {
- $translation_code = "${lang_code}-${region_code}";
- } elseif ( array_key_exists($lang_code, self::$translations) ) {
- $translation_code = $lang_code;
- } else {
- return false;
- }
+ $translation_code = self::normalise_translation($translation_code);
+ if (empty($translation_code)) {
+ return false;
}
// map translation to locale