0
私はRails 3.1でアプリケーションを構築しています。フロントエンドには5つの言語があり、バックエンドには英語のみが用意されています。"英語のみ"のバックエンドを持つ多言語サイト
管理者は、globalize3を使用してバックエンドにオブジェクトを作成し、属性の変換を指定できます。ここでは、コントローラの一部製品を作成する:
class Admin::ProductsController < ApplicationController
before_filter :set_language
after_filter :set_back_to_default_language
def new
@product = Product.new
end
def create
@product = Product.create(params[:product])
if @product.errors.empty?
redirect_to admin_product_path(@product)
else
render :action => :new
end
end
private
def set_language
I18n.locale = :it
end
def set_back_to_default_language
I18n.locale = :en
end
end
これは、イタリア語の属性を設定して製品を作成します。しかし、属性が必要な場合の出力:
<%= @product.errors[:title] %>
が
translation missing: it.activerecord.errors.models.product.attributes.title.blank
になりますが、デフォルトの言語で常に検証を持つ右の言語で属性を設定する方法を知っていますか?私はI18n.default_locale = :en
を使用することはできません。なぜなら、フロントエンドには私は他のフォームがあり、バリデーション文字列はローカライズされるべきだからです。