i18n and date_select exception
Reported by YavorIvanov | February 10th, 2009 @ 01:10 PM
When migrating a current project from GetText to i18n the following exception was thrown when using the date_select helper:
can't convert Symbol into String
When in your application you have set the I18n.locale to something different than "en" and you have the following simple code in your view:
<%= date_select("user_info", "birthdate") %>
You'll get the can't convert Symbol into String for the date_select helper. The problem can be rescued by giving the date_select helper order like this:
<%= date_select("user_info", "birthdate", :order => [:day,:month,:year]) %>
or by doing order in the yml file usually located at config/locales/your_lang.yml like this
date: formats: default: "" long: "" short: "" order: [ :day, :month, :year ]
Comments and changes to this ticket
- Assigned user cleared.
This was caused by missing translations?
date_helper.rb returns 'translation missing: nl, date, month_names' for month_names[number]
config/locale/nl.yml exists with the monthnames.
From the console:
I18n.l Date.today, :locale => :en => "2009-08-08" I18n.l Date.today, :locale => :nl I18n::MissingTranslationData: translation missing: nl, date, formats
Stupid, stupid: it has to be config/locales, not config/locale
Same cause for MvE?
Problem is somewhere at my end.
When I start a clean rails 2.3.2 project and download an untouched fr.yml file, then the application displays dates correctly in English & French.
Somehow, I'm causing the problem with projects updated from pre rails 2.3.2. Or when I add in a large block of application specific messages from the yml in an older application.
Ensuring that spaces, rather than any hidden tab characters in the yml file, keeps the dreaded "syntax error on line x, col y" error message away during the load. Unfortunately, as soon as I get an error free load, the "can't convert Symbol into String" returns.
Does any one know of a 'yml' validator routine, that would help me see how I'm causing the problem?
- Assigned user cleared.
Hi, i had the same problem than you and i finally found a solution.
Make sure the name is the same in all places.
In my case, i was using the es_MX locale, but the yml file was named es.yml and the start of the file was "es-MX":
So i changed the file name to be es_MX.yml, the start of the file to be the same "es_MX:" and make sure the line in config/environment.rb was right (config.i18n.default_locale = :es_MX). Notice that all have an underscore.
I hope that helps to you too.
Seems, numbers are shown because helper can't find proper month names (maybe problem with defining formats?).
Anyway this is how I solved it (pay attention to YAML layout):
lt: date: order: [ :year, :month, :day ] formats: default: "%Y-%m-%d" short: "%b %d" long: "%B %d, %Y" day_names: [Sekmadienis, Pirmadienis, Antradienis, Trečiadienis, Ketvirtadienis, Penktadienis, Sekmadienis] abbr_day_names: [S, P, A, T, K, Pn, Š] month_names: [~, Sausis, Vasaris, Kovas, Balandis, Gegužė, Birželis, Liepa, Rugpjūtis, Rugsėjis, Spalis, Lapkritis, Gruodis] abbr_month_names: [~, Sau, Vas, Kov, Bal, Geg, Bir, Lie, Rugs, Rugp, Spa, Lap, Gruo]
P.S. I registered to lighthouseapp.com only to show solution. Not sure if you will ever see me here.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
Internationalization API for Ruby.
This library is used in Ruby on Rails but also suited for use in other contexts.