From 580c3f4ffe9608d2beb56d418c68b3b112420e76 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 10 Nov 2019 12:49:51 +0000 Subject: another bulk of composer updates (cherry picked from commit 6685381fd8db507493c3d7c1793f8c05c681bbce) --- .../commerceguys/intl/scripts/country/generate.php | 216 ---------------- .../intl/scripts/currency/generate.php | 192 -------------- .../intl/scripts/generate_currency_data.php | 279 +++++++++++++++++++++ .../intl/scripts/generate_language_data.php | 217 ++++++++++++++++ .../intl/scripts/generate_locale_data.php | 15 ++ .../intl/scripts/generate_number_format_data.php | 205 +++++++++++++++ .../intl/scripts/language/generate.php | 148 ----------- .../intl/scripts/number_format/generate.php | 132 ---------- 8 files changed, 716 insertions(+), 688 deletions(-) delete mode 100644 vendor/commerceguys/intl/scripts/country/generate.php delete mode 100644 vendor/commerceguys/intl/scripts/currency/generate.php create mode 100644 vendor/commerceguys/intl/scripts/generate_currency_data.php create mode 100644 vendor/commerceguys/intl/scripts/generate_language_data.php create mode 100644 vendor/commerceguys/intl/scripts/generate_locale_data.php create mode 100644 vendor/commerceguys/intl/scripts/generate_number_format_data.php delete mode 100644 vendor/commerceguys/intl/scripts/language/generate.php delete mode 100644 vendor/commerceguys/intl/scripts/number_format/generate.php (limited to 'vendor/commerceguys/intl/scripts') 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 @@ - $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 @@ -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 @@ + $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 = " $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 @@ + $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 = " $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 @@ + $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 = " $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 @@ - $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 @@ - $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); -} -- cgit v1.2.3