Skip to content

Localization feature

Serge Gernyak edited this page Jan 15, 2016 · 2 revisions

Necessity of supporting to provide settings depending on current locale is high. For example, you have in settings your site name, and this site is multilanguage. So you need to provide different site name in different languages and depending on current language proper name is using.

From version v0.0.5 settingify has builtin ability for supporting multilocaled settings. This feature may be either active or not. But be careful! Are localization feature active or not expects proper DB schema for Setting model.

For more detail understanding localization feature work lets consider several real world examples.

Blank project. Site has single locale.

You do not need some additional configuration. Just use provided install generator. Enjoy!

Blank project. Site has several locales.

You need to provide additional options for install generator. For example:

rails g settingify:install --localization --locales=fr,nl

Provided options affects on several parts:

  • Generated Setting model schema: there are will be no value column, but will be columns like value_fr and value_nl;
  • Enables traco provided logic on Setting model.

After that fetched setting's value will be depending on I18n.locale value.

Existed project. Site must be moved to supporting multiple locales.

Just follow next steps:

  1. Go to config/initializers/settingify.rb and add the following lines to the beginning:
Settingify.config do |config|
  config.localization do |localization|
    localization.active            = true
    localization.available_locales = [:locale1, :locale2]
  end
end

# rest of the file
  1. Make migration for removing value column in settingify_settings table and add independent column for each available locales using pattern value_<LOCALE>. It must be done because of traco is works so.