Project

title

0.09
Low commit activity in last 3 years
A long-lived project that still receives updates
Abuses I18n to set HTML <title>s
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0

Runtime

 Project Readme

Title

Translations for <title>s!

Usage

Add to your translations:

en:
  titles:
    # titles.application defaults to the sigficant portion of
    # AppName::Application, which would be:
    application: AppName
    dashboards:
      show: Dashboard
    users:
      show: '%{user}'
      new: Registration

And to your HTML:

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

And to your User model:

def to_s
  name
end

You can pass additional values to the #title helper, which can be referenced in your translations:

<title><%= title(user_name: current_user.name) %></title>
en:
  titles:
    application: '%{user_name} - AppName'

Acknowledgement

Though the idea of translating titles was arrived at seperately, Brandon Keepers wrote Abusing Rails I18N to Set Page Titles which outlines an extremely similar approach, and from whence came the idea of using the view context to get local assigns to be used in interpolation.