English 中文(简体)
如何将翻译成一个阵列?
原标题:What is the way to add translation to an array?

Sorry if this is really easy. But I have tried many ways to add I18n and does not seem to work.

这一观点

 =  @event.categories.map(&:name).to_sentence

当地情况就是如此。

 #Categories
   categories:
   gastronomy: Gastronomy
   family: Family
   sports: Sports
   scene: Scene
   traditional: Tradition
   music: Music
   party: Party

我设法使翻译工作以形式进行,但并非在这里。 任何想法为什么?

最佳回答

<><>>

假设档案结构如下:

categories:
  gastronomy: Gastronomy
  family: Family
  sports: Sports
  scene: Scene
  traditional: Tradition
  music: Music
  party: Party

现在你可以做以下工作:

@event.categories.map{|n| I18n.t("categories.#{n}"}.to_sentence

<><>>>

更有甚者,你可以改变你的<条码>。 回归当地名称的模式:

class Category < ActiveRecord::Base

  def name
    key = read_attribute(:name)
    return key if key.blank? # return immediately if nil
    # use the key as value if the localization value is missing
    I18.n("categories.#{key}", :default => key.humanize)
  end
end

现在,<代码> 方法回归地方价值:

cat.name # localized name

你最初的发言也将奏效。

@event.categories.map(&:name).to_sentence

<><>ption 3>

https://github.com/svenfuchs/globalize3"rel=“nofollow” plcast

问题回答

暂无回答




相关问题
How does gettext handle dynamic content?

In php (or maybe gettext in general), what does gettext do when it sees a variable to dynamic content? I have 2 cases in mind. 1) Let s say I have <?=$user1?> poked John <?=$user2?>. ...

Explain the Need for Mutexes in Locales, Please

Reading the question Why doesn’t C++ STL support atoi(const string& ) like functions?, I encountered a comment which warned that GCC (at least) has a bug that can slow down multi-threaded ...

How does Vistalizer work

How does Vistalizer manage to override the language limit in Windows Vista Home edition. Which api s does it use to allow installation of Multiple language packages.

Localized exceptions (within a Struts2 app)

I am developing a Struts 2 application with support for multiple languages. If one of the domain objects needs to throw an exception, how can it do so in such a way that the error message is no ...

Rails Globalize plugin help

Has anyone gotten the Globalize plugin to work Rails 2.3.2 or later? If so, could you direct me to some useful info?

热门标签