From 9cab8ae58a29ecf7387e6865aa170715caeabf04 Mon Sep 17 00:00:00 2001 From: Stefan Parviainen Date: Tue, 30 Dec 2014 19:57:12 +0100 Subject: Language names via intl library. Fixes #773 --- library/intl/scripts/currency/generate.php | 153 +++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 library/intl/scripts/currency/generate.php (limited to 'library/intl/scripts/currency/generate.php') diff --git a/library/intl/scripts/currency/generate.php b/library/intl/scripts/currency/generate.php new file mode 100644 index 000000000..723906f7a --- /dev/null +++ b/library/intl/scripts/currency/generate.php @@ -0,0 +1,153 @@ +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'], array('XUA', 'XSU', 'XDR'))) { + // Ignore special currencies. + continue; + } + + $currencyCode = $currency['Ccy']; + $baseData[$currencyCode] = array( + 'code' => $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); +$json = json_encode($baseData, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); +file_put_contents('base.json', $json); + +// Gather available locales. +$locales = array(); +if ($handle = opendir('../json-full/main')) { + 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. +$currencies = array(); +foreach ($locales as $locale) { + $data = json_decode(file_get_contents('../json-full/main/' . $locale . '/currencies.json'), true); + $data = $data['main'][$locale]['numbers']['currencies']; + foreach ($data as $currencyCode => $currency) { + if (isset($baseData[$currencyCode])) { + $currencies[$locale][$currencyCode] = array( + 'name' => $currency['displayName'], + 'symbol' => $currency['symbol'], + ); + } + } +} + +// 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 ($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']); + }); + + $json = json_encode($localizedCurrencies, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); + file_put_contents($locale . '.json', $json); +} -- cgit v1.2.3 From 4f35efa0bad4ae6489b63f3eebafe6542d654094 Mon Sep 17 00:00:00 2001 From: RedMatrix Date: Wed, 31 Dec 2014 10:43:19 +1100 Subject: Revert "Language names via intl library." --- library/intl/scripts/currency/generate.php | 153 ----------------------------- 1 file changed, 153 deletions(-) delete mode 100644 library/intl/scripts/currency/generate.php (limited to 'library/intl/scripts/currency/generate.php') diff --git a/library/intl/scripts/currency/generate.php b/library/intl/scripts/currency/generate.php deleted file mode 100644 index 723906f7a..000000000 --- a/library/intl/scripts/currency/generate.php +++ /dev/null @@ -1,153 +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'], array('XUA', 'XSU', 'XDR'))) { - // Ignore special currencies. - continue; - } - - $currencyCode = $currency['Ccy']; - $baseData[$currencyCode] = array( - 'code' => $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); -$json = json_encode($baseData, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); -file_put_contents('base.json', $json); - -// Gather available locales. -$locales = array(); -if ($handle = opendir('../json-full/main')) { - 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. -$currencies = array(); -foreach ($locales as $locale) { - $data = json_decode(file_get_contents('../json-full/main/' . $locale . '/currencies.json'), true); - $data = $data['main'][$locale]['numbers']['currencies']; - foreach ($data as $currencyCode => $currency) { - if (isset($baseData[$currencyCode])) { - $currencies[$locale][$currencyCode] = array( - 'name' => $currency['displayName'], - 'symbol' => $currency['symbol'], - ); - } - } -} - -// 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 ($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']); - }); - - $json = json_encode($localizedCurrencies, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); - file_put_contents($locale . '.json', $json); -} -- cgit v1.2.3 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/currency/generate.php | 153 +++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 library/intl/scripts/currency/generate.php (limited to 'library/intl/scripts/currency/generate.php') diff --git a/library/intl/scripts/currency/generate.php b/library/intl/scripts/currency/generate.php new file mode 100644 index 000000000..723906f7a --- /dev/null +++ b/library/intl/scripts/currency/generate.php @@ -0,0 +1,153 @@ +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'], array('XUA', 'XSU', 'XDR'))) { + // Ignore special currencies. + continue; + } + + $currencyCode = $currency['Ccy']; + $baseData[$currencyCode] = array( + 'code' => $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); +$json = json_encode($baseData, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); +file_put_contents('base.json', $json); + +// Gather available locales. +$locales = array(); +if ($handle = opendir('../json-full/main')) { + 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. +$currencies = array(); +foreach ($locales as $locale) { + $data = json_decode(file_get_contents('../json-full/main/' . $locale . '/currencies.json'), true); + $data = $data['main'][$locale]['numbers']['currencies']; + foreach ($data as $currencyCode => $currency) { + if (isset($baseData[$currencyCode])) { + $currencies[$locale][$currencyCode] = array( + 'name' => $currency['displayName'], + 'symbol' => $currency['symbol'], + ); + } + } +} + +// 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 ($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']); + }); + + $json = json_encode($localizedCurrencies, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); + file_put_contents($locale . '.json', $json); +} -- cgit v1.2.3