2

There is a yaml file in a Rails application which named 'notices.yml'.

notices:
  content: "Notice 1."

Now want to set the notice content to dynamatic as:

  content: "Notice 1. Good"

So should parse parameter to it in some logic.

I have thought about Rails' I18n. If use something like I18n.t("notices.content", "Good") may realize it. The yaml should be:

notices:
  content: "Notice 1. %{data}"

But how to make the method? I am using a way to read yaml file like:

# config/application.rb
config.notices = YAML.load_file("#{Rails.root}/config/notices.yml")
# Some controller
content = Rails.configuration.notices['notices']['content']

It seems difficult to set parameter like that way.

I checked the I18n's translate method:

https://github.com/ruby-i18n/i18n/blob/master/lib/i18n.rb#L179

It use **options to set data. I have no idea to make a simple way to realize this case.

Alok Swain
  • 6,409
  • 5
  • 36
  • 57
02040402
  • 729
  • 3
  • 6
  • 21

0 Answers0