Forum: Rails I18n Rails initialization, productin mode and babilu

C6fff15a9ae1f3e0a9d78254ff49c278?d=identicon&s=25 Piercus (Guest)
on 2011-02-25 16:30
(Received via mailing list)
Hi everyone.

I use rails 3.0.4, and Babilu a plugin to use rails-i18n in javascript
code (see
http://tore.darell.no/posts/introducing_babilu_rai...)

Babilu generates a javascript file that contains all the translations
i can just call
Babilu.generate
to generate this file from i18n rails translations

The thing is, it works very well on developpement mode, because Babilu
generate the locales.js file at each request.

On production mode, babilu just generate his locales.js file at the
initialisation of the plugin.
But, since rails3, it seems to be broken : now the Babilu script can
just mirror  the native translations, but not the translations i added
myself.

In rails 2.3.8 it was working with a I18n.reload! to force
translations loading, but it doesn't seems to work now. (see
https://github.com/lou/babilu/commit/71aef7470cdab...
)

I can figure out when does my "custom" translations (that i put in
config/locales/en.yml) are loaded in i18n, and where can i put an
initializer script, at the start of the production server, to have
working i18n translations.

I tried to put code in config/initializer, in application.rb, it
doesn't work. I found nothing on rails guides.

I've got no error to show you, because it's just translation missing:
en.controller.blabla in my locales.js file

If anyone can help me it would be very nice (it will help me to not
rebuild static files at each request)
you can find my babilu fork at https://github.com/piercus/babilu

Thanks a lot

Pierre
Ba933e99502096b5ca23f75910128cff?d=identicon&s=25 Ingmar Stieger (ingmar_s)
on 2011-03-03 21:36
Pierre,

until babilu is updated to work with Rails3, this following workaround
works fine for me.

In application.rb, add this inside the Application class:

   config.after_initialize do
      Babilu.generate
    end

This generates locales.js just after Rails has done initializing.

Ingmar
C6fff15a9ae1f3e0a9d78254ff49c278?d=identicon&s=25 Pierre Colle (Guest)
on 2011-03-11 13:58
(Received via mailing list)
Ingmar,

That's exactly what i was searching for.

Thanks
Bcff5e628c77368016144538601faee3?d=identicon&s=25 dukha (Guest)
on 2011-04-06 09:31
(Received via mailing list)
Hi
At first glance Babilu seemed to be exactly what I was looking for: no
need to have extra translation logic for Javascript : just use rails.

However it is unclear what exactly it does. I see that it generates a
file called locales.js, in theory containing what is in your
translation files in rails, however I see a lot of extraneous stuff in
that file, like a list of countries apparently from factory_girl.  How
to stop it doing this?

Does babilu load all translations whenever you call generate ? When
does it use the default (as in default locale in locales.js)? I see
that there is a fork to etagwerker-babilu which purports to optimise
the creation of the file. But it doesn't say how. It is early days in
the project but will end up with a lot of big translation files in
many languages.

It would be better to have babilu just load 1 translation file per
language for the javascript or only  translation files when a new
language is selected by the user. Are there any options for such
things in babilu?  Is there another option for i18n in javascript in
combo with rails?

Regards

dukha
This topic is locked and can not be replied to.