1

私がこれらの翻訳を持っているとしましょう:

en:
  article:
    name: "article"

次のようなことは可能ですか:

test1: "We have zero #article.name.pluralize"
test2: "There is an error in your #article.name"
test3: "Title for this page is: My #article.name.pluralize.capitalize"

私は 1 と 3 (つまり、変数に対して追加の関数を実行すること) にあまりこだわっていませんが、test2 は非常に役立ちます。

これはまた疑問を投げかけます: これは翻訳ファイルを構造化する良い方法ですか? 他の言語はまったく異なる方法で構造化できるため、これを尋ねます。翻訳ファイルを乾燥させる方法を考えているところです。

4

1 に答える 1

1

次のような翻訳を定義できます。

test1: "We have zero %{things}"

そして、コードのどこかで次のように使用できます。

I18n.t(:test1, :scope => [:flashes], :things => t(:name, :scope => [:article] ))

または、別の表記法を使用して:

I18n.t("flashes.test1", :things => I18n.t("article.name"))
于 2012-07-03T15:28:56.657 に答える