Skip to content

Commit

Permalink
fix: fix currency formatting for various locales
Browse files Browse the repository at this point in the history
  • Loading branch information
tmchow committed Jan 19, 2024
1 parent c54f338 commit 8de9ee5
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion lib/currency-locales/locales/da.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ da:

currency:
format:
format: "%u%n"
format: "%n%u"
unit: "kr"
separator: ","
delimiter: "."
Expand Down
2 changes: 1 addition & 1 deletion lib/currency-locales/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ja:
format:
format: "%u%n"
unit: "¥"
separator: "."
separator: ""
delimiter: ","
precision: 0
significant: false
Expand Down
16 changes: 10 additions & 6 deletions lib/currency-locales/locales/nb.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
nb:
number:
format: &number_format
format:
precision: 2
separator: ","
delimiter: ""
significant: false
strip_insignificant_zeros: false

currency:
format:
unit: "kr"
format: "%n%u"
<<: *number_format

format: "%n %u"
precision: 2
separator: ","
delimiter: ""
significant: false
strip_insignificant_zeros: false

percentage:
format:
delimiter: ""

precision:
format:
delimiter: ""
3 changes: 1 addition & 2 deletions lib/currency-locales/locales/pl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pl:

currency:
format:
format: "%n%u"
format: "%n %u"
unit: ""
separator: ","
delimiter: ""
Expand All @@ -24,4 +24,3 @@ pl:
precision:
format:
delimiter: ""

2 changes: 1 addition & 1 deletion lib/currency-locales/locales/th.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ th:

currency:
format:
format: "%n%u"
format: "%u%n"
unit: "฿"
separator: "."
delimiter: ","
Expand Down
2 changes: 1 addition & 1 deletion lib/currency-locales/locales/tr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ tr:

currency:
format:
format: "%n %u"
format: "%u%n"
unit: ""
separator: ","
delimiter: "."
Expand Down
45 changes: 21 additions & 24 deletions spec/integration/currency_locales_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
shared_examples_for "locale" do |locale_code, small_currency, big_currency, small_precision, big_precision|
let(:locale) { locale_code }

it "should translate the small amount to currency" do
it "should translate the small amount to currency for locale #{locale_code}" do
expect(number_to_currency(small_amount)).to eq(small_currency)
end

it "should translate the big amount to currency" do
it "should translate the big amount to currency for locale #{locale_code}" do
expect(number_to_currency(big_amount)).to eq(big_currency)
end

it "should translate the small amount with precision" do
it "should translate the small amount with precision for locale #{locale_code}" do
expect(number_with_precision(small_amount)).to eq(small_precision)
end

it "should translate the big amount with precision" do
it "should translate the big amount with precision for locale #{locale_code}" do
expect(number_with_precision(big_amount)).to eq(big_precision)
end
end
Expand All @@ -34,36 +34,33 @@ def number_with_precision(number)

locales = {
'cs' => ['9,99Kč', '9999,99Kč', '9,99', '9999,99'],
'da' => ['kr9,99', 'kr9.999,99', '9,99', '9.999,99'],
'da' => ['9,99kr', '9.999,99kr', '9,99', '9.999,99'],
'en-AU' => ['$9.99', '$9,999.99', '9.99', '9,999.99'],
'en-GB' => ['£9.99', '£9,999.99', '9.99', '9,999.99'],
'en-IN' => ['₹9.99', '₹9,999.99', '9.99', '9,999.99'],
'en-IN' => ['₹9.99', '₹9,999.99', '9.99', '9999.99'],
'en-PH' => ['₱9.99', '₱9,999.99', '9.99', '9,999.99'],
'es-MX' => ['$9.99', '$9,999.99', '9.99', '9,999.99'],
'en-US' => ['$9.99', '$9,999.99', '9.99', '9,999.99'],
'es-MX' => ['$9.99', '$9,999.99', '9.99', '9,999.99'],
'eu' => ['€9.99', '€9,999.99', '9.99', '9,999.99'],
'gsw-CH' => ['CHF9.99', 'CHF9,999.99', '9.99', '9,999.99'],
'hu' => ['10Ft', '10000Ft', '9,99', '9999,99'],
'id' => ['Rp9,99', 'Rp9.999,99', '9,99', '9.999,99'],
'it' => ['€9,99', '€9.999,99', '9,99', '9.999,99'],
'ko' => ['₩9.99', '₩9,999.99', '9.99', '9,999.99'],
'nl' => ['€9,99', '€9.999,99', '9,99', '9.999,99'],
'pt' => ['R$9,99', 'R$9.999,99', '9,99', '9.999,99'],
'ro' => ['9,99Lei', '9.999,99Lei', '9,99', '9.999,99'],
'ru' => ['9,99р.', '9.999,99р.', '9,99', '9.999,99'],
'sk' => ['9,99€', '9.999,99€', '9,99', '9.999,99'],
'il' => ['₪9.99', '₪9,999.99', '9.99', '9,999.99'],
'ja' => ['¥10', '¥10,000', '9.99', '9,999.99'],
'ms-MY' => ['RM9.99', 'RM9,999.99', '9.99', '9,999.99'],
'nb' => ['9,99 kr', '9999,99 kr', '9,99', '9999,99'],
'pl' => ['9,99 zł', '9999,99 zł', '9,99', '9999,99'],
'pt-BR' => ['R$9,99', 'R$9.999,99', '9,99', '9.999,99'],
'sv-SE' => ['9,99 kr', '9999,99 kr', '9,99', '9999,99'],
'th' => ['฿9.99', '฿9,999.99', '9.99', '9,999.99'],
'tr' => ['9,99₺', '9.999,99₺', '9,99', '9.999,99'],
'uk' => ['9,99₴', '9.999,99₴', '9,99', '9.999,99'],
'vi' => ['9,99₫', '9.999,99₫', '9,99', '9.999,99'],
'zh-CN' => ['¥9.99', '¥9,999.99', '9.99', '9,999.99'],
'zh-HK' => ['HK$9.99', 'HK$9,999.99', '9.99', '9,999.99'],
'zh-SG' => ['S$9.99', 'S$9,999.99', '9.99', '9,999.99'],
'tr' => ['₺9,99', '₺9.999,99', '9,99', '9.999,99'],
'zh-TW' => ['NT$9.99', 'NT$9,999.99', '9.99', '9,999.99'],
}

locales.each do |locale, values|
it_behaves_like "locale", locale, *values
sorted_locales = locales.sort_by { |locale, _| locale }.to_h

sorted_locales.each do |locale, values|
describe "locale #{locale}" do
it_behaves_like "locale", locale, *values
end
end
end

0 comments on commit 8de9ee5

Please sign in to comment.