Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function generateData(GeneratorConfig $config)
 {
     $filesystem = new Filesystem();
     $localeScanner = new LocaleScanner();
     $reader = new IntlBundleReader();
     $writers = $config->getBundleWriters();
     $tempDir = sys_get_temp_dir() . '/icu-data-' . $this->dirName;
     // Prepare filesystem directories
     foreach ($writers as $targetDir => $writer) {
         $filesystem->remove($targetDir . '/' . $this->dirName);
         $filesystem->mkdir($targetDir . '/' . $this->dirName);
     }
     $filesystem->remove($tempDir);
     $filesystem->mkdir($tempDir);
     $locales = $this->scanLocales($localeScanner, $config->getSourceDir());
     $this->compileTemporaryBundles($this->compiler, $config->getSourceDir(), $tempDir);
     $this->preGenerate();
     foreach ($locales as $locale) {
         $localeData = $this->generateDataForLocale($reader, $tempDir, $locale);
         if (null !== $localeData) {
             foreach ($writers as $targetDir => $writer) {
                 $writer->write($targetDir . '/' . $this->dirName, $locale, $localeData);
             }
         }
     }
     $rootData = $this->generateDataForRoot($reader, $tempDir);
     if (null !== $rootData) {
         foreach ($writers as $targetDir => $writer) {
             $writer->write($targetDir . '/' . $this->dirName, 'root', $rootData);
         }
     }
     $metaData = $this->generateDataForMeta($reader, $tempDir);
     if (null !== $metaData) {
         foreach ($writers as $targetDir => $writer) {
             $writer->write($targetDir . '/' . $this->dirName, 'meta', $metaData);
         }
     }
     // Clean up
     $filesystem->remove($tempDir);
 }
Exemplo n.º 2
0
    echo '[5/6] libicuio.so...';
    cd($sourceDir . '/io');
    run('make 2>&1 && make install 2>&1');
    echo " ok.\n";
    echo '[6/6] genrb...';
    cd($sourceDir . '/tools/genrb');
    run('make 2>&1 && make install 2>&1');
    echo " ok.\n";
}
$genrb = $buildDir . '/bin/genrb';
$genrbEnv = 'LD_LIBRARY_PATH=' . $buildDir . '/lib ';
echo "Using {$genrb}.\n";
$icuVersionInDownload = get_icu_version_from_genrb($genrbEnv . ' ' . $genrb);
echo "Preparing resource bundle compilation (version {$icuVersionInDownload})...\n";
$compiler = new GenrbCompiler($genrb, $genrbEnv);
$config = new GeneratorConfig($sourceDir . '/data', $icuVersionInDownload);
$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
 /**
  * {@inheritdoc}
  */
 public function generateData(GeneratorConfig $config)
 {
     $filesystem = new Filesystem();
     $localeScanner = new LocaleScanner();
     $writers = $config->getBundleWriters();
     // Prepare filesystem directories
     foreach ($writers as $targetDir => $writer) {
         $filesystem->remove($targetDir . '/' . $this->dirName);
         $filesystem->mkdir($targetDir . '/' . $this->dirName);
     }
     $locales = $localeScanner->scanLocales($config->getSourceDir() . '/locales');
     $aliases = $localeScanner->scanAliases($config->getSourceDir() . '/locales');
     // Flip to facilitate lookup
     $flippedLocales = array_flip($locales);
     // Don't generate names for aliases (names will be generated for the
     // locale they are duplicating)
     $displayLocales = array_diff_key($flippedLocales, $aliases);
     ksort($displayLocales);
     // Generate a list of (existing) locale fallbacks
     $fallbackMapping = $this->generateFallbackMapping($displayLocales, $aliases);
     $localeNames = array();
     // Generate locale names for all locales that have translations in
     // at least the language or the region bundle
     foreach ($displayLocales as $displayLocale => $_) {
         $localeNames[$displayLocale] = array();
         foreach ($locales as $locale) {
             try {
                 // Generate a locale name in the language of each display locale
                 // Each locale name has the form: "Language (Script, Region, Variant1, ...)
                 // Script, Region and Variants are optional. If none of them is
                 // available, the braces are not printed.
                 if (null !== ($name = $this->generateLocaleName($locale, $displayLocale))) {
                     $localeNames[$displayLocale][$locale] = $name;
                 }
             } catch (MissingResourceException $e) {
             } catch (ResourceBundleNotFoundException $e) {
             }
         }
     }
     // Process again to de-duplicate locales and their fallback locales
     // Only keep the differences
     foreach ($displayLocales as $displayLocale => $_) {
         $fallback = $displayLocale;
         while (isset($fallbackMapping[$fallback])) {
             $fallback = $fallbackMapping[$fallback];
             $localeNames[$displayLocale] = array_diff($localeNames[$displayLocale], $localeNames[$fallback]);
         }
         // If no names remain to be saved for the current locale, skip it
         if (0 === count($localeNames[$displayLocale])) {
             continue;
         }
         foreach ($writers as $targetDir => $writer) {
             $writer->write($targetDir . '/' . $this->dirName, $displayLocale, array('Names' => $localeNames[$displayLocale]));
         }
     }
     // Generate aliases, needed to enable proper fallback from alias to its
     // target
     foreach ($aliases as $alias => $aliasOf) {
         foreach ($writers as $targetDir => $writer) {
             $writer->write($targetDir . '/' . $this->dirName, $alias, array('%%ALIAS' => $aliasOf));
         }
     }
     // Create root file which maps locale codes to locale codes, for fallback
     foreach ($writers as $targetDir => $writer) {
         $writer->write($targetDir . '/' . $this->dirName, 'meta', array('Locales' => $locales, 'Aliases' => $aliases));
     }
 }