diff options
author | Mario <mario@mariovavti.com> | 2019-11-10 12:49:51 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2019-11-10 14:10:03 +0100 |
commit | 580c3f4ffe9608d2beb56d418c68b3b112420e76 (patch) | |
tree | 82335d01179ac361d3f547a4b8e8c598d302e9f3 /vendor/commerceguys/intl/scripts | |
parent | d22766f458a8539a40a57f3946459a9be1f21cd6 (diff) | |
download | volse-hubzilla-580c3f4ffe9608d2beb56d418c68b3b112420e76.tar.gz volse-hubzilla-580c3f4ffe9608d2beb56d418c68b3b112420e76.tar.bz2 volse-hubzilla-580c3f4ffe9608d2beb56d418c68b3b112420e76.zip |
another bulk of composer updates
(cherry picked from commit 6685381fd8db507493c3d7c1793f8c05c681bbce)
Diffstat (limited to 'vendor/commerceguys/intl/scripts')
8 files changed, 716 insertions, 688 deletions
diff --git a/vendor/commerceguys/intl/scripts/country/generate.php b/vendor/commerceguys/intl/scripts/country/generate.php deleted file mode 100644 index ce156919a..000000000 --- a/vendor/commerceguys/intl/scripts/country/generate.php +++ /dev/null @@ -1,216 +0,0 @@ -<?php - -/** - * Generates the json files stored in resources/country. - */ -set_time_limit(0); - -// Downloaded from https://github.com/unicode-cldr/cldr-localenames-full.git -$localeDirectory = '../assets/cldr-localenames-full/main/'; -$enCountries = $localeDirectory . 'en/territories.json'; -// Downloaded from https://github.com/unicode-cldr/cldr-core.git -$codeMappings = '../assets/cldr-core/supplemental/codeMappings.json'; -$currencyData = '../assets/cldr-core/supplemental/currencyData.json'; -if (!file_exists($enCountries)) { - die("The $enCountries file was not found"); -} -if (!file_exists($codeMappings)) { - die("The $codeMappings file was not found"); -} -if (!file_exists($currencyData)) { - die("The $currencyData file was not found"); -} -if (!function_exists('collator_create')) { - // Reimplementing intl's collator would be a huge undertaking, so we - // use it instead to presort the generated locale specific data. - die('The intl extension was not found.'); -} -if (!is_dir($localeDirectory)) { - die("The $localeDirectory directory was not found"); -} - -$ignoredCountries = [ - 'AN', // Netherlands Antilles, no longer exists. - 'BV', 'HM', 'CP', // Uninhabited islands. - 'EU', 'QO', // European Union, Outlying Oceania. Not countries. - 'ZZ', // Unknown region -]; - -// Locales listed without a "-" match all variants. -// Locales listed with a "-" match only those exact ones. -$ignoredLocales = [ - // Interlingua is a made up language. - 'ia', - // Valencian differs from its parent only by a single character (è/é). - 'ca-ES-VALENCIA', - // Special "grouping" locales. - 'root', 'en-US-POSIX', 'en-001', 'en-150', 'es-419', -]; - -// Assemble the base data. Use the "en" data to get a list of countries. -$codeMappings = json_decode(file_get_contents($codeMappings), true); -$codeMappings = $codeMappings['supplemental']['codeMappings']; -$currencyData = json_decode(file_get_contents($currencyData), true); -$currencyData = $currencyData['supplemental']['currencyData']; -$countryData = json_decode(file_get_contents($enCountries), true); -$countryData = $countryData['main']['en']['localeDisplayNames']['territories']; -$baseData = []; -foreach ($countryData as $countryCode => $countryName) { - if (is_numeric($countryCode) || in_array($countryCode, $ignoredCountries)) { - // Ignore continents, regions, uninhabited islands. - continue; - } - if (strpos($countryCode, '-alt-') !== false) { - // Ignore alternative names. - continue; - } - - // Countries are not guaranteed to have an alpha3 and/or numeric code. - if (isset($codeMappings[$countryCode]['_alpha3'])) { - $baseData[$countryCode]['three_letter_code'] = $codeMappings[$countryCode]['_alpha3']; - } - if (isset($codeMappings[$countryCode]['_numeric'])) { - $baseData[$countryCode]['numeric_code'] = $codeMappings[$countryCode]['_numeric']; - } - - // Determine the current currency for this country. - if (isset($currencyData['region'][$countryCode])) { - $currencies = prepare_currencies($currencyData['region'][$countryCode]); - if ($currencies) { - $currentCurrency = end(array_keys($currencies)); - $baseData[$countryCode]['currency_code'] = $currentCurrency; - } - } -} - -// Write out base.json. -ksort($baseData); -file_put_json('base.json', $baseData); - -// Gather available locales. -$locales = []; -if ($handle = opendir($localeDirectory)) { - while (false !== ($entry = readdir($handle))) { - if (substr($entry, 0, 1) != '.') { - $entryParts = explode('-', $entry); - if (!in_array($entry, $ignoredLocales) && !in_array($entryParts[0], $ignoredLocales)) { - $locales[] = $entry; - } - } - } - closedir($handle); -} - -// Create the localizations. -$countries = []; -$untranslatedCounts = []; -foreach ($locales as $locale) { - $data = json_decode(file_get_contents($localeDirectory . $locale . '/territories.json'), true); - $data = $data['main'][$locale]['localeDisplayNames']['territories']; - foreach ($data as $countryCode => $countryName) { - if (isset($baseData[$countryCode])) { - // This country name is untranslated, use the english version. - if ($countryCode == str_replace('_', '-', $countryName)) { - $countryName = $countryData[$countryCode]; - // Maintain a count of untranslated countries per locale. - $untranslatedCounts += [$locale => 0]; - $untranslatedCounts[$locale]++; - } - - $countries[$locale][$countryCode] = [ - 'name' => $countryName, - ]; - } - } -} - -// Ignore locales that are more than 80% untranslated. -foreach ($untranslatedCounts as $locale => $count) { - $totalCount = count($countries[$locale]); - $untranslatedPercentage = $count * (100 / $totalCount); - if ($untranslatedPercentage >= 80) { - unset($countries[$locale]); - } -} - -// Identify localizations that are the same as the ones for the parent locale. -// For example, "fr-FR" if "fr" has the same data. -$duplicates = []; -foreach ($countries as $locale => $localizedCountries) { - if (strpos($locale, '-') !== false) { - $localeParts = explode('-', $locale); - array_pop($localeParts); - $parentLocale = implode('-', $localeParts); - $diff = array_udiff($localizedCountries, $countries[$parentLocale], function ($first, $second) { - return ($first['name'] == $second['name']) ? 0 : 1; - }); - - if (empty($diff)) { - // The duplicates are not removed right away because they might - // still be needed for other duplicate checks (for example, - // when there are locales like bs-Latn-BA, bs-Latn, bs). - $duplicates[] = $locale; - } - } -} -// Remove the duplicates. -foreach ($duplicates as $locale) { - unset($countries[$locale]); -} - -// Write out the localizations. -foreach ($countries as $locale => $localizedCountries) { - $collator = collator_create($locale); - uasort($localizedCountries, function ($a, $b) use ($collator) { - return collator_compare($collator, $a['name'], $b['name']); - }); - file_put_json($locale . '.json', $localizedCountries); -} - -/** - * Converts the provided data into json and writes it to the disk. - */ -function file_put_json($filename, $data) -{ - $data = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); - // Indenting with tabs instead of 4 spaces gives us 20% smaller files. - $data = str_replace(' ', "\t", $data); - file_put_contents($filename, $data); -} - -/** - * Prepares the currencies for a specific country. - */ -function prepare_currencies($currencies) { - if (empty($currencies)) { - return []; - } - // Rekey the array by currency code. - foreach ($currencies as $index => $realCurrencies) { - foreach ($realCurrencies as $currencyCode => $currency) { - $currencies[$currencyCode] = $currency; - } - unset($currencies[$index]); - } - // Remove non-tender currencies. - $currencies = array_filter($currencies, function ($currency) { - return !isset($currency['_tender']) || $currency['_tender'] != 'false'; - }); - // Sort by _from date. - uasort($currencies, 'compare_from_dates'); - - return $currencies; -} - -/** - * uasort callback for comparing arrays using their "_from" dates. - */ -function compare_from_dates($a, $b) { - $a = new DateTime($a['_from']); - $b = new DateTime($b['_from']); - // DateTime overloads the comparison providers. - if ($a == $b) { - return 0; - } - return ($a < $b) ? -1 : 1; -} diff --git a/vendor/commerceguys/intl/scripts/currency/generate.php b/vendor/commerceguys/intl/scripts/currency/generate.php deleted file mode 100644 index 63f0ef302..000000000 --- a/vendor/commerceguys/intl/scripts/currency/generate.php +++ /dev/null @@ -1,192 +0,0 @@ -<?php - -/** - * Generates the json files stored in resources/currency. - * - * The ISO currency list is used as a base, since it doesn't contain - * deprecated currencies, unlike CLDR (v25 has 139 deprecated entries). - */ -set_time_limit(0); - -// Downloaded from http://www.currency-iso.org/en/home/tables/table-a1.html -$isoCurrencies = '../assets/c2.xml'; -// Downloaded from https://github.com/unicode-cldr/cldr-numbers-full.git -$numbersDirectory = '../assets/cldr-numbers-full/main/'; -$cldrCurrencies = $numbersDirectory . 'en/currencies.json'; -// Downloaded from https://github.com/unicode-cldr/cldr-core.git -$currencyData = '../assets/cldr-core/supplemental/currencyData.json'; -// Downloaded from https://github.com/unicode-cldr/cldr-localenames-full.git -$localeDirectory = '../assets/cldr-localenames-full/main/'; -if (!file_exists($isoCurrencies)) { - die("The $isoCurrencies file was not found"); -} -if (!file_exists($cldrCurrencies)) { - die("The $cldrCurrencies file was not found"); -} -if (!file_exists($currencyData)) { - die("The $currencyData file was not found"); -} -if (!function_exists('collator_create')) { - // Reimplementing intl's collator would be a huge undertaking, so we - // use it instead to presort the generated locale specific data. - die('The intl extension was not found.'); -} -if (!is_dir($localeDirectory)) { - die("The $localeDirectory directory was not found"); -} -if (!is_dir($numbersDirectory)) { - die("The $numbersDirectory directory was not found"); -} - -// Locales listed without a "-" match all variants. -// Locales listed with a "-" match only those exact ones. -$ignoredLocales = [ - // Interlingua is a made up language. - 'ia', - // Valencian differs from its parent only by a single character (è/é). - 'ca-ES-VALENCIA', - // Special "grouping" locales. - 'root', 'en-US-POSIX', 'en-001', 'en-150', 'es-419', -]; - -// Assemble the base data. -$baseData = []; -$currencyData = json_decode(file_get_contents($currencyData), true); -$currencyData = $currencyData['supplemental']['currencyData']['fractions']; -$isoData = simplexml_load_file($isoCurrencies); -foreach ($isoData->CcyTbl->CcyNtry as $currency) { - $attributes = (array) $currency->CcyNm->attributes(); - if (!empty($attributes) && !empty($attributes['@attributes']['IsFund'])) { - // Ignore funds. - continue; - } - $currency = (array) $currency; - if (empty($currency['Ccy'])) { - // Ignore placeholders like "Antarctica". - continue; - } - if (substr($currency['CtryNm'], 0, 2) == 'ZZ' || in_array($currency['Ccy'], ['XUA', 'XSU', 'XDR'])) { - // Ignore special currencies. - continue; - } - - $currencyCode = $currency['Ccy']; - $baseData[$currencyCode] = [ - 'numeric_code' => $currency['CcyNbr'], - ]; - // Take the fraction digits from CLDR, not ISO, because it reflects real - // life usage more closely. If the digits aren't set, that means that the - // default value (2) should be used. - if (isset($currencyData[$currencyCode]['_digits'])) { - $fractionDigits = $currencyData[$currencyCode]['_digits']; - if ($fractionDigits != 2) { - $baseData[$currencyCode]['fraction_digits'] = $fractionDigits; - } - } -} - -// Write out base.json. -ksort($baseData); -file_put_json('base.json', $baseData); - -// Gather available locales. -$locales = []; -if ($handle = opendir($localeDirectory)) { - while (false !== ($entry = readdir($handle))) { - if (substr($entry, 0, 1) != '.') { - $entryParts = explode('-', $entry); - if (!in_array($entry, $ignoredLocales) && !in_array($entryParts[0], $ignoredLocales)) { - $locales[] = $entry; - } - } - } - closedir($handle); -} - -// Make sure 'en' is processed first so that it can be used as a fallback. -$index = array_search('en', $locales); -unset($locales[$index]); -array_unshift($locales, 'en'); - -// Create the localizations. -$currencies = []; -$untranslatedCounts = []; -foreach ($locales as $locale) { - $data = json_decode(file_get_contents($numbersDirectory . $locale . '/currencies.json'), true); - $data = $data['main'][$locale]['numbers']['currencies']; - foreach ($data as $currencyCode => $currency) { - if (isset($baseData[$currencyCode])) { - $currencyName = $currency['displayName']; - // This currency name is untranslated, use the english version. - if ($currencyCode == $currencyName) { - $currencyName = $currencies['en'][$currencyCode]['name']; - // Maintain a count of untranslated currencies per locale. - $untranslatedCounts += [$locale => 0]; - $untranslatedCounts[$locale]++; - } - - $currencies[$locale][$currencyCode] = [ - 'name' => $currencyName, - ]; - // Decrease the dataset size by exporting the symbol only if it's - // different from the currency code. - if ($currency['symbol'] != $currencyCode) { - $currencies[$locale][$currencyCode]['symbol'] = $currency['symbol']; - } - } - } -} - -// Ignore locales that are more than 80% untranslated. -foreach ($untranslatedCounts as $locale => $count) { - $totalCount = count($currencies[$locale]); - $untranslatedPercentage = $count * (100 / $totalCount); - if ($untranslatedPercentage >= 80) { - unset($currencies[$locale]); - } -} - -// Identify localizations that are the same as the ones for the parent locale. -// For example, "fr-FR" if "fr" has the same data. -$duplicates = []; -foreach ($currencies as $locale => $localizedCurrencies) { - if (strpos($locale, '-') !== false) { - $localeParts = explode('-', $locale); - array_pop($localeParts); - $parentLocale = implode('-', $localeParts); - $diff = array_udiff($localizedCurrencies, $currencies[$parentLocale], function ($first, $second) { - return ($first['name'] == $second['name']) ? 0 : 1; - }); - - if (empty($diff)) { - // The duplicates are not removed right away because they might - // still be needed for other duplicate checks (for example, - // when there are locales like bs-Latn-BA, bs-Latn, bs). - $duplicates[] = $locale; - } - } -} -// Remove the duplicates. -foreach ($duplicates as $locale) { - unset($currencies[$locale]); -} - -// Write out the localizations. -foreach ($currencies as $locale => $localizedCurrencies) { - $collator = collator_create($locale); - uasort($localizedCurrencies, function ($a, $b) use ($collator) { - return collator_compare($collator, $a['name'], $b['name']); - }); - file_put_json($locale . '.json', $localizedCurrencies); -} - -/** - * Converts the provided data into json and writes it to the disk. - */ -function file_put_json($filename, $data) -{ - $data = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); - // Indenting with tabs instead of 4 spaces gives us 20% smaller files. - $data = str_replace(' ', "\t", $data); - file_put_contents($filename, $data); -} diff --git a/vendor/commerceguys/intl/scripts/generate_currency_data.php b/vendor/commerceguys/intl/scripts/generate_currency_data.php new file mode 100644 index 000000000..9dfc262e1 --- /dev/null +++ b/vendor/commerceguys/intl/scripts/generate_currency_data.php @@ -0,0 +1,279 @@ +<?php + +/** + * Generates the json files stored in resources/currency. + * + * The ISO currency list is used as a base, since it doesn't contain + * deprecated currencies, unlike CLDR (v25 has 139 deprecated entries). + */ + +set_time_limit(0); +require __DIR__ . '/../vendor/autoload.php'; + +// Downloaded from http://www.currency-iso.org/en/home/tables/table-a1.html +$isoCurrencies = __DIR__ . '/assets/c2.xml'; +// Downloaded from https://github.com/unicode-cldr/cldr-numbers-full.git +$numbersDirectory = __DIR__ . '/assets/cldr-numbers-full/main/'; +$cldrCurrencies = $numbersDirectory . 'en/currencies.json'; +// Downloaded from https://github.com/unicode-cldr/cldr-core.git +$currencyData = __DIR__ . '/assets/cldr-core/supplemental/currencyData.json'; +// Downloaded from https://github.com/unicode-cldr/cldr-localenames-full.git +$localeDirectory = __DIR__ . '/assets/cldr-localenames-full/main/'; +if (!file_exists($isoCurrencies)) { + die("The $isoCurrencies file was not found"); +} +if (!file_exists($cldrCurrencies)) { + die("The $cldrCurrencies file was not found"); +} +if (!file_exists($currencyData)) { + die("The $currencyData file was not found"); +} +if (!function_exists('collator_create')) { + // Reimplementing intl's collator would be a huge undertaking, so we + // use it instead to presort the generated locale specific data. + die('The intl extension was not found.'); +} +if (!is_dir($localeDirectory)) { + die("The $localeDirectory directory was not found"); +} +if (!is_dir($numbersDirectory)) { + die("The $numbersDirectory directory was not found"); +} + +$currencyData = json_decode(file_get_contents($currencyData), true); +$isoData = simplexml_load_file($isoCurrencies); + +$baseData = generate_base_data($currencyData, $isoData); +$localizations = generate_localizations($baseData); +$localizations = filter_duplicate_localizations($localizations); + +// Make sure we're starting from a clean slate. +if (is_dir(__DIR__ . '/currency')) { + die('The currency/ directory must not exist.'); +} + +// Prepare the filesystem. +mkdir(__DIR__ . '/currency'); + +// Write out the localizations. +foreach ($localizations as $locale => $localizedCurrencies) { + $collator = collator_create($locale); + uasort($localizedCurrencies, function ($a, $b) use ($collator) { + return collator_compare($collator, $a['name'], $b['name']); + }); + file_put_json(__DIR__ . '/currency/' . $locale . '.json', $localizedCurrencies); +} + +$availableLocales = array_keys($localizations); +sort($availableLocales); +// Base currency definitions and available locales are stored +// in PHP, then manually transferred to CurrencyRepository. +$data = "<?php\n\n"; +$data .= export_locales($availableLocales); +$data .= export_base_data($baseData); +file_put_contents(__DIR__ . '/currency_data.php', $data); + +echo "Done.\n"; + +/** + * Converts the provided data into json and writes it to the disk. + */ +function file_put_json($filename, $data) +{ + $data = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); + // Indenting with tabs instead of 4 spaces gives us 20% smaller files. + $data = str_replace(' ', "\t", $data); + file_put_contents($filename, $data); +} + +/** + * Exports base data. + */ +function export_base_data($baseData) +{ + $export = '$baseData = [' . "\n"; + foreach ($baseData as $currencyCode => $currencyData) { + $export .= " '" . $currencyCode . "' => ['"; + $export .= $currencyData['numeric_code'] . "', " . $currencyData['fraction_digits']; + $export .= "],\n"; + } + $export .= "];"; + + return $export; +} + +/** + * Exports locales. + */ +function export_locales($data) +{ + // Wrap the values in single quotes. + $data = array_map(function ($value) { + return "'" . $value . "'"; + }, $data); + + $export = '// ' . count($data) . " available locales. \n"; + $export .= '$locales = [' . "\n"; + $export .= ' ' . implode(', ', $data) . "\n"; + $export .= "];\n\n"; + + return $export; +} + +/** + * Generates the base data. + */ +function generate_base_data(array $currencyData, $isoData) +{ + $baseData = []; + $currencyData = $currencyData['supplemental']['currencyData']['fractions']; + foreach ($isoData->CcyTbl->CcyNtry as $currency) { + $attributes = (array) $currency->CcyNm->attributes(); + if (!empty($attributes) && !empty($attributes['@attributes']['IsFund'])) { + // Ignore funds. + continue; + } + $currency = (array) $currency; + if (empty($currency['Ccy'])) { + // Ignore placeholders like "Antarctica". + continue; + } + if (substr($currency['CtryNm'], 0, 2) == 'ZZ' || in_array($currency['Ccy'], ['XUA', 'XSU', 'XDR'])) { + // Ignore special currencies. + continue; + } + + $currencyCode = $currency['Ccy']; + $baseData[$currencyCode] = [ + 'numeric_code' => $currency['CcyNbr'], + ]; + // Take the fraction digits from CLDR, not ISO, because it reflects real + // life usage more closely. + if (isset($currencyData[$currencyCode]['_digits'])) { + $baseData[$currencyCode]['fraction_digits'] = $currencyData[$currencyCode]['_digits']; + } else { + $baseData[$currencyCode]['fraction_digits'] = $currencyData['DEFAULT']['_digits']; + } + } + ksort($baseData); + + return $baseData; +} + +/** + * Generates the localizations. + */ +function generate_localizations(array $baseData) +{ + global $numbersDirectory; + + $locales = discover_locales(); + // Make sure 'en' is processed first so that it can be used as a fallback. + $index = array_search('en', $locales); + unset($locales[$index]); + array_unshift($locales, 'en'); + + $localizations = []; + $untranslatedCounts = []; + foreach ($locales as $locale) { + $data = json_decode(file_get_contents($numbersDirectory . $locale . '/currencies.json'), true); + $data = $data['main'][$locale]['numbers']['currencies']; + foreach ($data as $currencyCode => $currency) { + if (isset($baseData[$currencyCode])) { + $currencyName = $currency['displayName']; + // This currency name is untranslated, use the english version. + if ($currencyCode == $currencyName) { + $currencyName = $localizations['en'][$currencyCode]['name']; + // Maintain a count of untranslated currencies per locale. + $untranslatedCounts += [$locale => 0]; + $untranslatedCounts[$locale]++; + } + + $localizations[$locale][$currencyCode] = [ + 'name' => $currencyName, + ]; + // Decrease the dataset size by exporting the symbol only if it's + // different from the currency code. + if ($currency['symbol'] != $currencyCode) { + $localizations[$locale][$currencyCode]['symbol'] = $currency['symbol']; + } + } + } + } + + // Ignore locales that are more than 80% untranslated. + foreach ($untranslatedCounts as $locale => $count) { + $totalCount = count($localizations[$locale]); + $untranslatedPercentage = $count * (100 / $totalCount); + if ($untranslatedPercentage >= 80) { + unset($localizations[$locale]); + } + } + + return $localizations; +} + +/** + * Filters out duplicate localizations (same as their parent locale). + * + * For example, "fr-FR" will be removed if "fr" has the same data. + */ +function filter_duplicate_localizations(array $localizations) +{ + $duplicates = []; + foreach ($localizations as $locale => $localizedCurrencies) { + if ($parentLocale = \CommerceGuys\Intl\Locale::getParent($locale)) { + $parentCurrencies = isset($localizations[$parentLocale]) ? $localizations[$parentLocale] : []; + $diff = array_udiff($localizedCurrencies, $parentCurrencies, function ($first, $second) { + return ($first['name'] == $second['name']) ? 0 : 1; + }); + + if (empty($diff)) { + // The duplicates are not removed right away because they might + // still be needed for other duplicate checks (for example, + // when there are locales like bs-Latn-BA, bs-Latn, bs). + $duplicates[] = $locale; + } + } + } + foreach ($duplicates as $locale) { + unset($localizations[$locale]); + } + + return $localizations; +} + +/** + * Creates a list of available locales. + */ +function discover_locales() +{ + global $localeDirectory; + + // Locales listed without a "-" match all variants. + // Locales listed with a "-" match only those exact ones. + $ignoredLocales = [ + // Interlingua is a made up language. + 'ia', + // Valencian differs from its parent only by a single character (è/é). + 'ca-ES-VALENCIA', + // Special "grouping" locales. + 'root', 'en-US-POSIX', + ]; + + // Gather available locales. + $locales = []; + if ($handle = opendir($localeDirectory)) { + while (false !== ($entry = readdir($handle))) { + if (substr($entry, 0, 1) != '.') { + $entryParts = explode('-', $entry); + if (!in_array($entry, $ignoredLocales) && !in_array($entryParts[0], $ignoredLocales)) { + $locales[] = $entry; + } + } + } + closedir($handle); + } + + return $locales; +} diff --git a/vendor/commerceguys/intl/scripts/generate_language_data.php b/vendor/commerceguys/intl/scripts/generate_language_data.php new file mode 100644 index 000000000..a7dbd836e --- /dev/null +++ b/vendor/commerceguys/intl/scripts/generate_language_data.php @@ -0,0 +1,217 @@ +<?php + +/** + * Generates the json files stored in resources/language. + * + * CLDR lists about 515 languages, many of them dead (like Latin or Old English). + * In order to decrease the list to a reasonable size, only the languages + * for which CLDR itself has translations are listed. + */ + +set_time_limit(0); +require __DIR__ . '/../vendor/autoload.php'; + +// Downloaded from https://github.com/unicode-cldr/cldr-localenames-full.git +$localeDirectory = __DIR__ . '/assets/cldr-localenames-full/main/'; +$enLanguages = $localeDirectory . 'en/languages.json'; + +if (!is_dir($localeDirectory)) { + die("The $localeDirectory directory was not found"); +} +if (!file_exists($enLanguages)) { + die("The $enLanguages file was not found"); +} +if (!function_exists('collator_create')) { + // Reimplementing intl's collator would be a huge undertaking, so we + // use it instead to presort the generated locale specific data. + die('The intl extension was not found.'); +} + +$languages = generate_languages(); +$languages = filter_duplicate_localizations($languages); + +// Make sure we're starting from a clean slate. +if (is_dir(__DIR__ . '/language')) { + die('The language/ directory must not exist.'); +} + +// Prepare the filesystem. +mkdir(__DIR__ . '/language'); + +// Write out the localizations. +foreach ($languages as $locale => $localizedLanguages) { + $collator = collator_create($locale); + uasort($localizedLanguages, function ($a, $b) use ($collator) { + return collator_compare($collator, $a, $b); + }); + file_put_json(__DIR__ . '/language/' . $locale . '.json', $localizedLanguages); +} + +$availableLocales = array_keys($languages); +sort($availableLocales); +// Available locales are stored in PHP, then manually +// transferred to LanguageRepository. +$data = "<?php\n\n"; +$data .= export_locales($availableLocales); +file_put_contents(__DIR__ . '/language_data.php', $data); + +echo "Done.\n"; + +/** + * Converts the provided data into json and writes it to the disk. + */ +function file_put_json($filename, $data) +{ + $data = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); + // Indenting with tabs instead of 4 spaces gives us 20% smaller files. + $data = str_replace(' ', "\t", $data); + file_put_contents($filename, $data); +} + +/** + * Exports locales. + */ +function export_locales($data) +{ + // Wrap the values in single quotes. + $data = array_map(function ($value) { + return "'" . $value . "'"; + }, $data); + + $export = '// ' . count($data) . " available locales. \n"; + $export .= '$locales = [' . "\n"; + $export .= ' ' . implode(', ', $data) . "\n"; + $export .= "];\n"; + + return $export; +} + +/** + * Generates the language lists for each locale. + */ +function generate_languages() +{ + global $localeDirectory; + + $locales = discover_locales(); + // Make sure 'en' is processed first so that it can be used as a fallback. + $index = array_search('en', $locales); + unset($locales[$index]); + array_unshift($locales, 'en'); + // The filtering of the language list against the locale list can be + // too strict, filtering out languages that should be in the final list. + // This override ensures that such cases are covered. + $explicitlyAllowed = ['wa']; + // Languages that are untranslated in most locales (as of CLDR v34). + $explicitlyIgnored = ['ccp', 'fa-AF']; + + $untranslatedCounts = []; + $languages = []; + foreach ($locales as $locale) { + $data = json_decode(file_get_contents($localeDirectory . $locale . '/languages.json'), true); + $data = $data['main'][$locale]['localeDisplayNames']['languages']; + foreach ($data as $languageCode => $languageName) { + // Skip all languages that aren't an available locale at the same time. + // This reduces the language list from about 515 to about 185 languages. + if (!in_array($languageCode, $locales) && !in_array($languageCode, $explicitlyAllowed)) { + continue; + } + if (in_array($languageCode, $explicitlyIgnored)) { + continue; + } + + // This language name is untranslated, use to the english version. + if ($languageCode == str_replace('_', '-', $languageName)) { + $languageName = $languages['en'][$languageCode]; + // Maintain a count of untranslated languages per locale. + $untranslatedCounts += [$locale => 0]; + $untranslatedCounts[$locale]++; + } + + $languages[$locale][$languageCode] = $languageName; + } + // CLDR v34 has an uneven language list due to missing translations. + if ($locale != 'en') { + $missingLanguages = array_diff_key($languages['en'], $languages[$locale]); + foreach ($missingLanguages as $languageCode => $languageName) { + $languages[$locale][$languageCode] = $languages['en'][$languageCode]; + } + } + } + + // Ignore locales that are more than 80% untranslated. + foreach ($untranslatedCounts as $locale => $count) { + $totalCount = count($languages[$locale]); + $untranslatedPercentage = $count * (100 / $totalCount); + if ($untranslatedPercentage >= 80) { + unset($languages[$locale]); + } + } + + return $languages; +} + +/** + * Filters out duplicate localizations (same as their parent locale). + * + * For example, "fr-FR" will be removed if "fr" has the same data. + */ +function filter_duplicate_localizations(array $localizations) +{ + $duplicates = []; + foreach ($localizations as $locale => $localizedLanguages) { + if ($parentLocale = \CommerceGuys\Intl\Locale::getParent($locale)) { + $parentLanguages = isset($localizations[$parentLocale]) ? $localizations[$parentLocale] : []; + $diff = array_udiff($localizedLanguages, $parentLanguages, function ($first, $second) { + return ($first === $second) ? 0 : 1; + }); + + if (empty($diff)) { + // The duplicates are not removed right away because they might + // still be needed for other duplicate checks (for example, + // when there are locales like bs-Latn-BA, bs-Latn, bs). + $duplicates[] = $locale; + } + } + } + foreach ($duplicates as $locale) { + unset($localizations[$locale]); + } + + return $localizations; +} + +/** + * Creates a list of available locales. + */ +function discover_locales() +{ + global $localeDirectory; + + // Locales listed without a "-" match all variants. + // Locales listed with a "-" match only those exact ones. + $ignoredLocales = [ + // Interlingua is a made up language. + 'ia', + // Valencian differs from its parent only by a single character (è/é). + 'ca-ES-VALENCIA', + // Special "grouping" locales. + 'root', 'en-US-POSIX', + ]; + + // Gather available locales. + $locales = []; + if ($handle = opendir($localeDirectory)) { + while (false !== ($entry = readdir($handle))) { + if (substr($entry, 0, 1) != '.') { + $entryParts = explode('-', $entry); + if (!in_array($entry, $ignoredLocales) && !in_array($entryParts[0], $ignoredLocales)) { + $locales[] = $entry; + } + } + } + closedir($handle); + } + + return $locales; +} diff --git a/vendor/commerceguys/intl/scripts/generate_locale_data.php b/vendor/commerceguys/intl/scripts/generate_locale_data.php new file mode 100644 index 000000000..4e2b617b8 --- /dev/null +++ b/vendor/commerceguys/intl/scripts/generate_locale_data.php @@ -0,0 +1,15 @@ +<?php + +/** + * Generates the $parents array for the Locale class. + */ + +$parentLocales = __DIR__ . '/assets/cldr-core/supplemental/parentLocales.json'; +$parentLocales = json_decode(file_get_contents($parentLocales), true); +$parentLocales = $parentLocales['supplemental']['parentLocales']['parentLocale']; +$parentLocales = var_export($parentLocales, true) . ';'; + +$export = "<?php\n\n"; +$export .= '$parents = ' . str_replace(['array (', ')'], ['[', ']'], $parentLocales); +$export .= "\n"; +file_put_contents(__DIR__ . '/locale_data.php', $export); diff --git a/vendor/commerceguys/intl/scripts/generate_number_format_data.php b/vendor/commerceguys/intl/scripts/generate_number_format_data.php new file mode 100644 index 000000000..a9d7d4849 --- /dev/null +++ b/vendor/commerceguys/intl/scripts/generate_number_format_data.php @@ -0,0 +1,205 @@ +<?php + +/** + * Generates the json files stored in resources/number_format. + */ + +set_time_limit(0); +require __DIR__ . '/../vendor/autoload.php'; + +// Downloaded from https://github.com/unicode-cldr/cldr-localenames-full.git +$localeDirectory = __DIR__ . '/assets/cldr-localenames-full/main/'; +$enLanguages = $localeDirectory . 'en/languages.json'; +// Downloaded from https://github.com/unicode-cldr/cldr-numbers-full.git +$numbersDirectory = __DIR__ . '/assets/cldr-numbers-full/main/'; + +if (!is_dir($localeDirectory)) { + die("The $localeDirectory directory was not found"); +} +if (!is_dir($numbersDirectory)) { + die("The $numbersDirectory directory was not found"); +} +if (!file_exists($enLanguages)) { + die("The $enLanguages file was not found"); +} + +$numberFormats = generate_number_formats(); +$numberFormats = filter_duplicates($numberFormats); +// We treat 'en' as a generic definition, which allows +// us to strip any data that matches one of its keys. +foreach ($numberFormats as $locale => $numberFormat) { + if ($locale != 'en') { + $numberFormats[$locale] = array_diff_assoc($numberFormats[$locale], $numberFormats['en']); + } +} + +// Number formats are stored in PHP, then manually +// transferred to NumberFormatRepository. +$data = "<?php\n\n"; +$data .= export_number_formats($numberFormats); +file_put_contents(__DIR__ . '/number_formats.php', $data); + +echo "Done.\n"; + +/** + * Exports number formats. + */ +function export_number_formats(array $numberFormats) +{ + $indent = ' '; + $export = '// ' . count($numberFormats) . " available formats: \n"; + $export .= '$numberFormats = [' . "\n"; + foreach ($numberFormats as $locale => $numberFormat) { + $locale = "'" . $locale . "'"; + $export .= $indent . $locale . " => [\n"; + foreach ($numberFormat as $key => $value) { + $key = "'" . $key . "'"; + $value = "'" . $value . "'"; + $export .= $indent . $indent . $key . ' => ' . $value . ",\n"; + } + $export .= "$indent],\n"; + } + $export .= '];' . "\n\n"; + $export = str_replace("[\n$indent],", '[],', $export); + + return $export; +} + +/** + * Generates the number formats. + */ +function generate_number_formats() +{ + global $numbersDirectory; + + $numberFormats = []; + foreach (discover_locales() as $locale) { + $data = json_decode(file_get_contents($numbersDirectory . $locale . '/numbers.json'), true); + $data = $data['main'][$locale]['numbers']; + // Use the default numbering system, if it's supported. + if (in_array($data['defaultNumberingSystem'], ['arab', 'arabext', 'beng', 'deva', 'latn'])) { + $numberingSystem = $data['defaultNumberingSystem']; + } else { + $numberingSystem = 'latn'; + } + + $patterns = [ + 'decimal' => $data['decimalFormats-numberSystem-' . $numberingSystem]['standard'], + 'percent' => $data['percentFormats-numberSystem-' . $numberingSystem]['standard'], + 'currency' => $data['currencyFormats-numberSystem-' . $numberingSystem]['standard'], + 'accounting' => $data['currencyFormats-numberSystem-' . $numberingSystem]['accounting'], + ]; + // The "bg" patterns have no '#', confusing the formatter. + foreach ($patterns as $key => $pattern) { + if (strpos($pattern, '#') === false) { + $patterns[$key] = str_replace('0.00', '#0.00', $pattern); + } + } + + $numberFormats[$locale] = [ + 'numbering_system' => $numberingSystem, + 'decimal_pattern' => $patterns['decimal'], + 'percent_pattern' => $patterns['percent'], + 'currency_pattern' => $patterns['currency'], + 'accounting_currency_pattern' => $patterns['accounting'], + ]; + // No need to export 'latn' since that is the default value. + if ($numberFormats[$locale]['numbering_system'] != 'latn') { + $numberFormats[$locale]['numbering_system'] = $numberingSystem; + } + + // Add the symbols only if they're different from the default data. + $decimalSeparator = $data['symbols-numberSystem-' . $numberingSystem]['decimal']; + $groupingSeparator = $data['symbols-numberSystem-' . $numberingSystem]['group']; + $plusSign = $data['symbols-numberSystem-' . $numberingSystem]['plusSign']; + $minusSign = $data['symbols-numberSystem-' . $numberingSystem]['minusSign']; + $percentSign = $data['symbols-numberSystem-' . $numberingSystem]['percentSign']; + if ($decimalSeparator != '.') { + $numberFormats[$locale]['decimal_separator'] = $decimalSeparator; + } + if ($groupingSeparator != ',') { + $numberFormats[$locale]['grouping_separator'] = $groupingSeparator; + } + if ($plusSign != '+') { + $numberFormats[$locale]['plus_sign'] = $plusSign; + } + if ($minusSign != '-') { + $numberFormats[$locale]['minus_sign'] = $minusSign; + } + if ($percentSign != '%') { + $numberFormats[$locale]['percent_sign'] = $percentSign; + } + } + ksort($numberFormats); + + return $numberFormats; +} + +/** + * Filters out duplicate number formats (same as their parent locale). + * + * For example, "fr-FR" will be removed if "fr" has the same data. + */ +function filter_duplicates(array $numberFormats) +{ + $duplicates = []; + foreach ($numberFormats as $locale => $numberFormat) { + $parentNumberFormat = []; + $parentLocale = \CommerceGuys\Intl\Locale::getParent($locale); + if ($parentLocale && isset($numberFormats[$parentLocale])) { + $parentNumberFormat = $numberFormats[$parentLocale]; + } + + $diff = array_diff_assoc($numberFormat, $parentNumberFormat); + if (empty($diff)) { + // The duplicates are not removed right away because they might + // still be needed for other duplicate checks (for example, + // when there are locales like bs-Latn-BA, bs-Latn, bs). + $duplicates[] = $locale; + } + } + // Remove the duplicates. + foreach ($duplicates as $locale) { + unset($numberFormats[$locale]); + } + + return $numberFormats; +} + +/** + * Creates a list of available locales. + */ +function discover_locales() +{ + global $localeDirectory; + + // Locales listed without a "-" match all variants. + // Locales listed with a "-" match only those exact ones. + $ignoredLocales = [ + // Interlingua is a made up language. + 'ia', + // Ignored by other generation scripts, very minor locales. + 'as', 'asa', 'bem', 'ccp', 'chr', 'dav', 'dua', 'ebu', 'ewo', 'guz', 'gv', 'ii', + 'jgo', 'jmc', 'kam', 'kde', 'ki', 'kkj', 'kl', 'kln', 'ksb', 'kw', 'lag', + 'ln', 'mer', 'mgo', 'nd', 'nmg', 'nnh', 'nus', 'os', 'ps', 'rwk', 'sah', + 'saq', 'sbp', 'shi', 'sn', 'teo', 'vai', 'vun', 'xog', 'zgh', + // Special "grouping" locales. + 'root', 'en-US-POSIX', + ]; + + // Gather available locales. + $locales = []; + if ($handle = opendir($localeDirectory)) { + while (false !== ($entry = readdir($handle))) { + if (substr($entry, 0, 1) != '.') { + $entryParts = explode('-', $entry); + if (!in_array($entry, $ignoredLocales) && !in_array($entryParts[0], $ignoredLocales)) { + $locales[] = $entry; + } + } + } + closedir($handle); + } + + return $locales; +} diff --git a/vendor/commerceguys/intl/scripts/language/generate.php b/vendor/commerceguys/intl/scripts/language/generate.php deleted file mode 100644 index 72e8d1b44..000000000 --- a/vendor/commerceguys/intl/scripts/language/generate.php +++ /dev/null @@ -1,148 +0,0 @@ -<?php - -/** - * Generates the json files stored in resources/language. - * - * CLDR lists about 515 languages, many of them dead (like Latin or Old English). - * In order to decrease the list to a reasonable size, only the languages - * for which CLDR itself has translations are listed. - */ -set_time_limit(0); - -// Downloaded from https://github.com/unicode-cldr/cldr-localenames-full.git -$localeDirectory = '../assets/cldr-localenames-full/main/'; -$enLanguages = $localeDirectory . 'en/languages.json'; - -if (!is_dir($localeDirectory)) { - die("The $localeDirectory directory was not found"); -} -if (!file_exists($enLanguages)) { - die("The $enLanguages file was not found"); -} -if (!function_exists('collator_create')) { - // Reimplementing intl's collator would be a huge undertaking, so we - // use it instead to presort the generated locale specific data. - die('The intl extension was not found.'); -} - -// Locales listed without a "-" match all variants. -// Locales listed with a "-" match only those exact ones. -$ignoredLocales = [ - // Interlingua is a made up language. - 'ia', - // Valencian differs from its parent only by a single character (è/é). - 'ca-ES-VALENCIA', - // Special "grouping" locales. - 'root', 'en-US-POSIX', 'en-001', 'en-150', 'es-419', -]; - -$languages = []; -// Load the "en" data first so that it can be used as a fallback for -// untranslated language names in other locales. -$languageData = json_decode(file_get_contents($enLanguages), true); -$languageData = $languageData['main']['en']['localeDisplayNames']['languages']; -foreach ($languageData as $languageCode => $languageName) { - if (strpos($languageCode, '-alt-') === false) { - $languages['en'][$languageCode] = [ - 'name' => $languageName, - ]; - } -} - -// Gather available locales. -$locales = []; -if ($handle = opendir($localeDirectory)) { - while (false !== ($entry = readdir($handle))) { - if (substr($entry, 0, 1) != '.') { - $entryParts = explode('-', $entry); - if (!in_array($entry, $ignoredLocales) && !in_array($entryParts[0], $ignoredLocales)) { - $locales[] = $entry; - } - } - } - closedir($handle); -} - -// Remove all languages that aren't an available locale at the same time. -// This reduces the language list from about 515 to about 185 languages. -foreach ($languages['en'] as $languageCode => $languageData) { - if (!in_array($languageCode, $locales)) { - unset($languages['en'][$languageCode]); - } -} - -// Load the localizations. -$untranslatedCounts = []; -foreach ($locales as $locale) { - $data = json_decode(file_get_contents($localeDirectory . $locale . '/languages.json'), true); - $data = $data['main'][$locale]['localeDisplayNames']['languages']; - foreach ($data as $languageCode => $languageName) { - if (isset($languages['en'][$languageCode])) { - // This language name is untranslated, use to the english version. - if ($languageCode == str_replace('_', '-', $languageName)) { - $languageName = $languages['en'][$languageCode]['name']; - // Maintain a count of untranslated languages per locale. - $untranslatedCounts += [$locale => 0]; - $untranslatedCounts[$locale]++; - } - - $languages[$locale][$languageCode] = [ - 'name' => $languageName, - ]; - } - } -} - -// Ignore locales that are more than 80% untranslated. -foreach ($untranslatedCounts as $locale => $count) { - $totalCount = count($languages[$locale]); - $untranslatedPercentage = $count * (100 / $totalCount); - if ($untranslatedPercentage >= 80) { - unset($languages[$locale]); - } -} - -// Identify localizations that are the same as the ones for the parent locale. -// For example, "fr-FR" if "fr" has the same data. -$duplicates = []; -foreach ($languages as $locale => $localizedLanguages) { - if (strpos($locale, '-') !== false) { - $localeParts = explode('-', $locale); - array_pop($localeParts); - $parentLocale = implode('-', $localeParts); - $diff = array_udiff($localizedLanguages, $languages[$parentLocale], function ($first, $second) { - return ($first['name'] == $second['name']) ? 0 : 1; - }); - - if (empty($diff)) { - // The duplicates are not removed right away because they might - // still be needed for other duplicate checks (for example, - // when there are locales like bs-Latn-BA, bs-Latn, bs). - $duplicates[] = $locale; - } - } -} -// Remove the duplicates. -foreach ($duplicates as $locale) { - unset($languages[$locale]); -} - -// Write out the localizations. -foreach ($languages as $locale => $localizedLanguages) { - $collator = collator_create($locale); - uasort($localizedLanguages, function ($a, $b) use ($collator) { - return collator_compare($collator, $a['name'], $b['name']); - }); - file_put_json($locale . '.json', $localizedLanguages); -} - -/** - * Converts the provided data into json and writes it to the disk. - */ -function file_put_json($filename, $data) -{ - $data = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); - // Indenting with tabs instead of 4 spaces gives us 20% smaller files. - $data = str_replace(' ', "\t", $data); - file_put_contents($filename, $data); -} diff --git a/vendor/commerceguys/intl/scripts/number_format/generate.php b/vendor/commerceguys/intl/scripts/number_format/generate.php deleted file mode 100644 index 6809c980f..000000000 --- a/vendor/commerceguys/intl/scripts/number_format/generate.php +++ /dev/null @@ -1,132 +0,0 @@ -<?php - -/** - * Generates the json files stored in resources/number_format. - */ -set_time_limit(0); - -// Downloaded from https://github.com/unicode-cldr/cldr-localenames-full.git -$localeDirectory = '../assets/cldr-localenames-full/main/'; -$enLanguages = $localeDirectory . 'en/languages.json'; -// Downloaded from https://github.com/unicode-cldr/cldr-numbers-full.git -$numbersDirectory = '../assets/cldr-numbers-full/main/'; - -if (!is_dir($localeDirectory)) { - die("The $localeDirectory directory was not found"); -} -if (!is_dir($numbersDirectory)) { - die("The $numbersDirectory directory was not found"); -} -if (!file_exists($enLanguages)) { - die("The $enLanguages file was not found"); -} - -// Locales listed without a "-" match all variants. -// Locales listed with a "-" match only those exact ones. -$ignoredLocales = [ - // Interlingua is a made up language. - 'ia', - // Ignored by other generation scripts, very minor locales. - 'as', 'asa', 'bem', 'ccp', 'chr', 'dav', 'dua', 'ebu', 'ewo', 'guz', 'gv', 'ii', - 'jgo', 'jmc', 'kam', 'kde', 'ki', 'kkj', 'kl', 'kln', 'ksb', 'kw', 'lag', - 'ln', 'mer', 'mgo', 'nd', 'nmg', 'nnh', 'nus', 'os', 'ps', 'rwk', 'sah', - 'saq', 'sbp', 'shi', 'sn', 'teo', 'vai', 'vun', 'xog', 'zgh', - // Special "grouping" locales. - 'root', 'en-US-POSIX', 'en-001', 'en-150', 'es-419', -]; - -// Gather available locales. -$locales = []; -if ($handle = opendir($localeDirectory)) { - while (false !== ($entry = readdir($handle))) { - if (substr($entry, 0, 1) != '.') { - $entryParts = explode('-', $entry); - if (!in_array($entry, $ignoredLocales) && !in_array($entryParts[0], $ignoredLocales)) { - $locales[] = $entry; - } - } - } - closedir($handle); -} - -// Load the data. -$numberFormats = []; -foreach ($locales as $locale) { - $data = json_decode(file_get_contents($numbersDirectory . $locale . '/numbers.json'), true); - $data = $data['main'][$locale]['numbers']; - // Use the default numbering system, if it's supported. - if (in_array($data['defaultNumberingSystem'], ['arab', 'arabext', 'beng', 'deva', 'latn'])) { - $numberingSystem = $data['defaultNumberingSystem']; - } else { - $numberingSystem = 'latn'; - } - - $numberFormats[$locale] = [ - 'numbering_system' => $numberingSystem, - 'decimal_pattern' => $data['decimalFormats-numberSystem-' . $numberingSystem]['standard'], - 'percent_pattern' => $data['percentFormats-numberSystem-' . $numberingSystem]['standard'], - 'currency_pattern' => $data['currencyFormats-numberSystem-' . $numberingSystem]['standard'], - 'accounting_currency_pattern' => $data['currencyFormats-numberSystem-' . $numberingSystem]['accounting'], - ]; - - // Add the symbols only if they're different from the default data. - $decimalSeparator = $data['symbols-numberSystem-' . $numberingSystem]['decimal']; - $groupingSeparator = $data['symbols-numberSystem-' . $numberingSystem]['group']; - $plusSign = $data['symbols-numberSystem-' . $numberingSystem]['plusSign']; - $minusSign = $data['symbols-numberSystem-' . $numberingSystem]['minusSign']; - $percentSign = $data['symbols-numberSystem-' . $numberingSystem]['percentSign']; - if ($decimalSeparator != '.') { - $numberFormats[$locale]['decimal_separator'] = $decimalSeparator; - } - if ($groupingSeparator != ',') { - $numberFormats[$locale]['grouping_separator'] = $groupingSeparator; - } - if ($plusSign != '+') { - $numberFormats[$locale]['plus_sign'] = $plusSign; - } - if ($minusSign != '-') { - $numberFormats[$locale]['minus_sign'] = $minusSign; - } - if ($percentSign != '%') { - $numberFormats[$locale]['percent_sign'] = $percentSign; - } -} - -// Identify localizations that are the same as the ones for the parent locale. -// For example, "fr-FR" if "fr" has the same data. -$duplicates = []; -foreach ($numberFormats as $locale => $formatData) { - if (strpos($locale, '-') !== false) { - $localeParts = explode('-', $locale); - array_pop($localeParts); - $parentLocale = implode('-', $localeParts); - $diff = array_diff_assoc($formatData, $numberFormats[$parentLocale]); - - if (empty($diff)) { - // The duplicates are not removed right away because they might - // still be needed for other duplicate checks (for example, - // when there are locales like bs-Latn-BA, bs-Latn, bs). - $duplicates[] = $locale; - } - } -} -// Remove the duplicates. -foreach ($duplicates as $locale) { - unset($numberFormats[$locale]); -} - -// Write out the data. -foreach ($numberFormats as $locale => $numberFormat) { - file_put_json($locale . '.json', $numberFormat); -} - -/** - * Converts the provided data into json and writes it to the disk. - */ -function file_put_json($filename, $data) -{ - $data = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); - // Indenting with tabs instead of 4 spaces gives us 20% smaller files. - $data = str_replace(' ', "\t", $data); - file_put_contents($filename, $data); -} |