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

Numeric Fallback #128

Open
alethea opened this issue Apr 5, 2016 · 5 comments
Open

Numeric Fallback #128

alethea opened this issue Apr 5, 2016 · 5 comments

Comments

@alethea
Copy link

alethea commented Apr 5, 2016

Would it be in scope of this project to include an option to allow, Numeric#to_words to fallback to returning Numeric#to_s for locales that aren't supported?

@dblock
Copy link
Collaborator

dblock commented Apr 6, 2016

I am not sure. I think if the library can't convert something you'd probably want to get an error. At the very least that would be a change in behavior so we'd want a way to turn it off.

@alethea
Copy link
Author

alethea commented Apr 6, 2016

Oh, I'm so sorry, it looks like Github ate my description. I was suggesting it as an opt-in option. For instance, you're trying to render a page in the zh locale, it would fall back to numbers, but in en it would use words.

@dblock
Copy link
Collaborator

dblock commented Apr 6, 2016

👍 give it a shot

@jlduran
Copy link
Collaborator

jlduran commented Apr 6, 2016

@alethea Something like this?

require 'numbers_and_words'

number = 42
locales = %i(aa en es fr ru zh)

locales.each do |locale|
  begin
    I18n.with_locale(locale) { p number.to_words }
  rescue I18n::InvalidLocale
    p number
  end
end

# => 42
# => "forty-two"
# => "cuarenta y dos"
# => "quarante-deux"
# => "сорок два"
# => 42

@alethea
Copy link
Author

alethea commented Apr 7, 2016

@jlduran Yes, that's exactly the behavior I was proposing.

@dblock I'll see if I can put a PR together over the weekend.

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

No branches or pull requests

3 participants