Translation
Overview
We can convert certain keys to the language the application needs.
Installation
rails generate 'i18n:active_record:install'
Usage
-
Create a migration to add a column for locale for the user.
class AddLocaleToUser < ActiveRecord::Migration[7.2]
def change
add_column :users, :locale, :string, default: 'en'
end
end
-
Add the following line to the
config/initializers/i18n_active_record.rb
file.
require 'i18n/backend/active_record'
I18n.backend = I18n::Backend::ActiveRecord.new
I18n::Backend::ActiveRecord.configure do |config|
config.cache_translations = true # defaults to false
# config.cleanup_with_destroy = true # defaults to false
config.scope = 'cm_admin' # defaults to nil, won't be used
end
-
We can create a translation by going to
/cm_admin/translations
.“‘ruby
-
key - The text that needs to be converted. Eg: Edit
-
value - The value that needs to be applied. Eg: يحرر
-
locale - The language in which the text needs to be converted. Eg: ar
“‘
Important Notes
-
Success messages are not converted yet.