如何为文档添加翻译

How to add translation for document

我有一个名为 'documents' 的 table,它有附件(通过回形针 gem),我想为该附件添加翻译(通过 globalize gem)在 Activeadmin 中使用。 因此,一旦我在活动管理员中打开文档页面,我想添加两个或多个文档的翻译,但对于相同的模型(相同的模型 ID,但只有语言环境发生变化)。

文档模型的模式创建 table DB table 是:

create_table "documents", force: :cascade do |t|
    t.datetime "created_at",       null: false
    t.datetime "updated_at",       null: false
    t.string   "doc_file_name"
    t.string   "doc_content_type"
    t.integer  "doc_file_size"
    t.datetime "doc_updated_at"
    t.integer  "model_id"
  end

并且数据库是 postgres。

最后,我解决了这个问题,方法是从文档 table 中删除附件 'doc',然后使用 globalize gem [=12= 为文档创建翻译 table ] 并添加:

has_many :docs
 class Translation
    belongs_to :document
    has_attached_file :doc, MODEL_DOCUMENTS_STORAGE_OPTIONS
    validates_attachment_content_type :doc, content_type: ['application/pdf']
  end

到文档模型,然后通过活动管理表单最终访问它(创建/更新):

form :html => { :enctype => 'multipart/form-data' } do |f|
    f.inputs 'Details' do
      f.translated_inputs 'ignored title', switch_locale: false do |t|
        t.input :doc, :as => :file
      end
    end
    actions
  end