Closed stiebitzhofer closed 11 years ago
Aloha, sorry for my insanely delayed response. Have you found a solution yet? I don't really understand what your problem is completely either. Can you pleas explain more or give some additional code or context so I can see what you're trying to do? Thanks
No, haven't found a solution yet - was quite busy and on vacation:-)
Let me try another way:
In a class I load the value from the database and retrieve the time zone string for setting the time zone with the function shown above, resulting in either "Bruxelles" or "Brüssel". When I set the time zone with
Time.zone = zone
this crashes.
I set time_zone and locales in the application controller:
before_filter :set_timezone
before_filter :set_locale
def set_timezone
if current_user && current_user.etsyshop && current_user.etsyshop.timezone && current_user.etsyshop.timezone != ""
Time.zone = current_user.etsyshop.timezone_s
end
end
def set_locale
unless params[:locale]
params[:locale] = extract_locale_from_accept_language_header
end
available = ['en', 'de']
if available.include? params[:locale]
I18n.locale = params[:locale]
end
end
Basically I am a bit glue less where to attack the problem. Any hints and help appreciated.
Ok, the problem is you're saving the translated version and trying to set the Rails timezone to the translated version. The problem is that Rails itself doesn't understand the translated names. It only knows the original zone names. You ought to just save the original version of the timezone not the translated versions and when you display them just display them based on the current locale so the user will see the translated version.
Okay, got it. Will do so. Should I write up how to do so when done?
If you think it would be useful for someone else then by all means please do. I know the docs are a little terse right now so some additional usage examples would probably be beneficial. Thanks
For rookies like me that would definitely shorten the process. Will do so and send you a pull request for your review. Thanks for your help, have a nice weekend.
I fixed it. It is so simple. Arrrgh. Anyway I past code here just in case somebody googles the stuff.
%br
%select{:name => "timezone"}
%option{:value => ''} #{t('myaccount.please_select')}
- ActiveSupport::TimeZone.all.each do |t|
%option{:value => t.name, :name => t.to_s, :selected => @user.etsyshop.timezone == t.name} #{t}
Thanks again for pointing me to the solution!
My application is localized in English and German, using ActiveSupport and i18n-timezones. When using English everything works fine with the following code.
However, if I switch to German and select e.g. "(GMT+1:00) Brüssel" the value get's stored properly but when I look up the value somewhere else in the code it crashes because this value is unknown - basically it works only for values where the German translations equals the English original.
I am a bit lost to be honest - can you give my any advise on how this works and where to adapt stuff get it working properly.