Skip to content

Commit 4c4788d

Browse files
authored
Support currency locale overrides from CSV (#82)
* Add currency locale overrides where data is missing * Regenerate currencies to update locales
1 parent d933d7e commit 4c4788d

5 files changed

Lines changed: 167 additions & 21 deletions

File tree

cleanse/cleanse.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,28 @@ func LoadCurrencyLocales() map[string]string {
787787
return table
788788
}
789789

790+
791+
// For some reason, some countries are missing from the underlying CLDR "Numbers" data that we ingest.
792+
// It's easier to add this manual override than figure out how to fix the source data.
793+
func LoadLocaleOverrides() []common.Locale {
794+
results := []common.Locale{}
795+
796+
for _, record := range readCsv("data/overrides/locales.csv") {
797+
results = append(results, common.Locale{
798+
Id: record["id"],
799+
Name: record["name"],
800+
Country: record["country"],
801+
Language: record["language"],
802+
Numbers: common.LocaleNumbers{
803+
Decimal: record["numbers_decimal"],
804+
Group: record["numbers_group"],
805+
},
806+
})
807+
}
808+
809+
return results
810+
}
811+
790812
func LoadContinents() []Continent {
791813
return []Continent{
792814
Continent{

data/final/currencies.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@
301301
"symbols": {
302302
"primary": "CZK",
303303
"narrow": ""
304-
}
304+
},
305+
"default_locale": "cs-CZ"
305306
},
306307
{
307308
"name": "Danish Krone",
@@ -374,7 +375,8 @@
374375
"number_decimals": 2,
375376
"symbols": {
376377
"primary": "ETB"
377-
}
378+
},
379+
"default_locale": "am-ET"
378380
},
379381
{
380382
"name": "Euro",
@@ -706,7 +708,8 @@
706708
"number_decimals": 2,
707709
"symbols": {
708710
"primary": "MVR"
709-
}
711+
},
712+
"default_locale": "dv-MV"
710713
},
711714
{
712715
"name": "Mauritania Ouguiya",
@@ -789,7 +792,8 @@
789792
"symbols": {
790793
"primary": "NPR",
791794
"narrow": "Rs"
792-
}
795+
},
796+
"default_locale": "ne-NP"
793797
},
794798
{
795799
"name": "New Belarusian Ruble",
@@ -1046,7 +1050,8 @@
10461050
"number_decimals": 2,
10471051
"symbols": {
10481052
"primary": "RSD"
1049-
}
1053+
},
1054+
"default_locale": "sr-RS"
10501055
},
10511056
{
10521057
"name": "Seychelles Rupee",

data/final/locales.json

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@
4949
"group": ","
5050
}
5151
},
52+
{
53+
"id": "am-ET",
54+
"name": "Amharic - Ethiopia",
55+
"country": "ETH",
56+
"language": "am",
57+
"numbers": {
58+
"decimal": ".",
59+
"group": ","
60+
}
61+
},
5262
{
5363
"id": "ar-DZ",
5464
"name": "Arabic - Algeria",
@@ -489,6 +499,16 @@
489499
"group": "."
490500
}
491501
},
502+
{
503+
"id": "cs-CZ",
504+
"name": "Czech - Czechia",
505+
"country": "CZE",
506+
"language": "cs",
507+
"numbers": {
508+
"decimal": ",",
509+
"group": "."
510+
}
511+
},
492512
{
493513
"id": "da-DK",
494514
"name": "Danish - Denmark",
@@ -519,6 +539,16 @@
519539
"group": "."
520540
}
521541
},
542+
{
543+
"id": "dv-MV",
544+
"name": "Divehi - Maldives",
545+
"country": "MDV",
546+
"language": "dv",
547+
"numbers": {
548+
"decimal": ".",
549+
"group": ","
550+
}
551+
},
522552
{
523553
"id": "nl-AW",
524554
"name": "Dutch - Aruba",
@@ -569,6 +599,16 @@
569599
"group": "."
570600
}
571601
},
602+
{
603+
"id": "nl-SR",
604+
"name": "Dutch - Suriname",
605+
"country": "SUR",
606+
"language": "nl",
607+
"numbers": {
608+
"decimal": ",",
609+
"group": "."
610+
}
611+
},
572612
{
573613
"id": "nl",
574614
"name": "Dutch - The Netherlands",
@@ -1589,6 +1629,16 @@
15891629
"group": ","
15901630
}
15911631
},
1632+
{
1633+
"id": "et-EE",
1634+
"name": "Estonian - Estonia",
1635+
"country": "EST",
1636+
"language": "et",
1637+
"numbers": {
1638+
"decimal": ".",
1639+
"group": ","
1640+
}
1641+
},
15921642
{
15931643
"id": "et",
15941644
"name": "Estonian - Ethiopia",
@@ -2419,6 +2469,16 @@
24192469
"group": "."
24202470
}
24212471
},
2472+
{
2473+
"id": "lv-LV",
2474+
"name": "Latvian - Latvia",
2475+
"country": "LVA",
2476+
"language": "lv",
2477+
"numbers": {
2478+
"decimal": ".",
2479+
"group": ","
2480+
}
2481+
},
24222482
{
24232483
"id": "lv",
24242484
"name": "Latvian - Latvia",
@@ -2459,6 +2519,16 @@
24592519
"group": "."
24602520
}
24612521
},
2522+
{
2523+
"id": "lt-LT",
2524+
"name": "Lithuanian - Lithuania",
2525+
"country": "LTU",
2526+
"language": "lt",
2527+
"numbers": {
2528+
"decimal": ",",
2529+
"group": "."
2530+
}
2531+
},
24622532
{
24632533
"id": "lt",
24642534
"name": "Lithuanian - Lithuania",
@@ -2569,6 +2639,16 @@
25692639
"group": ","
25702640
}
25712641
},
2642+
{
2643+
"id": "ne-NP",
2644+
"name": "Nepali - Nepal",
2645+
"country": "NPL",
2646+
"language": "ne",
2647+
"numbers": {
2648+
"decimal": ".",
2649+
"group": ","
2650+
}
2651+
},
25722652
{
25732653
"id": "ne",
25742654
"name": "Nepali - Niger",
@@ -2619,6 +2699,16 @@
26192699
"group": ","
26202700
}
26212701
},
2702+
{
2703+
"id": "fa-TJ",
2704+
"name": "Persian - Tajikistan",
2705+
"country": "TJK",
2706+
"language": "fa",
2707+
"numbers": {
2708+
"decimal": ".",
2709+
"group": ","
2710+
}
2711+
},
26222712
{
26232713
"id": "pl",
26242714
"name": "Polish - Poland",
@@ -2889,6 +2979,16 @@
28892979
"group": "."
28902980
}
28912981
},
2982+
{
2983+
"id": "sr-RS",
2984+
"name": "Serbian - Serbia",
2985+
"country": "SRB",
2986+
"language": "sr",
2987+
"numbers": {
2988+
"decimal": ",",
2989+
"group": "."
2990+
}
2991+
},
28922992
{
28932993
"id": "sn",
28942994
"name": "Shona - Senegal",
@@ -3379,6 +3479,16 @@
33793479
"group": " "
33803480
}
33813481
},
3482+
{
3483+
"id": "tk-TM",
3484+
"name": "Turkmen - Turkmenistan",
3485+
"country": "TKM",
3486+
"language": "tk",
3487+
"numbers": {
3488+
"decimal": ",",
3489+
"group": "."
3490+
}
3491+
},
33823492
{
33833493
"id": "uk-UA",
33843494
"name": "Ukrainian - Ukraine",

data/overrides/locales.csv

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"id","name","country","language","numbers_decimal","numbers_group"
2+
"en-KY","English - Cayman Islands","CYM","en",".",","
3+
"cs-CZ","Czech - Czechia","CZE","cs",",","."
4+
"es-SV","Spanish - El Salvador","SLV","es",".",","
5+
"et-EE","Estonian - Estonia","EST","et",".",","
6+
"am-ET","Amharic - Ethiopia","ETH","am",".",","
7+
"en-FK","English - Falkland Islands","FLK","en",".",","
8+
"en-GI","English - Gibraltar","GIB","en",".",","
9+
"fr-HT","French - Haiti","HTI","fr",",","."
10+
"lv-LV","Latvian - Latvia","LVA","lv",".",","
11+
"lt-LT","Lithuanian - Lithuania","LTU","lt",",","."
12+
"fr-MG","French - Madagascar","MDG","fr",",","."
13+
"dv-MV","Divehi - Maldives","MDV","dv",".",","
14+
"ar-MR","Arabic - Mauritania","MRT","ar",".",","
15+
"pt-MZ","Portuguese - Mozambique","MOZ","pt",",","."
16+
"ne-NP","Nepali - Nepal","NPL","ne",".",","
17+
"es-PA","Spanish - Panama","PAN","es",",","."
18+
"pt-ST","Portuguese - São Tomé and Príncipe","STP","pt",",","."
19+
"sr-RS","Serbian - Serbia","SRB","sr",",","."
20+
"fa-TJ","Persian - Tajikistan","TJK","fa",".",","
21+
"en-SH","English - Saint Helena","SHN","en",".",","
22+
"nl-SR","Dutch - Suriname","SUR","nl",",","."
23+
"tk-TM","Turkmen - Turkmenistan","TKM","tk",",","."
24+
"zh-TW","Chinese - Taiwan","TWN","zh",".",","

final/final.go

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -184,21 +184,6 @@ func commonLocales(data CleansedDataSet) []common.Locale {
184184
"se": "sw",
185185
}
186186

187-
// For some reason, Taiwan is missing from the underlying CLDR "Numbers" data that we ingest.
188-
// It's easier to add this manual override than figuring out how to fix the source data.
189-
overrides := []common.Locale{
190-
common.Locale{
191-
Id: "zh-TW",
192-
Name: "Chinese - Taiwan",
193-
Country: "TWN",
194-
Language: "zh",
195-
Numbers: common.LocaleNumbers{
196-
Decimal: ".",
197-
Group: ",",
198-
},
199-
},
200-
}
201-
202187
unsupportedCountryCodes := common.UnsupportedCountryCodes()
203188

204189
for _, n := range data.Numbers {
@@ -294,7 +279,7 @@ func commonLocales(data CleansedDataSet) []common.Locale {
294279
}
295280
}
296281

297-
all = append(all, overrides...)
282+
all = append(all, cleanse.LoadLocaleOverrides()...)
298283

299284
uniqueLocales := uniqueLocaleIds(all)
300285
sortLocales(uniqueLocales)

0 commit comments

Comments
 (0)