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

Export currency names #51

merged 1 commit into from
Jun 17, 2019

Conversation

froyomuffin
Copy link
Collaborator

@froyomuffin froyomuffin commented Jun 6, 2019

Presently, we're not exporting the currency labels from CLDR data

Essentially, we have two use cases for this data:

  1. Render it with a number. Eg. 5 US dollars
  2. Render it within a list. Eg. US Dollar, Euro, etc

The capitalization is different in both cases.

The currently export implementation simply exports data as :one and then overrides it with the actual :one. This PR just exports the data under :name.

I also added a test to check the case where we only have a 'displayName' node that we use that node's data to populate :one.

@froyomuffin froyomuffin requested a review from camertron June 6, 2019 15:26
@froyomuffin
Copy link
Collaborator Author

@camertron I pushed the branch directly to this repo by mistake. Would you prefer I create a fork and restart there?

@froyomuffin froyomuffin force-pushed the export_currency_labels branch 2 times, most recently from dfaa818 to fc902b6 Compare June 6, 2019 18:55
@froyomuffin froyomuffin force-pushed the export_currency_labels branch from fc902b6 to 3e8c8d7 Compare June 6, 2019 19:10
@froyomuffin froyomuffin changed the title Export currency labels Export currency names Jun 6, 2019
Copy link

@larouxn larouxn left a comment

Choose a reason for hiding this comment

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

First time looking at this repo but changes look reasonable. One test comment.

@@ -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.

@camertron
Copy link
Collaborator

camertron commented Jun 7, 2019

@froyomuffin nah that's fine :) Prob won't be able to look at this PR until next week tho, is that cool?

@froyomuffin
Copy link
Collaborator Author

@camertron Yuppers :)

@larouxn
Copy link

larouxn commented Jun 15, 2019

👋 Any chance we can get this merged soon?

@camertron camertron merged commit 3dfe8b1 into master Jun 17, 2019
@camertron
Copy link
Collaborator

Published this in v0.3.0 of the gem (along with a few other things).

@camertron camertron deleted the export_currency_labels branch June 17, 2019 00:08
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 >.<

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants