Store Page Titles in I18n

While the <title> element is one of the only required tags in HTML, it is often overlooked by developers and designers alike until the end of the development process.

Title hopes to bring an end to all that, making it dead simple to add static and dynamic <title>s to each page in your Rails app.

By allowing you to store your pages titles in the already-familiar config/locales/en.yml, Title lowers the barrier to adding page titles. Take a look:

app/views/application.html.erb:

<title><%= title %></title>

config/locales/en.yml:

en:
  titles:
    application: App Name
    homepage:
      index: Homepage
    users:
      new: Sign up
      show: '%{user}'

app/models/user.rb:

class User
  def to_s
    name
  end
end

Title will automatically make translation lookups and will fall back to titles.application. If you don’t bother with setting title translations at all, Title will fall back to a guess of the <title> based on your application’s name.

One of the coolest features is that Title will automatically grab the instance variables from the view and provide them to I18n as interpolation variables. In the code above, users#show’s <title> will be the user’s name.

Please, give title a shot in your new or existing Rails application. I welcome contributions, and if you have any problems just open an issue.

Let me know what you think at @thompson_caleb.