Hi,
I'm a bit puzzled with a translation problem: switching languages
doesn't work in production only for enum_string fields.
We are working on a Rails 3.0.10 + Hobo 1.3.0 app. It's a Car Rental
site, and we need it to work in English and Spanish. Right now
translations are working except for a enum_string field, where we have
found a weird behaviour when switching languages:
- - Language switches correctly in development mode, including the
enum_string field
- - Language switches correctly in production mode, *except* for the
enum_string field, which stays in the first language loaded (sometimes
spanish, sometimes english, depending on the param provided in the
first petition).
I have reproduced this behaviour in a clean one table Hobo app, and we
are switching languages using the official Rails guide method, so I
think that's not the problem. I believe that as the problem is in the
fix commented last year:
http://groups.google.com/group/hobousers/browse_thread/thread/484dc97b1e7c80e6?pli=1
:
Region = HoboFields::Types::EnumString.for(:ab, :bc, :name =>
"Region")
Somehow the enum_string is being cached and not changing languages.
Has anybody else seen this behaviour? Any tip on where to start digging?
Regards,
Ignacio
- --
Ignacio Huerta Arteche
http://www.ihuerta.net
Tel�fono: 0034 645 70 77 35
Email realizado con software libre
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk9FPj4ACgkQBPlUJ6RHaORIDgCdGIk7h/zxyVBJ6MGEVxt357a1
CxcAn1DYP0n2VRctcuAryxXD8ws7etTM
=+tMc
-----END PGP SIGNATURE-----
> - - Language switches correctly in development mode, including the
> enum_string field
> - - Language switches correctly in production mode, *except* for the
> enum_string field, which stays in the first language loaded (sometimes
> spanish, sometimes english, depending on the param provided in the
> first petition).
Current enum_string implementation doesn't consider locale switching.
As a workaround, you can re-initialize the enum_string on every
request in your application_controller:
prepend_before_filter :force_random_locale
def force_random_locale
I18n.locale = ("aa".."zz").to_a[rand(676)]
Region.with_values(*Region.values)
end
But it may produce strange results in threaded environment.
-----
Tomoaki Hayasaka <haya...@pfsl.mech.tohoku.ac.jp>
This is not a coincidence. Hobo's i18n mechanism was written by
people who actually use it: Spiralis and Domizio, primarily. The
only exception is the enum_string localization, which I wrote because
we needed to finish 1.3 and get it out the door, instead of writing it
because I needed it for one of my own websites.
So if somebody who actually creates multi-lingual websites wants to
take a crack at fixing this problem properly, that would be
appreciated.
Bryan
Thank you very much to both of you.
I'm afraid the workaround didn't work for me. I got this error:
uninitialized constant OrdersController::Region
I'm going to try to take a look at the Hobo code and see what I can
do. By the way, I created an ticket about this in lighthouse: we have
reached ticket number 1000!
Regards,
Ignacio
El 23/02/12 10:25, Bryan Larsen escribi�:
- --
Ignacio Huerta Arteche
http://www.ihuerta.net
Tel�fono: 0034 645 70 77 35
Email realizado con software libre
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk9GXgAACgkQBPlUJ6RHaOT9+ACggrtEJuZS6IMs52jj67XfrE0w
2t4An38tx05jVD4L3otJH6G+pm0lCKnR
=djc5
-----END PGP SIGNATURE-----
Hi,
I've been digging into this and I have found that right now the
enum_string translations is done within hobo_fields, and that makes
translations only work on first load in production mode.
Maybe we can move translations to the tag library? I made a small test
with the input tag and it worked nicely in development and production
mode:
<def tag="input" for="HoboFields::Types::EnumString" attrs="labels,
titleize, first-option, first-value"><%
labels ||= {}
labels = HashWithIndifferentAccess.new(labels)
titleize = true if titleize.nil?
# I18N: First we need to find the column name searching in the
content_columns
for column in model.content_columns.*.name
if model.attr_type(column) == this_type
options = this_type.values.map {|v|
[
I18n.t("activerecord.attributes.#{model.to_s.downcase}/#{column}s.#{v}",
:default => titleize ? v.titleize : v),
v]}
end
end
%>
<select name="#{param_name_for_this}" merge-attrs>
<option value="#{first_value}"
unless="&first_option.nil?"><first-option/></option>
<%= options_for_select(options, this) %>
</select>
</def>
Now you can add translations to your app.**.yml like this:
activerecord:
attributes:
order/pickup_points:
hotel: "Hotel"
office: "Oficina"
airport: "Aeropuerto"
Do you think this is a good solution? If you want I can test it a bit
more and make a pull request :).
Regards,
Ignacio
El 23/02/12 16:40, Ignacio Huerta escribi�:
iEYEARECAAYFAk9Gll0ACgkQBPlUJ6RHaOTPsgCdFKaWwla4YyTeq4xNjG48tMf2
hd0AnRWzO9nD09lo6hvRgCoq0q9JJFhQ
=gIP+
-----END PGP SIGNATURE-----
That seems like a reasonable solutiony to me.
El 23/02/12 16:40, Ignacio Huerta escribió:
> Thank you very much to both of you.
>
> I'm afraid the workaround didn't work for me. I got this error:
>
> uninitialized constant OrdersController::Region
>
> I'm going to try to take a look at the Hobo code and see what I
> can do. By the way, I created an ticket about this in lighthouse:
> we have reached ticket number 1000!
>
> https://hobo.lighthouseapp.com/projects/8324-hobo/tickets/1000-i18n-support-switching-locales-with-enum_string
>
> Regards, Ignacio
>
> El 23/02/12 10:25, Bryan Larsen escribió:
>>> Current enum_string implementation doesn't consider locale
>>> switching.
>
>> This is not a coincidence. Hobo's i18n mechanism was written by
>> people who actually use it: Spiralis and Domizio, primarily.
>> The only exception is the enum_string localization, which I
>> wrote because we needed to finish 1.3 and get it out the door,
>> instead of writing it because I needed it for one of my own
>> websites.
>
>> So if somebody who actually creates multi-lingual websites wants
>> to take a crack at fixing this problem properly, that would be
>> appreciated.
>
>> Bryan
>
>
- --
Ignacio Huerta Arteche
http://www.ihuerta.net
Teléfono: 0034 645 70 77 35
Email realizado con software libre
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk9Gll0ACgkQBPlUJ6RHaOTPsgCdFKaWwla4YyTeq4xNjG48tMf2
hd0AnRWzO9nD09lo6hvRgCoq0q9JJFhQ
=gIP+
-----END PGP SIGNATURE-----
--
You received this message because you are subscribed to the Google Groups "Hobo Users" group.
To post to this group, send email to hobo...@googlegroups.com.
To unsubscribe from this group, send email to hobousers+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/hobousers?hl=en.
El 23/02/12 16:40, Ignacio Huerta escribi�:
> Thank you very much to both of you.
>
> I'm afraid the workaround didn't work for me. I got this error:
>
> uninitialized constant OrdersController::Region
>
> I'm going to try to take a look at the Hobo code and see what I
> can do. By the way, I created an ticket about this in lighthouse:
> we have reached ticket number 1000!
>
> https://hobo.lighthouseapp.com/projects/8324-hobo/tickets/1000-i18n-support-switching-locales-with-enum_string
>
> Regards, Ignacio
>
> El 23/02/12 10:25, Bryan Larsen escribi�:
>>> Current enum_string implementation doesn't consider locale
>>> switching.
>
>> This is not a coincidence. Hobo's i18n mechanism was written by
>> people who actually use it: Spiralis and Domizio, primarily.
>> The only exception is the enum_string localization, which I
>> wrote because we needed to finish 1.3 and get it out the door,
>> instead of writing it because I needed it for one of my own
>> websites.
>
>> So if somebody who actually creates multi-lingual websites wants
>> to take a crack at fixing this problem properly, that would be
>> appreciated.
>
>> Bryan
>
>
- --
Ignacio Huerta Arteche
http://www.ihuerta.net
Tel�fono: 0034 645 70 77 35
Email realizado con software libre
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
Tel�fono: 0034 645 70 77 35
Email realizado con software libre
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk9FPj4ACgkQBPlUJ6RHaORIDgCdGIk7h/zxyVBJ6MGEVxt357a1
CxcAn1DYP0n2VRctcuAryxXD8ws7etTM
=+tMc
-----END PGP SIGNATURE-----
Tel�fono: 0034 645 70 77 35
Email realizado con software libre
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk9FPj4ACgkQBPlUJ6RHaORIDgCdGIk7h/zxyVBJ6MGEVxt357a1
CxcAn1DYP0n2VRctcuAryxXD8ws7etTM
=+tMc
-----END PGP SIGNATURE-----
Tel�fono: 0034 645 70 77 35
Email realizado con software libre
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk9FPj4ACgkQBPlUJ6RHaORIDgCdGIk7h/zxyVBJ6MGEVxt357a1
CxcAn1DYP0n2VRctcuAryxXD8ws7etTM
=+tMc
-----END PGP SIGNATURE-----
Tel�fono: 0034 645 70 77 35
Email realizado con software libre
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk9FPj4ACgkQBPlUJ6RHaORIDgCdGIk7h/zxyVBJ6MGEVxt357a1
CxcAn1DYP0n2VRctcuAryxXD8ws7etTM
=+tMc
-----END PGP SIGNATURE-----
Tel�fono: 0034 645 70 77 35
Email realizado con software libre
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/