Forum: Rails I18n accessing I18n translations yamls

8a2de74362a8ee5f9c5e86b1ba0b1640?d=identicon&s=25 Joaquin Rivera padron (joahking)
on 2010-01-22 14:18
(Received via mailing list)
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
390e714e320bd505fb5e9f762870ba5e?d=identicon&s=25 Krzysztof Knapik (Guest)
on 2010-01-22 14:41
(Received via mailing list)
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/...

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 <joahking@gmail.com>:
8a2de74362a8ee5f9c5e86b1ba0b1640?d=identicon&s=25 Joaquin Rivera padron (joahking)
on 2010-01-22 16:02
(Received via mailing list)
hei knapo thanks, I'll check your fork and see what I can come up with
:-)

greeetings,
joaquin

2010/1/22 Krzysztof Knapik <krzysztof.knapik@gmail.com>

> piece of data in nested yml files. Having few thousands keys in few
> Btw, as Fast backend uses flattened hashes, I believe that when you
> > in accessing the yamls loaded by I18n (I mean I could load them by
> >
> >
> > To unsubscribe from this group, send email to
> To unsubscribe from this group, send email to
> rails-i18n+unsubscribe@googlegroups.com<rails-i18n%2Bunsubscribe@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/rails-i18n?hl=en.
>
>


--
www.least-significant-bit.com
This topic is locked and can not be replied to.