我正在尝试构造动态YAML来返回字符串,我想知道是否有可能用YAML做这样的事情?
en:
occupation: "Studying #{department} at %{university} %{*speciality}"
speciality: &speciality "specialising in %{subject}"
I18n.t(:occupation, :department => "Computer Science",
:university => "Staffordshire University",
:subject => "Ruby")
#=> "Studying Computer Science at Staffordshire University specialising in Ruby"
I18n.t(:occupation, :department => "Computer Science",
:university => "Staffordshire University",
:subject => nil)
#=> "Studying Computer Science at Staffordshire University"
目前,我认为这可能是唯一可行的方式是
subject = "Ruby"
I18n.t(:occupation, :department => "Computer Science",
:university => "Staffordshire University",
:subject => (
I18n.t(:speciality, :subject => subject) if subject
))
#=> "Studying Computer Science at Staffordshire University specialising in Ruby"