From c78c0aa828ab7ef25891eaa75eb318a938d9afff Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 7 Aug 2013 17:33:06 +0200 Subject: [PATCH] Fixed merge error See 00ffe72944e004e1dbbbad43fe644b733053d4a9 --- i18n/i18n.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/i18n/i18n.php b/i18n/i18n.php index 3879bc0f2..b54b13947 100644 --- a/i18n/i18n.php +++ b/i18n/i18n.php @@ -2224,15 +2224,22 @@ class i18n extends Object implements TemplateGlobalProvider { $allLocales = Config::inst()->get('i18n', 'all_locales'); $moduleLocales = scandir("{$module}/lang/"); foreach($moduleLocales as $moduleLocale) { - preg_match('/(.*)\.[\w\d]+$/',$moduleLocale, $matches); - if($locale = @$matches[1]) { - // Normalize locale to include likely region tag. + $locale = pathinfo($moduleLocale, PATHINFO_FILENAME); + $ext = pathinfo($moduleLocale, PATHINFO_EXTENSION); + if($locale && in_array($ext, array('php','yml'))) { + // Normalize locale to include likely region tag, avoid repetition in locale labels // TODO Replace with CLDR list of actually available languages/regions - $locale = str_replace('-', '_', self::get_locale_from_lang($locale)); - $locales[$locale] = (isset($allLocales[$locale])) ? $allLocales[$locale] : $locale; + // Only allow explicitly registered locales, otherwise we'll get into trouble + // if the locale doesn't exist in Zend's CLDR data + $labelLocale = str_replace('-', '_', self::get_locale_from_lang($locale)); + if(isset(self::$all_locales[$locale])) { + $locales[$locale] = self::$all_locales[$locale]; + } else if(isset(self::$all_locales[$labelLocale])) { + $locales[$locale] = self::$all_locales[$labelLocale]; } - } + } } + } // sort by title (not locale) asort($locales);