0

I know that I can create nested translations in i18n dictionary. e.g.

en:
  bugs:
    index:
      new_label: "File a new bug"
      edit_label: "edit"
      delete_label: "delete"

It works perfect with simple YAML-files. But what will be if I want to use ActiveRecord as backend for i18n?

Smth like this

I18n.backend = I18n::Backend::ActiveRecord.new

I found some migration for this feature

class CreateTranslations < ActiveRecord::Migration
  def self.up
    create_table :translations do |t|
      t.string :locale
      t.string :key
      t.text   :value
      t.text   :interpolations
      t.boolean :is_proc, :default => false

      t.timestamps
    end
  end

  def self.down
    drop_table :translations
  end
end

How can I save nested translations in this case? Without it translation must be like

{ bugs: value, bugs_index: value, bugs_index_new_label: value, ... }

But in my opinion it's not nice solution...

mxgoncharov
  • 475
  • 2
  • 7
  • 15
  • 1
    A yaml is basically a nested hash, a database table is just a plain list. There is not much you can do. What you can try is to use the format Rails uses for scopes, something like: `bugs.index.new_label`, `bugs.index.edit_label`, `bugs.index.delete_label`... – spickermann Nov 17 '14 at 11:27
  • @spickermann thnx. But I don't understand what scopes you are talking about? – mxgoncharov Nov 17 '14 at 12:22
  • http://guides.rubyonrails.org/i18n.html#using-different-backends – max Nov 17 '14 at 12:56
  • @endifix: See 5.1.1 on http://guides.rubyonrails.org/i18n.html#translations-for-active-record-models – spickermann Nov 17 '14 at 20:40

0 Answers0