/** * {@inheritdoc} */ public function beforeCompile(CompilationContextInterface $context) { // The language data is contained in the locales bundle in ICU <= 4.2 if (IcuVersion::compare($context->getIcuVersion(), '4.2', '<=', 1)) { return $context->getSourceDir() . '/locales'; } return $context->getSourceDir() . '/lang'; }
/** * {@inheritdoc} */ public function beforeCompile(CompilationContextInterface $context) { // The currency data is contained in the locales and misc bundles // in ICU <= 4.2 if (IcuVersion::compare($context->getIcuVersion(), '4.2', '<=', 1)) { return array($context->getSourceDir() . '/misc/supplementalData.txt', $context->getSourceDir() . '/locales'); } return $context->getSourceDir() . '/curr'; }
private function scanLocales(CompilationContextInterface $context) { $tempDir = sys_get_temp_dir() . '/icu-data-locales-source'; $context->getFilesystem()->remove($tempDir); $context->getFilesystem()->mkdir($tempDir); // Temporarily generate the resource bundles $context->getCompiler()->compile($context->getSourceDir() . '/locales', $tempDir); // Discover the list of supported locales, which are the names of the resource // bundles in the "locales" directory $locales = glob($tempDir . '/*.res'); // Remove file extension and sort array_walk($locales, function (&$locale) { $locale = basename($locale, '.res'); }); sort($locales); // Delete unneeded locales foreach ($locales as $key => $locale) { // Delete all aliases from the list // i.e., "az_AZ" is an alias for "az_Latn_AZ" $content = file_get_contents($context->getSourceDir() . '/locales/' . $locale . '.txt'); // The key "%%ALIAS" is not accessible through the \ResourceBundle class, // so look in the original .txt file instead if (strpos($content, '%%ALIAS') !== false) { unset($locales[$key]); } // Delete locales that have no content (i.e. only "Version" key) try { $bundle = new \ResourceBundle($locale, $tempDir); } catch (\Exception $e) { // HHVM compatibility: constructor throws on invalid resource $bundle = null; } if (null === $bundle) { throw new RuntimeException('The resource bundle for locale ' . $locale . ' could not be loaded from directory ' . $tempDir); } // There seems to be no other way for identifying all keys in this specific // resource bundle if (array_keys(iterator_to_array($bundle)) === array('Version')) { unset($locales[$key]); } } $context->getFilesystem()->remove($tempDir); return $locales; }