/**
  * @dataProvider provideLocales
  */
 public function testGetName($displayLocale)
 {
     $names = $this->dataProvider->getNames($displayLocale);
     foreach ($names as $country => $name) {
         $this->assertSame($name, $this->dataProvider->getName($country, $displayLocale));
     }
 }
 private function generateLocaleName($locale, $displayLocale)
 {
     $name = null;
     $lang = \Locale::getPrimaryLanguage($locale);
     $script = \Locale::getScript($locale);
     $region = \Locale::getRegion($locale);
     $variants = \Locale::getAllVariants($locale);
     // Currently the only available variant is POSIX, which we don't want
     // to include in the list
     if (count($variants) > 0) {
         return;
     }
     // Some languages are translated together with their region,
     // i.e. "en_GB" is translated as "British English"
     // we don't include these languages though because they mess up
     // the name sorting
     // $name = $this->langBundle->getLanguageName($displayLocale, $lang, $region);
     // Some languages are simply not translated
     // Example: "az" (Azerbaijani) has no translation in "af" (Afrikaans)
     if (null === ($name = $this->languageDataProvider->getName($lang, $displayLocale))) {
         return;
     }
     // "as" (Assamese) has no "Variants" block
     //if (!$langBundle->get('Variants')) {
     //    continue;
     //}
     $extras = array();
     // Discover the name of the script part of the locale
     // i.e. in zh_Hans_MO, "Hans" is the script
     if ($script) {
         // Some scripts are not translated into every language
         if (null === ($scriptName = $this->scriptDataProvider->getName($script, $displayLocale))) {
             return;
         }
         $extras[] = $scriptName;
     }
     // Discover the name of the region part of the locale
     // i.e. in de_AT, "AT" is the region
     if ($region) {
         // Some regions are not translated into every language
         if (null === ($regionName = $this->regionDataProvider->getName($region, $displayLocale))) {
             return;
         }
         $extras[] = $regionName;
     }
     if (count($extras) > 0) {
         // Remove any existing extras
         // For example, in German, zh_Hans is "Chinesisch (vereinfacht)".
         // The latter is the script part which is already included in the
         // extras and will be appended again with the other extras.
         if (preg_match('/^(.+)\\s+\\([^\\)]+\\)$/', $name, $matches)) {
             $name = $matches[1];
         }
         $name .= ' (' . implode(', ', $extras) . ')';
     }
     return $name;
 }
Example #3
0
 /**
  * Creates a new region bundle.
  *
  * @param string                     $path
  * @param BundleEntryReaderInterface $reader
  * @param LocaleDataProvider         $localeProvider
  */
 public function __construct($path, BundleEntryReaderInterface $reader, LocaleDataProvider $localeProvider)
 {
     parent::__construct($path, $reader);
     $this->localeProvider = $localeProvider;
 }