grosser / i18n_data

Ruby: country/language names and 2-letter-code pairs, in 85 languages, for country/language i18n
MIT License
217 stars 63 forks source link

nil instead of raise #7

Open AlexLarra opened 10 years ago

AlexLarra commented 10 years ago

Hi grosser, I needed a list of languages translated in their own language and I used your gem. I did this helper.

def languages
  languages = {}

  I18nData.languages.each do |code, language|
    begin
      languages.merge!(I18nData.languages(code)[code] => code.downcase)
    rescue Exception => e
      languages.merge!(I18nData.languages('EN')[code] => code.downcase)
    end
  end
  languages
end

It would better not to work with rescue but there it is this line that uses raises instead of return nil: https://github.com/grosser/i18n_data/blob/b9d0db30acc1cbfe93446f4968561c201ae15ffb/lib/i18n_data/file_data_provider.rb#L8

Wouldn't be better to use nil?

Thank you for your gem

grosser commented 10 years ago

sounds like a good idea, can you make this a PR ?