Translations using enum_string

69 views
Skip to first unread message

tjg

unread,
Aug 20, 2010, 1:54:27 PM8/20/10
to Hobo Users
Hi again,

Just back from a summer of avoiding this particular problem, but am
still looking for a nudge in the right direction. I could no longer
bump my original posting, so I am copying the text here again. Any
pointers greatly appreciated!

I've been struggling a little get an enum_string to pick up
translation keys. Having consulted these refs:

http://cookbook.hobocentral.net/manual/hobofields/rich_types
and
http://guides.rubyonrails.org/i18n.html

I am left puzzled. I cannot get a Hobo-generated SELECT (based on an
enum_string) to pick up defined keys. It continues to simply titleize
the enum_string constants.

1. What's the correct file to put the keys in? I'm putting keys in the
config/locales/en.yml file, but I see references to "rails.en.yml",
and "app.en.yml", so which one to use?

2. From the cookbook ref, it suggests a particular syntax that will
cause enum_string to use the translated values, but none of my myriad
variations seems to work.

I have the following enum_string in my Document class:

ProvTerr = HoboFields::EnumString.for(:ab, :bc, :mb)

I have the following in my en.yml class, with two spaces for each
indent:

documents:
ProvTerr:
ab: "Alberta"
bc: "British Columbia"
mb: "Manitoba"

Can anyone see what's not correct?

Many thanks,
Tim

Spiralis

unread,
Aug 24, 2010, 12:48:44 PM8/24/10
to Hobo Users
Hi Tim,

I don't think I have ever had the need to translate an enum in my apps
yet. This could be a case where the translation engine hasn't yet been
added to the chain when using enums, although I sincerely thought it
was.

Maybe some of the core hobo-people can enlighten us on how and where
this piece of magic takes place?

~Ronny

On Aug 20, 7:54 pm, tjg <enwoodt...@gmail.com> wrote:
> Hi again,
>
> Just back from a summer of avoiding this particular problem, but am
> still looking for a nudge in the right direction. I could no longer
> bump my original posting, so I am copying the text here again. Any
> pointers greatly appreciated!
>
> I've been struggling a little get an enum_string to pick up
> translation keys. Having consulted these refs:
>
> http://cookbook.hobocentral.net/manual/hobofields/rich_types
> andhttp://guides.rubyonrails.org/i18n.html

tjg

unread,
Aug 24, 2010, 10:52:08 PM8/24/10
to Hobo Users
Thanks, Ronny - an interesting observation that hadn't crossed my
mind. Yes, I'd love to hear what Tom and Owen might have to say on
this...

Tim

tjg

unread,
Sep 21, 2010, 11:14:24 AM9/21/10
to Hobo Users
Tom or Owen,

Any chance you could comment on whether enum translations are in the
translation chain in Hobo? I'm not familiar enough with Hobo, yet, to
be rooting around in dark places.

Thanks,
Tim

Matt Jones

unread,
Sep 22, 2010, 10:32:01 PM9/22/10
to hobo...@googlegroups.com
I vaguely recall a mad dash to squeeze it in when we were pushing 1.0 out the door; checking the history of the v1.0.0 tag on Github might shed some light.

--Matt Jones

> --
> 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.
>

Matt Jones

unread,
Sep 24, 2010, 3:22:52 PM9/24/10
to hobo...@googlegroups.com
Some poking around in hobofields points to this line in enum_string.rb:

I18n.t("#{name.tableize}.#{value}", :default => value)

Which then gets used by the default EnumString input tag in Rapid.

You'll also need to set the name of the class:

ProvTerr.set_name('ProvTerr')

(this should probably be handled better, maybe by defaulting the name method to return self.class.name perhaps?)

--Matt Jones

On Sep 21, 2010, at 11:14 AM, tjg wrote:

tjg

unread,
Sep 25, 2010, 12:09:27 PM9/25/10
to Hobo Users
Thanks, Matt. I'll give this a shot and report back for future
reference.

Tim

erbecke

unread,
Oct 7, 2010, 2:23:05 PM10/7/10
to Hobo Users
Hello everybody.

I have the same problem... translation doesn't work in my
enum_strings.

I tried to do everything I could following the HoboFields manual, but
I didn't get any results.Someone did it work?

Best regards,
eddie


On 20 ago, 15:54, tjg <enwoodt...@gmail.com> wrote:
> Hi again,
>
> Just back from a summer of avoiding this particular problem, but am
> still looking for a nudge in the right direction. I could no longer
> bump my original posting, so I am copying the text here again. Any
> pointers greatly appreciated!
>
> I've been struggling a little get anenum_stringto pick uptranslationkeys. Having consulted these refs:
>
> http://cookbook.hobocentral.net/manual/hobofields/rich_types
> andhttp://guides.rubyonrails.org/i18n.html
>
> I am left puzzled. I cannot get a Hobo-generated SELECT (based on anenum_string) to pick up defined keys. It continues to simply titleize
> theenum_stringconstants.
>
> 1. What's the correct file to put the keys in? I'm putting keys in the
> config/locales/en.yml file, but I see references to "rails.en.yml",
> and "app.en.yml", so which one to use?
>
> 2. From the cookbook ref, it suggests a particular syntax that will
> causeenum_stringto use the translated values, but none of my myriad
> variations seems to work.
>
> I  have the followingenum_stringin my Document class:

Bryan Larsen

unread,
Mar 27, 2011, 1:29:23 PM3/27/11
to hobo...@googlegroups.com
I helped Tim figure it out. Here's a working example:

class Document < ActiveRecord::Base
hobo_model
Region = HoboFields::Types::EnumString.for(:ab, :bc, :mb, :nb, :nl,
:ns, :nt, :nu, :on, :pe, :qc, :sk, :yt, :other)
...

(config/locales/app.en.yml)
en:
document/regions:


ab: "Alberta"
bc: "British Columbia"

...

This is for Hobo 1.3. The corresponding manual page is available, you
just need to know where it is, (the cookbook displays the stable manual).

https://github.com/tablatom/hobo/blob/rails3/hobo_fields/test/rich_types.rdoctest

We can set the name explicitly to avoid the slash:

class Document < ActiveRecord::Base
hobo_model
Region = HoboFields::Types::EnumString.for(:ab, :bc, :mb, :nb, :nl,
:ns, :nt, :nu, :on, :pe, :qc, :sk, :yt, :other, :name => "Region")
...

en:
regions:


ab: "Alberta"
bc: "British Columbia"

...

cheers,
Bryan

Owen Dall

unread,
Mar 27, 2011, 2:11:47 PM3/27/11
to hobo...@googlegroups.com
Thanks for tracking that down, Bryan.

--
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.




--


- Owen

Owen Dall, Chief Systems Architect
Barquin International

Tim Griffin

unread,
Mar 28, 2011, 12:12:45 PM3/28/11
to Hobo Users
Yes, my sincere thanks for Bryan for stopping me from going in
circles.

For everyone else's benefit, here are the critical observations that
had escaped me:

1. If you don't explicitly name the enum_string with the "name: =>"
parameter or with a call to set_name, the main key in your locale file
must include the model name in which the enum_string is defined, as
well as the tableized name of the enum_string (lower-case/
pluralized).

***BUT*** the enum_string's main key can ONLY use the "/" notation.

So, if you do this:

class Document < ActiveRecord::Base
hobo_model
Region = HoboFields::Types::EnumString.for(:ab, :bc)

you must use this notation:

en:
document/regions:
ab: "Alberta"
bc: "British Columbia"

and ***NOT*** this notation:

en:
document:
regions:
ab: "Alberta"
bc: "British Columbia"


2. If you DO explicitly name the enum_string with the "name: =>"
parameter or with a call to set_name, the keys in your locale file
must not include the model name.

If you do this:

class Document < ActiveRecord::Base
hobo_model
Region = HoboFields::Types::EnumString.for(:ab, :bc, :name =>
"Region")

Your locale file's enum_string key must match the tableized version of
the name you assigned to the enum_string (note the lower-case first
letter, and the pluralization).

en:
regions:
ab: "Alberta"
bc: "British Columbia"


Tim



On Mar 27, 2:11 pm, Owen Dall <od...@barquin.com> wrote:
> Thanks for tracking that down, Bryan.
>
> On Sun, Mar 27, 2011 at 1:29 PM, Bryan Larsen <bryan.lar...@gmail.com>wrote:
>
>
>
> > I helped Tim figure it out.   Here's a working example:
>
> > class Document < ActiveRecord::Base
> >  hobo_model
> >  Region = HoboFields::Types::EnumString.for(:ab, :bc, :mb, :nb, :nl, :ns,
> > :nt, :nu, :on, :pe, :qc, :sk, :yt, :other)
> > ...
>
> > (config/locales/app.en.yml)
> > en:
> >  document/regions:
>
> >    ab: "Alberta"
> >    bc: "British Columbia"
>
> > ...
>
> > This is for Hobo 1.3.   The corresponding manual page is available, you
> > just need to know where it is, (the cookbook displays the stable manual).
>
> >https://github.com/tablatom/hobo/blob/rails3/hobo_fields/test/rich_ty...

Owen Dall

unread,
Mar 28, 2011, 1:24:27 PM3/28/11
to hobo...@googlegroups.com, Tim Griffin
Tricky...

erbecke

unread,
Mar 28, 2011, 4:08:33 PM3/28/11
to Hobo Users


Thank you Bryan ;)


On Mar 27, 2:29 pm, Bryan Larsen <bryan.lar...@gmail.com> wrote:
> I helped Tim figure it out.   Here's a working example:
>
> class Document < ActiveRecord::Base
>    hobo_model
>    Region = HoboFields::Types::EnumString.for(:ab, :bc, :mb, :nb, :nl,
> :ns, :nt, :nu, :on, :pe, :qc, :sk, :yt, :other)
> ...    
>
> (config/locales/app.en.yml)
> en:
>    document/regions:
>      ab: "Alberta"
>      bc: "British Columbia"
>
> ...
>
> This is for Hobo 1.3.   The corresponding manual page is available, you
> just need to know where it is, (the cookbook displays the stable manual).
>
> https://github.com/tablatom/hobo/blob/rails3/hobo_fields/test/rich_ty...
Reply all
Reply to author
Forward
0 new messages