In the last post, we saw how we can translate a variety of dynamic contents that we may have in our Rails applications using globalize gem. There is another complementary gem to globalize that can be used to do these translations inside Rails Admin, which make it a lot easier and simpler to insert these translations inside RailsAdmin’s user friendly interface.
It is called rails_admin_globalize_field and is very easy to install and configure.
You should initially have globalize gem already installed and configured; rails_admin_globalize_field uses it to its job.
Once we are done with the installation and configuration of globalize, we can install this new gem:
After that, you can include translation models at your rails_admin.rb config file with the following:
config.included_models << ['Model','Model::Translation']
You should also add the following at the model that you are trying to do the translation for:
class Model < ActiveRecord::Base translates :title, :desc accepts_nested_attributes_for :translations, allow_destroy: true end
Add configuration to your translated model and associated translation model. :locale field is always required.
config.model 'Post' do configure :translations, :globalize_tabs edit do field :translations do label "Translations" end end end config.model 'Model::Translation' do visible false configure :locale, :hidden do help '' end include_fields :locale, :title, :desc end
Do not forget to include the translations field in your Edit page, because you may not be able to see it being displayed in your RailsAdmin.
You can see a preview of how it looks like in the image displayed above.
This is an open source project, that you can learn and benefit from, and also contribute to make it better. At the time of this writing, this gem has only 29 stars in its Github page, but I believe it deserves a lot more, because of its applicability.