# Rails initialization, productin mode and babilu

**URL:** <https://www.ruby-forum.com/t/rails-initialization-productin-mode-and-babilu/203713>\
**Category:** Rails I18n\
**Created:** [February 25, 2011, 4:30pm UTC](https://www.ruby-forum.com/t/rails-initialization-productin-mode-and-babilu/203713 "2011-02-25T16:30:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [February 25, 2011, 4:30pm UTC](https://www.ruby-forum.com/t/rails-initialization-productin-mode-and-babilu/203713/1 "2011-02-25T16:30:12Z")

</div>

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\_rails\_i18n\_for\_your\_javascript](http://tore.darell.no/posts/introducing_babilu_rails_i18n_for_your_javascript))

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/71aef7470cdabf7888affc538ea806caddce7c1f](https://github.com/lou/babilu/commit/71aef7470cdabf7888affc538ea806caddce7c1f)  
)

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 [GitHub - piercus/babilu: JavaScript Rails internationalization](https://github.com/piercus/babilu)

Thanks a lot

Pierre

---

<div class="post-metadata">

**Author:** ![Piercus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b9bd4f/32.png) [@Piercus](https://www.ruby-forum.com/u/Piercus)\
**Post date:** [March 3, 2011, 9:36pm UTC](https://www.ruby-forum.com/t/rails-initialization-productin-mode-and-babilu/203713/2 "2011-03-03T21:36:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Piercus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b9bd4f/32.png) [@Piercus](https://www.ruby-forum.com/u/Piercus)\
**Post date:** [March 11, 2011, 1:58pm UTC](https://www.ruby-forum.com/t/rails-initialization-productin-mode-and-babilu/203713/3 "2011-03-11T13:58:03Z")

</div>

Ingmar,

That’s exactly what i was searching for.

Thanks

---

<div class="post-metadata">

**Author:** ![Piercus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b9bd4f/32.png) [@Piercus](https://www.ruby-forum.com/u/Piercus)\
**Post date:** [April 6, 2011, 9:31am UTC](https://www.ruby-forum.com/t/rails-initialization-productin-mode-and-babilu/203713/4 "2011-04-06T09:31:27Z")

</div>

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
