Skip to content
This repository
Browse code

MINOR Reverting to use directory scanning rather than Zend_Translate(…

…) in i18n::get_existing_languages(), as the only way to determine this information from Zend is loading all locales (which is way too slow e.g. for loading a language drop down in the member profile)
  • Loading branch information...
commit 190c7586395348b66f93977c0f823dc14198fcd7 1 parent 326ff4a
Ingo Schommer authored December 04, 2011

Showing 1 changed file with 16 additions and 27 deletions. Show diff stats Hide diff stats

  1. 43  i18n/i18n.php
43  i18n/i18n.php
@@ -1597,46 +1597,35 @@ static function get_locale_list() {
1597 1597
 	/**
1598 1598
 	 * Searches the root-directory for module-directories
1599 1599
 	 * (identified by having a _config.php on their first directory-level).
1600  
-	 * Returns all found locales.
  1600
+	 * Finds locales by filename convention ("<locale>.<extension>", e.g. "de_AT.yml").
1601 1601
 	 * 
1602 1602
 	 * @return array
1603 1603
 	 */
1604 1604
 	static function get_existing_translations() {
1605  
-		$localeWithTitles = array();
  1605
+		$locales = array();
1606 1606
 		
1607  
-		foreach(self::get_translators() as $priority => $translators) {
1608  
-			foreach($translators as $name => $translator) {
1609  
-				$adapter = $translator->getAdapter();
1610  
-				// TODO Inspect themes
1611  
-				$modules = SS_ClassLoader::instance()->getManifest()->getModules();
1612  
-				foreach($modules as $module) {
1613  
-					if(!file_exists("{$module}/lang/")) continue;
1614  
-					$adapter->addTranslation(array(
1615  
-						'content' => "{$module}/lang/",
1616  
-						'scan' => Zend_Translate_Adapter::LOCALE_FILENAME,
1617  
-						// TODO Support custom translators with their own file extensions
1618  
-						'ignore' => array(
1619  
-							'.',
1620  
-							'_manifest_exclude',
1621  
-							'regex' => '/^.*\.(?!yml).*$/i'
1622  
-						)
1623  
-					));
1624  
-				}
1625  
-				$locales = $adapter->getList();
1626  
-				foreach($locales as $locale) {
  1607
+		// TODO Inspect themes
  1608
+		$modules = SS_ClassLoader::instance()->getManifest()->getModules();
  1609
+		
  1610
+		foreach($modules as $module) {
  1611
+			if(!file_exists("{$module}/lang/")) continue;
  1612
+			
  1613
+			$moduleLocales = scandir("{$module}/lang/");
  1614
+			foreach($moduleLocales as $moduleLocale) {
  1615
+				preg_match('/(.*)\.[\w\d]+$/',$moduleLocale, $matches);
  1616
+				if($locale = @$matches[1]) {
1627 1617
 					// Normalize locale to include likely region tag.
1628 1618
 					// TODO Replace with CLDR list of actually available languages/regions
1629  
-					$locale = self::get_locale_from_lang($locale);
1630  
-
1631  
-					$localeWithTitles[$locale] = (@self::$all_locales[$locale]) ? self::$all_locales[$locale] : $locale;
  1619
+					$locale = str_replace('-', '_', self::get_locale_from_lang($locale));
  1620
+					$locales[$locale] = (@self::$all_locales[$locale]) ? self::$all_locales[$locale] : $locale;
1632 1621
 				}
1633 1622
 			}
1634 1623
 		}
1635 1624
 
1636 1625
 		// sort by title (not locale)
1637  
-		asort($localeWithTitles);
  1626
+		asort($locales);
1638 1627
 		
1639  
-		return $localeWithTitles;
  1628
+		return $locales;
1640 1629
 	}
1641 1630
 	
1642 1631
 	/**

0 notes on commit 190c758

Please sign in to comment.
Something went wrong with that request. Please try again.