Welcome to brand new series of content where we will share short tips and pieces of knowledge.
This time Ruby on Rails!
Recently I was working on separating gettext translations in our project into separate domains. It's very useful in cases when some strings should be translated differently in different contexts. I will explain shortly how to use multiple domains for Gettext translations in your Rails app. Enjoy!
By default, gettext is using single default domain. To have more than one domain we will need to overwrite gettext:setup task using our app configuration. Here are some examples which can show you how you can achieve that:
Nowrails gettext:setup and rails gettext:find should create files called app.pot, frontend.pot and new_design.pot. Every call of domain-based translation method (e.g. d_("new_design", "Some string from new design goes here")) will be translated based on the values in the domain pot file. Voila, problem solved!
TIL, or Today I Learned, is where our developers share the best tech stuff they found every day. You can find smart solutions for some issues, useful advices and anything which will make your developer life easier.