public function testGetNameDefaultLocale()
 {
     Locale::setDefault('de_AT');
     $names = $this->dataProvider->getNames('de_AT');
     foreach ($names as $script => $name) {
         $this->assertSame($name, $this->dataProvider->getName($script));
     }
 }
 public function testGetNameDefaultLocale()
 {
     Locale::setDefault('de_AT');
     $expected = $this->dataProvider->getNames('de_AT');
     $actual = array();
     foreach ($expected as $currency => $name) {
         $actual[$currency] = $this->dataProvider->getName($currency);
     }
     $this->assertSame($expected, $actual);
 }
 public function getNames($displayLocale = null)
 {
     if (null === $displayLocale) {
         $displayLocale = Locale::getDefault();
     }
     $names = $this->reader->readEntry($this->path, $displayLocale, array('Names'));
     if ($names instanceof \Traversable) {
         $names = iterator_to_array($names);
     }
     $collator = new \Collator($displayLocale);
     $collator->asort($names);
     return $names;
 }
 public function getNames($displayLocale = null)
 {
     if (null === $displayLocale) {
         $displayLocale = Locale::getDefault();
     }
     // ====================================================================
     // For reference: It is NOT possible to return names indexed by
     // numeric code here, because some numeric codes map to multiple
     // 3-letter codes (e.g. 32 => "ARA", "ARP", "ARS")
     // ====================================================================
     $names = $this->reader->readEntry($this->path, $displayLocale, array('Names'));
     if ($names instanceof \Traversable) {
         $names = iterator_to_array($names);
     }
     $index = static::INDEX_NAME;
     array_walk($names, function (&$value) use($index) {
         $value = $value[$index];
     });
     // Sorting by value cannot be done during bundle generation, because
     // binary bundles are always sorted by keys
     $collator = new \Collator($displayLocale);
     $collator->asort($names);
     return $names;
 }
示例#5
0
$baseDir = dirname(__DIR__) . '/data';
//$txtDir = $baseDir.'/txt';
$jsonDir = $baseDir;
//$phpDir = $baseDir.'/'.Intl::PHP;
//$resDir = $baseDir.'/'.Intl::RB_V2;
$targetDirs = array($jsonDir);
$workingDirs = array($jsonDir);
//$config->addBundleWriter($txtDir, new TextBundleWriter());
$config->addBundleWriter($jsonDir, new JsonBundleWriter());
echo "Starting resource bundle compilation. This may take a while...\n";
$filesystem->remove($workingDirs);
foreach ($workingDirs as $targetDir) {
    $filesystem->mkdir(array($targetDir . '/' . Intl::CURRENCY_DIR, $targetDir . '/' . Intl::LANGUAGE_DIR, $targetDir . '/' . Intl::LOCALE_DIR, $targetDir . '/' . Intl::REGION_DIR, $targetDir . '/' . Intl::SCRIPT_DIR));
}
// We don't want to use fallback to English during generation
Locale::setDefaultFallback(null);
echo "Generating language data...\n";
$generator = new LanguageDataGenerator($compiler, Intl::LANGUAGE_DIR);
$generator->generateData($config);
//echo "Compiling...\n";
//
//$compiler->compile($txtDir.'/'.Intl::LANGUAGE_DIR, $resDir.'/'.Intl::LANGUAGE_DIR);
echo "Generating script data...\n";
$generator = new ScriptDataGenerator($compiler, Intl::SCRIPT_DIR);
$generator->generateData($config);
//echo "Compiling...\n";
//
//$compiler->compile($txtDir.'/'.Intl::SCRIPT_DIR, $resDir.'/'.Intl::SCRIPT_DIR);
echo "Generating region data...\n";
$generator = new RegionDataGenerator($compiler, Intl::REGION_DIR);
$generator->generateData($config);
 protected function setUp()
 {
     Locale::setDefault('en');
     Locale::setDefaultFallback('en');
 }
 /**
  * {@inheritdoc}
  */
 public function readEntry($path, $locale, array $indices, $fallback = true)
 {
     $entry = null;
     $isMultiValued = false;
     $readSucceeded = false;
     $exception = null;
     $currentLocale = $locale;
     $testedLocales = array();
     while (null !== $currentLocale) {
         // Resolve any aliases to their target locales
         if (isset($this->localeAliases[$currentLocale])) {
             $currentLocale = $this->localeAliases[$currentLocale];
         }
         try {
             $data = $this->reader->read($path, $currentLocale);
             $currentEntry = RecursiveArrayAccess::get($data, $indices);
             $readSucceeded = true;
             $isCurrentTraversable = $currentEntry instanceof \Traversable;
             $isCurrentMultiValued = $isCurrentTraversable || is_array($currentEntry);
             // Return immediately if fallback is disabled or we are dealing
             // with a scalar non-null entry
             if (!$fallback || !$isCurrentMultiValued && null !== $currentEntry) {
                 return $currentEntry;
             }
             // =========================================================
             // Fallback is enabled, entry is either multi-valued or NULL
             // =========================================================
             // If entry is multi-valued, convert to array
             if ($isCurrentTraversable) {
                 $currentEntry = iterator_to_array($currentEntry);
             }
             // If previously read entry was multi-valued too, merge them
             if ($isCurrentMultiValued && $isMultiValued) {
                 $currentEntry = array_merge($currentEntry, $entry);
             }
             // Keep the previous entry if the current entry is NULL
             if (null !== $currentEntry) {
                 $entry = $currentEntry;
             }
             // If this or the previous entry was multi-valued, we are dealing
             // with a merged, multi-valued entry now
             $isMultiValued = $isMultiValued || $isCurrentMultiValued;
         } catch (ResourceBundleNotFoundException $e) {
             // Continue if there is a fallback locale for the current
             // locale
             $exception = $e;
         } catch (OutOfBoundsException $e) {
             // Remember exception and rethrow if we cannot find anything in
             // the fallback locales either
             $exception = $e;
         }
         // Remember which locales we tried
         $testedLocales[] = $currentLocale;
         // Check whether fallback is allowed
         if (!$fallback) {
             break;
         }
         // Then determine fallback locale
         $currentLocale = Locale::getFallback($currentLocale);
     }
     // Multi-valued entry was merged
     if ($isMultiValued) {
         return $entry;
     }
     // Entry is still NULL, but no read error occurred
     if ($readSucceeded) {
         return $entry;
     }
     // Entry is still NULL, read error occurred. Throw an exception
     // containing the detailed path and locale
     $errorMessage = sprintf('Couldn\'t read the indices [%s] for the locale "%s" in "%s".', implode('][', $indices), $locale, $path);
     // Append fallback locales, if any
     if (count($testedLocales) > 1) {
         // Remove original locale
         array_shift($testedLocales);
         $errorMessage .= sprintf(' The indices also couldn\'t be found for the fallback locale(s) "%s".', implode('", "', $testedLocales));
     }
     throw new MissingResourceException($errorMessage, 0, $exception);
 }
 public function connexion_utilisateurAction()
 {
     $request = $this->getRequest();
     $session = $request->getSession();
     // get the login error if there is one
     if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
         $error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
     } else {
         $error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
         $session->remove(SecurityContext::AUTHENTICATION_ERROR);
     }
     //Création des variables de session
     //Local pour la traduction et récupération des fichier XLLIF
     //$this->get('session')->set('_locale', 'fr');
     Locale::setDefaultFallback('fr');
     return $this->render('ROUtilisateurBundle:utilisateur:connexion_utilisateur.html.twig', array('error' => $error));
 }
 public function testGetNamesDefaultLocale()
 {
     Locale::setDefault('de_AT');
     $this->assertSame($this->dataProvider->getNames('de_AT'), $this->dataProvider->getNames());
 }
 /**
  * @return \IntlDateFormatter
  */
 private function getDateFormatter()
 {
     return \IntlDateFormatter::create(Locale::getDefault(), \IntlDateFormatter::SHORT, \IntlDateFormatter::NONE);
 }
 private function generateFallbackMapping(array $displayLocales, array $aliases)
 {
     $mapping = array();
     foreach ($displayLocales as $displayLocale => $_) {
         $mapping[$displayLocale] = null;
         $fallback = $displayLocale;
         // Recursively search for a fallback locale until one is found
         while (null !== ($fallback = Locale::getFallback($fallback))) {
             // Currently, no locale has an alias as fallback locale.
             // If this starts to be the case, we need to add code here.
             assert(!isset($aliases[$fallback]));
             // Check whether the fallback exists
             if (isset($displayLocales[$fallback])) {
                 $mapping[$displayLocale] = $fallback;
                 break;
             }
         }
     }
     return $mapping;
 }