Add i18n to filters options #1304

wants to merge 1 commit into


None yet
4 participants

vala commented Sep 4, 2012


I was missing the ability to cleanly translate the filter options in my application.
What I call filter options is the HTML options hardcoded in the ra.filter-box.js that are proposed depending on the field type that you're trying to filter.

This pull request is made so it can be criticized and solutions can be given because, while the hack works, it's quite ugly in some places.

The things to note that I'd like to discuss :

  • I had to rename ra.filter-box.js to ra.filter-box.js.erb so I can dynamically insert the I18n names. I could have loaded them through Ajax, or even worst made a JS translation file, but I thought it was a cleaner way.
  • I coded an erb inlined helper inside the ra.filter-box.js.erb because, as we don't have access to ActionView helpers in this file, I didn't want to make every call to the translate helper method too long so it keeps readable.
  • Should I test this kind of code ? I suppose it can be done, but if it can be I'll be glad someone gives me a clue on how to proceed here.

The patch lets you translate those filter options directly in the locale file

This pull request passes (merged 51ba2b6 into 936337d).


bbenezech commented Sep 7, 2012

Nice idea, but it won't work nicely with the asset pipeline.

You'll lose the ability to switch local :/

Maybe we should have a look at Gon for a better refactoring of what has already be done for JS i18n

vala commented Sep 7, 2012

You're right, after some tries I had to edit the ra.filter-box.js.erb in order to make the locale switch on assets compilation.

Gon seems quite clean and simple to implement. We could always push the whole rails_admin translations into some gon.rails_admin_translations variable so every plugin could take advantage of it while ensuring it's always available.

I'll submit a new patch next to this one.

I'll try that and


mshibuya commented Jun 15, 2013

Closing this for now.
Another pull request is welcomed :)

@mshibuya mshibuya closed this Jun 15, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment