Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export currency names #51

Merged
merged 1 commit into from
Jun 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/cldr/export/data/currencies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@ def currencies

def currency(node)
data = select(node, 'displayName').inject({}) do |result, node|
count = node.attribute('count') ? node.attribute('count').value.to_sym : :one
result[count] = node.content unless draft?(node)
unless draft?(node)
if node.attribute('count')
count = node.attribute('count').value.to_sym
result[count] = node.content
else
result[:one] = node.content if result[:one].nil?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@froyomuffin Why is one special cased here?


  • This adds a one key for languages that don't have a one pluralization rule (e.g., zh), slightly bloating the data files)

  • This is missing all of the other pluralization keys that might be needed in the locale.

    I18n.with_locale(:af) do
      I18n.t("currencies.LVL", count: 0)
    end
    I18n::InvalidPluralizationData: translation data {:one=>"Lettiese lats", :name=>"Lettiese lats", :symbol=>"LVL"} can not be used with :count => 0. key 'other' is missing.
    

My guess without context is that this was done to give a "reasonable" default for the currency in cases where CLDR doesn't have pluralization translation information for the currency.

IMO, in some sense this is fabricating information that isn't in the upstream CLDR dataset.
Unless ruby-cldr's mission is to augment CLDR with its own, I feel that this logic belongs downstream of ruby-cldr in the consumer's code.

Copy link
Collaborator

@movermeyer movermeyer Sep 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see that you were just maintaining this existing behaviour (which is present all the way back to at least:

count = node.attribute('count') ? node.attribute('count').value.to_sym : :one

2009-12-30 (!)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for late reply. I honestly do not remember >.<

result[:name] = node.content
end
end

result
end

Expand All @@ -30,4 +38,4 @@ def currency(node)
end
end
end
end
end
7 changes: 6 additions & 1 deletion test/export/data/currencies_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ class TestCldrCurrencies < Test::Unit::TestCase
currencies = Cldr::Export::Data::Currencies.new('de')[:currencies]
assert_empty codes - currencies.keys, "Unexpected missing currencies"
assert_empty currencies.keys - codes, "Unexpected extra currencies"
assert_equal({ :one => 'Euro', :other => 'Euro', :symbol => '€' }, currencies[:EUR])
assert_equal({ :name => 'Euro', :one => 'Euro', :other => 'Euro', :symbol => '€' }, currencies[:EUR])
Copy link

@larouxn larouxn Jun 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should assert a locale/currency whose values differ such as en/CAD.

test 'currencies :en' do
  codes = [:ADP, :AED, :AFA, :AFN, :ALL, :AMD, :ANG, :AOA, :AOK, :AON, :AOR,
    :ARA, :ARP, :ARS, :ATS, :AUD, :AWG, :AZM, :AZN, :BAD, :BAM, :BBD,
    :BDT, :BEC, :BEF, :BEL, :BGL, :BGN, :BHD, :BIF, :BMD, :BND, :BOB,
    :BOP, :BOV, :BRB, :BRC, :BRE, :BRL, :BRN, :BRR, :BRZ, :BSD, :BTN,
    :BUK, :BWP, :BYB, :BYR, :BZD, :CAD, :CDF, :CHE, :CHF, :CHW, :CLF,
    :CLP, :CNY, :COP, :CRC, :CSD, :CSK, :CUC, :CUP, :CVE, :CYP, :CZK,
    :DDM, :DEM, :DJF, :DKK, :DOP, :DZD, :ECS, :ECV, :EEK, :EGP, :ERN,
    :ESA, :ESB, :ESP, :ETB, :EUR, :FIM, :FJD, :FKP, :FRF, :GBP, :GEK,
    :GEL, :GHC, :GHS, :GIP, :GMD, :GNF, :GNS, :GQE, :GRD, :GTQ, :GWE,
    :GWP, :GYD, :HKD, :HNL, :HRD, :HRK, :HTG, :HUF, :IDR, :IEP, :ILP,
    :ILS, :INR, :IQD, :IRR, :ISK, :ITL, :JMD, :JOD, :JPY, :KES, :KGS,
    :KHR, :KMF, :KPW, :KRW, :KWD, :KYD, :KZT, :LAK, :LBP, :LKR, :LRD,
    :LSL, :LTL, :LTT, :LUC, :LUF, :LUL, :LVL, :LVR, :LYD, :MAD, :MAF,
    :MDL, :MGA, :MGF, :MKD, :MLF, :MMK, :MNT, :MOP, :MRO, :MTL, :MTP,
    :MUR, :MVR, :MWK, :MXN, :MXP, :MXV, :MYR, :MZE, :MZM, :MZN, :NAD,
    :NGN, :NIC, :NIO, :NLG, :NOK, :NPR, :NZD, :OMR, :PAB, :PEI, :PEN,
    :PES, :PGK, :PHP, :PKR, :PLN, :PLZ, :PTE, :PYG, :QAR, :RHD, :ROL,
    :RON, :RSD, :RUB, :RUR, :RWF, :SAR, :SBD, :SCR, :SDD, :SDG, :SDP,
    :SEK, :SGD, :SHP, :SIT, :SKK, :SLL, :SOS, :SRD, :SRG, :SSP, :STD,
    :SUR, :SVC, :SYP, :SZL, :THB, :TJR, :TJS, :TMM, :TMT, :TND, :TOP,
    :TPE, :TRL, :TRY, :TTD, :TWD, :TZS, :UAH, :UAK, :UGS, :UGX, :USD,
    :USN, :USS, :UYP, :UYU, :UZS, :VEB, :VEF, :VND, :VUV, :WST, :XAF,
    :XAG, :XAU, :XBA, :XBB, :XBC, :XBD, :XCD, :XDR, :XEU, :XFO, :XFU,
    :XOF, :XPD, :XPF, :XPT, :XRE, :XTS, :XXX, :YDD, :YER, :YUD, :YUM,
    :YUN, :ZAL, :ZAR, :ZMK, :ZMW, :ZRN, :ZRZ, :ZWD, :ZWL, :ZWR, :ALK,
    :ARL, :ARM, :BAN, :BGM, :BGO, :BOL, :CLE, :CNX, :COU, :ILR, :ISJ,
    :KRH, :KRO, :MCF, :MDC, :MKN, :MVP, :UYI, :VNN, :XSU, :XUA, :YUR,
    :BYN, :CNH, :MRU, :STN, :VES, :UYW]

  currencies = Cldr::Export::Data::Currencies.new('en')[:currencies]
  assert_empty codes - currencies.keys, "Unexpected missing currencies"
  assert_empty currencies.keys - codes, "Unexpected extra currencies"

  # Note, for some reason, the currency symbol is missing for en.
  assert_equal({ :name => 'Canadian Dollar', :one => 'Canadian dollar', :other => 'Canadian dollars' }, currencies[:CAD])
end

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've generally treated the CLDR data as "correct" in the sense that there's not too much we as downstream consumers can do if it's wrong. Moreover, I'm fairly sure currencies get added and removed on a semi-frequent basis, so I'm not sure what value a test like this would bring us considering it would break whenever a currency like the South Sudanese pound is added.

end

test 'currencies uses the label to populate :one when count is unavailable' do
currencies = Cldr::Export::Data::Currencies.new('ak')[:currencies]
assert_equal({ :name => 'Yuan', :one => 'Yuan' }, currencies[:CNY])
end

# Cldr::Export::Data.locales.each do |locale|
Expand Down