handle non-string values in the "en.yml" files
Reported by Randy | August 17th, 2009 @ 04:38 PM
In summary, the problem is that some "translated values" in the built-in Rails en.yml files have non-string values such as booleans, . For example in activesupport/lib/active_support/locale/en.yml:
en:
<---- snip ---->
Used in array.to_sentence.
support: array:
sentence_connector: "and"
skip_last_comma: false
When globalize2 gets the "translation" for :"support.array.skip_last_comma", which is false, it assumes there is no translation (but there is... it's just the boolean value of false). This problem goes unnoticed until you extend the I18n.exception_handler (to do more fallback logic, exception notification, etc) like so:
module I18n
def self.just_raise_that_exception(exception, locale, key,
options)
if MissingTranslationData === exception
# fallbacks, exception notification, etc
raise exception
end
end end
I18n.exception_handler = :just_raise_that_exception
To reproduce this problem, just extend the I18n module as above, then go into the console and create an invalid object then look at its error messages in sentence form:
o = SomeObjectThatHasValidations.new
o.valid?
c.errors.full_messages.to_sentence
I18n::MissingTranslationData: translation missing: en, support,
array, skip_last_comma
Comments and changes to this ticket
-
Randy August 17th, 2009 @ 04:40 PM
Sorry about the formatting... just copied it from an email. The patch should be self-explanatory.
I'll add some tests and append to this ticket.
-
Randy August 18th, 2009 @ 05:46 PM
Here is the new patch, with changes to the test that takes this issue into account.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
The second incarnation of Globalize for Rails, which will let your Rails app speak any language on Earth, and beyond.