Skip to content

Instantly share code, notes, and snippets.

@dustinsmith1024
Last active July 26, 2016 21:33
Show Gist options
  • Save dustinsmith1024/7da683cf644694af79d42d905398dbb6 to your computer and use it in GitHub Desktop.
Save dustinsmith1024/7da683cf644694af79d42d905398dbb6 to your computer and use it in GitHub Desktop.
Globalize by Locale
'use strict';
/**
* This shows the currency formatting by locales.
* To add a new locale just update the locales var below.
*
* To run:
* `node translations/tasks/example_outputs.js` to view the output.
*/
const Globalize = require( "globalize" ),
cldr = require( "cldr-data" ),
util = require('util');
Globalize.load( cldr.entireSupplemental() );
const LOCALES = ['en', 'fr', 'de', 'zh-HANS', 'zh-HANT', 'zh'],
LANGUAGES = ["AED", "AUD", "CAD", "CHF", "CLP", "CNY",
"COP", "CRC", "CZK", "EUR", "GBP", 'HKD', "ILS", "INR", "JPY",
"KRW", "MXN", "MYR", "NGN", "RUB", "SGD", "TWD", "USD", "MXN"];
function checkCurrency(currency) {
const style = 'accounting',
positive = Globalize.currencyFormatter(currency, {style: style})(123456789.0),
negative = Globalize.currencyFormatter(currency, {style: style})(-123456789.0);
return {
positive: positive,
negative: negative,
};
}
function log(locale, currency) {
const numbers = checkCurrency(currency);
console.log(util.format("%s %s \n\t%s \n\t%s\n", locale, currency, numbers.positive, numbers.negative));
}
LOCALES.forEach(locale => {
console.log("=============================================");
Globalize.load(cldr.entireMainFor(locale));
Globalize.locale(locale),
LANGUAGES.forEach(currency => {
log(locale, currency);
});
});
=============================================
en AED
AED 123,456,789.00
(AED 123,456,789.00)
en AUD
A$123,456,789.00
(A$123,456,789.00)
en CAD
CA$123,456,789.00
(CA$123,456,789.00)
en CHF
CHF 123,456,789.00
(CHF 123,456,789.00)
en CLP
CLP 123,456,789
(CLP 123,456,789)
en CNY
CN¥123,456,789.00
(CN¥123,456,789.00)
en COP
COP 123,456,789
(COP 123,456,789)
en CRC
CRC 123,456,789
(CRC 123,456,789)
en CZK
CZK 123,456,789.00
(CZK 123,456,789.00)
en EUR
€123,456,789.00
(€123,456,789.00)
en GBP
£123,456,789.00
(£123,456,789.00)
en HKD
HK$123,456,789.00
(HK$123,456,789.00)
en ILS
₪123,456,789.00
(₪123,456,789.00)
en INR
₹123,456,789.00
(₹123,456,789.00)
en JPY
¥123,456,789
(¥123,456,789)
en KRW
₩123,456,789
(₩123,456,789)
en MXN
MX$123,456,789.00
(MX$123,456,789.00)
en MYR
MYR 123,456,789.00
(MYR 123,456,789.00)
en NGN
NGN 123,456,789.00
(NGN 123,456,789.00)
en RUB
RUB 123,456,789.00
(RUB 123,456,789.00)
en SGD
SGD 123,456,789.00
(SGD 123,456,789.00)
en TWD
NT$123,456,789.00
(NT$123,456,789.00)
en USD
$123,456,789.00
($123,456,789.00)
en MXN
MX$123,456,789.00
(MX$123,456,789.00)
=============================================
fr AED
123 456 789,00 AED
(123 456 789,00 AED)
fr AUD
123 456 789,00 $AU
(123 456 789,00 $AU)
fr CAD
123 456 789,00 $CA
(123 456 789,00 $CA)
fr CHF
123 456 789,00 CHF
(123 456 789,00 CHF)
fr CLP
123 456 789 $CL
(123 456 789 $CL)
fr CNY
123 456 789,00 CNY
(123 456 789,00 CNY)
fr COP
123 456 789 $CO
(123 456 789 $CO)
fr CRC
123 456 789 CRC
(123 456 789 CRC)
fr CZK
123 456 789,00 CZK
(123 456 789,00 CZK)
fr EUR
123 456 789,00 €
(123 456 789,00 €)
fr GBP
123 456 789,00 £GB
(123 456 789,00 £GB)
fr HKD
123 456 789,00 HKD
(123 456 789,00 HKD)
fr ILS
123 456 789,00 ₪
(123 456 789,00 ₪)
fr INR
123 456 789,00 ₹
(123 456 789,00 ₹)
fr JPY
123 456 789 JPY
(123 456 789 JPY)
fr KRW
123 456 789 ₩
(123 456 789 ₩)
fr MXN
123 456 789,00 $MX
(123 456 789,00 $MX)
fr MYR
123 456 789,00 MYR
(123 456 789,00 MYR)
fr NGN
123 456 789,00 NGN
(123 456 789,00 NGN)
fr RUB
123 456 789,00 RUB
(123 456 789,00 RUB)
fr SGD
123 456 789,00 $SG
(123 456 789,00 $SG)
fr TWD
123 456 789,00 TWD
(123 456 789,00 TWD)
fr USD
123 456 789,00 $US
(123 456 789,00 $US)
fr MXN
123 456 789,00 $MX
(123 456 789,00 $MX)
=============================================
de AED
123.456.789,00 AED
-123.456.789,00 AED
de AUD
123.456.789,00 AU$
-123.456.789,00 AU$
de CAD
123.456.789,00 CA$
-123.456.789,00 CA$
de CHF
123.456.789,00 CHF
-123.456.789,00 CHF
de CLP
123.456.789 CLP
-123.456.789 CLP
de CNY
123.456.789,00 CN¥
-123.456.789,00 CN¥
de COP
123.456.789 COP
-123.456.789 COP
de CRC
123.456.789 CRC
-123.456.789 CRC
de CZK
123.456.789,00 CZK
-123.456.789,00 CZK
de EUR
123.456.789,00 €
-123.456.789,00 €
de GBP
123.456.789,00 £
-123.456.789,00 £
de HKD
123.456.789,00 HK$
-123.456.789,00 HK$
de ILS
123.456.789,00 ₪
-123.456.789,00 ₪
de INR
123.456.789,00 ₹
-123.456.789,00 ₹
de JPY
123.456.789 ¥
-123.456.789 ¥
de KRW
123.456.789 ₩
-123.456.789 ₩
de MXN
123.456.789,00 MX$
-123.456.789,00 MX$
de MYR
123.456.789,00 MYR
-123.456.789,00 MYR
de NGN
123.456.789,00 NGN
-123.456.789,00 NGN
de RUB
123.456.789,00 RUB
-123.456.789,00 RUB
de SGD
123.456.789,00 SGD
-123.456.789,00 SGD
de TWD
123.456.789,00 NT$
-123.456.789,00 NT$
de USD
123.456.789,00 $
-123.456.789,00 $
de MXN
123.456.789,00 MX$
-123.456.789,00 MX$
=============================================
zh-HANS AED
AED 123,456,789.00
(AED 123,456,789.00)
zh-HANS AUD
A$123,456,789.00
(A$123,456,789.00)
zh-HANS CAD
CA$123,456,789.00
(CA$123,456,789.00)
zh-HANS CHF
CHF 123,456,789.00
(CHF 123,456,789.00)
zh-HANS CLP
CLP 123,456,789
(CLP 123,456,789)
zh-HANS CNY
CN¥123,456,789.00
(CN¥123,456,789.00)
zh-HANS COP
COP 123,456,789
(COP 123,456,789)
zh-HANS CRC
CRC 123,456,789
(CRC 123,456,789)
zh-HANS CZK
CZK 123,456,789.00
(CZK 123,456,789.00)
zh-HANS EUR
€123,456,789.00
(€123,456,789.00)
zh-HANS GBP
£123,456,789.00
(£123,456,789.00)
zh-HANS HKD
HK$123,456,789.00
(HK$123,456,789.00)
zh-HANS ILS
₪123,456,789.00
(₪123,456,789.00)
zh-HANS INR
₹123,456,789.00
(₹123,456,789.00)
zh-HANS JPY
¥123,456,789
(¥123,456,789)
zh-HANS KRW
₩123,456,789
(₩123,456,789)
zh-HANS MXN
MX$123,456,789.00
(MX$123,456,789.00)
zh-HANS MYR
MYR 123,456,789.00
(MYR 123,456,789.00)
zh-HANS NGN
NGN 123,456,789.00
(NGN 123,456,789.00)
zh-HANS RUB
RUB 123,456,789.00
(RUB 123,456,789.00)
zh-HANS SGD
SGD 123,456,789.00
(SGD 123,456,789.00)
zh-HANS TWD
NT$123,456,789.00
(NT$123,456,789.00)
zh-HANS USD
$123,456,789.00
($123,456,789.00)
zh-HANS MXN
MX$123,456,789.00
(MX$123,456,789.00)
=============================================
zh-HANT AED
AED 123,456,789.00
(AED 123,456,789.00)
zh-HANT AUD
A$123,456,789.00
(A$123,456,789.00)
zh-HANT CAD
CA$123,456,789.00
(CA$123,456,789.00)
zh-HANT CHF
CHF 123,456,789.00
(CHF 123,456,789.00)
zh-HANT CLP
CLP 123,456,789
(CLP 123,456,789)
zh-HANT CNY
CN¥123,456,789.00
(CN¥123,456,789.00)
zh-HANT COP
COP 123,456,789
(COP 123,456,789)
zh-HANT CRC
CRC 123,456,789
(CRC 123,456,789)
zh-HANT CZK
CZK 123,456,789.00
(CZK 123,456,789.00)
zh-HANT EUR
€123,456,789.00
(€123,456,789.00)
zh-HANT GBP
£123,456,789.00
(£123,456,789.00)
zh-HANT HKD
HK$123,456,789.00
(HK$123,456,789.00)
zh-HANT ILS
₪123,456,789.00
(₪123,456,789.00)
zh-HANT INR
₹123,456,789.00
(₹123,456,789.00)
zh-HANT JPY
¥123,456,789
(¥123,456,789)
zh-HANT KRW
₩123,456,789
(₩123,456,789)
zh-HANT MXN
MX$123,456,789.00
(MX$123,456,789.00)
zh-HANT MYR
MYR 123,456,789.00
(MYR 123,456,789.00)
zh-HANT NGN
NGN 123,456,789.00
(NGN 123,456,789.00)
zh-HANT RUB
RUB 123,456,789.00
(RUB 123,456,789.00)
zh-HANT SGD
SGD 123,456,789.00
(SGD 123,456,789.00)
zh-HANT TWD
NT$123,456,789.00
(NT$123,456,789.00)
zh-HANT USD
$123,456,789.00
($123,456,789.00)
zh-HANT MXN
MX$123,456,789.00
(MX$123,456,789.00)
=============================================
zh AED
AED 123,456,789.00
(AED 123,456,789.00)
zh AUD
AU$123,456,789.00
(AU$123,456,789.00)
zh CAD
CA$123,456,789.00
(CA$123,456,789.00)
zh CHF
CHF 123,456,789.00
(CHF 123,456,789.00)
zh CLP
CLP 123,456,789
(CLP 123,456,789)
zh CNY
¥123,456,789.00
(¥123,456,789.00)
zh COP
COP 123,456,789
(COP 123,456,789)
zh CRC
CRC 123,456,789
(CRC 123,456,789)
zh CZK
CZK 123,456,789.00
(CZK 123,456,789.00)
zh EUR
€123,456,789.00
(€123,456,789.00)
zh GBP
£123,456,789.00
(£123,456,789.00)
zh HKD
HK$123,456,789.00
(HK$123,456,789.00)
zh ILS
₪123,456,789.00
(₪123,456,789.00)
zh INR
₹123,456,789.00
(₹123,456,789.00)
zh JPY
JP¥123,456,789
(JP¥123,456,789)
zh KRW
₩123,456,789
(₩123,456,789)
zh MXN
MX$123,456,789.00
(MX$123,456,789.00)
zh MYR
MYR 123,456,789.00
(MYR 123,456,789.00)
zh NGN
NGN 123,456,789.00
(NGN 123,456,789.00)
zh RUB
RUB 123,456,789.00
(RUB 123,456,789.00)
zh SGD
SGD 123,456,789.00
(SGD 123,456,789.00)
zh TWD
NT$123,456,789.00
(NT$123,456,789.00)
zh USD
US$123,456,789.00
(US$123,456,789.00)
zh MXN
MX$123,456,789.00
(MX$123,456,789.00)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment