Catfish
Catfish

Reputation: 19294

rails t function showing i18n

I'm working on my first refinerycms project and there is this line in the footer:

<%= t('.copyright', :year => Time.now.year, :site_name => Refinery::Core.site_name) %>

It's displaying this on my site:

i18n: Copyright

Where does the i18n come from and is the t function needed?

EDIT:

My /config/locales/en.yml contains the code below. Do i need to add something to this or would it best just to remove the t() tag?

en:
  hello: "Hello world"

Upvotes: 5

Views: 5449

Answers (3)

Dwayne Crooks
Dwayne Crooks

Reputation: 2857

The t method is an alias for the translate method. Both of them can be found in ActionView::Helpers::TranslationHelper.

Assume options = { :year => Time.now.year, :site_name => Refinery::Core.site_name }.

Since the key being passed starts with a period, the call to t('.copyright', options) which is in the refinery/_footer.html.erb view will actually be calling I18n.translate('refinery.footer.copyright', options).

Now, the default English translation for the key refinery.footer.copyright can be found here. It is "Copyright © %{year} %{site_name}". If you want to override that value, then I think the best way to do that will be to set that key in your config/locales/en.yml file.

en:
  refinery:
    footer:
      copyright: "My custom copyright text"

Upvotes: 1

ABrukish
ABrukish

Reputation: 1452

About your second question - t('.copyright') expecting for proper key under your folders tree structure ( because it has . at the beggining ). For example, if you have a footer under your shared folder ( full path will be app/views/shared/_footer.erb ), then you should have next structure for your YML:

en:
  shared:
    footer:
      copyright: "All rights reserved. (c) %{site_name} at %{year}"

%{site_name} and %{year} are interpolation's placeholders for your values at:

<%= t('.copyright', :year => Time.now.year, :site_name => Refinery::Core.site_name) %>

Upvotes: 7

Ismael
Ismael

Reputation: 16730

i18n it's the internationalization library that comes with Rails, wich helps for having translation for diferent locations in your Rails app.

t() it's just the call for translate, I think it's an alias actually.

You should have a yaml file in your locales folder where there is a copyright, wich needs a year and a site_name.

I guess you changed the location so there is no translation, since refineryCms should be english only.

Upvotes: 4

Related Questions