Rails Kitchen

It's a place to write on stuff I learned recently.

Multiple Language Sites in Refinery CMS With I18n

| Comments

Refinery CMS is an Rails-based CMS that supports Rails 3.2 and 4.1. We can make Refinary CMS Multilingual with i18n Translations.
For this add the gem to Gemfile
ruby
1
gem 'refinerycms-i18n'
Run the generator
ruby
1
rails g refinery:i18n
Change the language settings In Refinery’s settings find I18n Translation Frontend Locales (Refinery) and add the ISO country name.
config/initializers/refinery/i18n.rb
ruby
1
2
3
4
5
6
7
8
9
10
11
12
Refinery::I18n.configure do |config|
   config.default_locale = :en

  # config.current_locale = :en

  # config.default_frontend_locale = :en

   config.frontend_locales = [:en,:ar]

   config.locales = {:en=>"English", :ar=>"Arabic"}
   #, :nl=>"Nederlands", :pt=>"Português", :"pt-BR"=>"Português brasileiro", :da=>"Dansk", :nb=>"Norsk Bokmål", :sl=>"Slovenian", :es=>"Español", :it=>"Italiano", :de=>"Deutsch", :lv=>"Latviski", :ru=>"Русский", :sv=>"Svenska", :pl=>"Polski", :"zh-CN"=>"简体中文", :"zh-TW"=>"繁體中文", :el=>"Ελληνικά", :rs=>"Srpski", :cs=>"Česky", :sk=>"Slovenský", :ja=>"日本語", :bg=>"Български", :hu=>"Hungarian", :uk=>"Українська"}
end
That’s it! Visit the Pages tab and you should see flags indicating the page language in the tree.

Edit a page and you’ll see the available languages at the top. Simply select one to add content for that language.

Now we need to add multi language support for our extensions. For this we need to specify this when we create extension with –i18n attribute.
ruby
1
rails g refinery:engine Service title:string description:text icon:image --i18n title description
We can add link to toggle between languages in Frontend web site using following code
1
2
3
4
5
<nav id='locale'>
    <% ::Refinery::I18n.frontend_locales.each do |locale| %>
      <%= link_to_if Globalize.locale.to_s != locale.to_s, locale, {:locale => locale} %>
    <% end %>
</nav>

Comments