From 7bf7f8180dbc3a89824815de3bc1e4f40857d2f6 Mon Sep 17 00:00:00 2001 From: Stefan Parviainen Date: Wed, 31 Dec 2014 10:42:08 +0100 Subject: Revert "Revert "Language names via intl library."" This reverts commit 4f35efa0bad4ae6489b63f3eebafe6542d654094. --- library/intl/scripts/number_format/generate.php | 107 ++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 library/intl/scripts/number_format/generate.php (limited to 'library/intl/scripts/number_format') diff --git a/library/intl/scripts/number_format/generate.php b/library/intl/scripts/number_format/generate.php new file mode 100644 index 000000000..4308b4dc7 --- /dev/null +++ b/library/intl/scripts/number_format/generate.php @@ -0,0 +1,107 @@ + $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 = array(); +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) { + $json = json_encode($numberFormat, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); + file_put_contents($locale . '.json', $json); +} -- cgit v1.2.3