accessing I18n translations yamls

73 views
Skip to first unread message

Joaquin Rivera Padron

unread,
Jan 22, 2010, 7:17:49 AM1/22/10
to rails...@googlegroups.com
hello there,
I'm trying to hack a little helper project of mine and I might be interest in accessing the yamls loaded by I18n (I mean I could load them by myself, but accessing them through I18n is more backend agnostic).

The reason is I want to be able to invert the yaml in such a way that the values of the translations link to the "full_i18n_keys" that make them accessible. An example:

Let's say I have the locales:
{"en"=>{"hello"=>{"world"=>"Hello world"}}}
{"es"=>{"hello"=>{"world"=>"hola mundo"}}}

I want to invert them like this:
{"en"=>{"Hello world" => "hello.world"}}
{"es"=>{"Hola mundo"=>"hello.world"}}

I know there could arise problems with repeated texts, and such, but I'll cope with them...

so back to my question: is there a way I can access the yamls or is there anyone who have then already inverted like that? If not, how would you recommend I go into it?

TIA and greetings,
joaquin

--
www.least-significant-bit.com

Krzysztof Knapik

unread,
Jan 22, 2010, 8:41:00 AM1/22/10
to rails...@googlegroups.com
Hi,

I did similar thing, you're talking about. I extend the backend to
support flattened YML files, so all my translations files look like:

en:
activerecord.errors.messages.accepted: "must be accepted"
activerecord.errors.messages.blank: "can't be blank"

The reason of doing it was complications I met with working on huge
piece of data in nested yml files. Having few thousands keys in few
translations files, was making me furious when I needed rename
translation keys, move them to another namespace etc. and had to
scroll a lot, looking and wondering what is namespace of the key.
Also, resolving merge conflicts, checking for missing translations in
other locale files are much easier, when you have and see full key.

Having the Fast backend in latest i18n, implementing it was quite
simple and it's in my fork of i18n:
http://github.com/knapo/i18n/blob/master/lib/i18n/backend/zuper_fast.rb

Btw, as Fast backend uses flattened hashes, I believe that when you
invert I18n.backend.flattened_translations hash you'll get what you
need.

Regards,
Krzysztof Knapik

2010/1/22 Joaquin Rivera Padron <joah...@gmail.com>:

> --
> You received this message because you are subscribed to the Google Groups
> "rails-i18n" group.
> To post to this group, send email to rails...@googlegroups.com.
> To unsubscribe from this group, send email to
> rails-i18n+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/rails-i18n?hl=en.
>

Joaquin Rivera Padron

unread,
Jan 22, 2010, 10:01:26 AM1/22/10
to rails...@googlegroups.com
hei knapo thanks, I'll check your fork and see what I can come up with :-)

greeetings,
joaquin

2010/1/22 Krzysztof Knapik <krzyszto...@gmail.com>
Reply all
Reply to author
Forward
0 new messages