# \[ANN\] a helper to DRY-up internationalized \<title\>'s (http://github.com/lwe/page\_title\_helper)

**URL:** <https://www.ruby-forum.com/t/ann-a-helper-to-dry-up-internationalized-title-s-http-github-com-lwe-page-title-helper/171732>\
**Category:** Rails\
**Created:** [July 8, 2009, 10:42am UTC](https://www.ruby-forum.com/t/ann-a-helper-to-dry-up-internationalized-title-s-http-github-com-lwe-page-title-helper/171732 "2009-07-08T10:42:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lwe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e480ec/32.png) [@lwe](https://www.ruby-forum.com/u/lwe)\
**Post date:** [July 8, 2009, 10:42am UTC](https://www.ruby-forum.com/t/ann-a-helper-to-dry-up-internationalized-title-s-http-github-com-lwe-page-title-helper/171732/1 "2009-07-08T10:42:08Z")

</div>

Hey there

Code and (longer) quick-start guide can also be found here:

> **[GitHub - lwe/page\_title\_helper: Simple, internationalized and DRY page titles...](https://github.com/lwe/page_title_helper)**
>
> Simple, internationalized and DRY page titles and headings for Rails. - GitHub - lwe/page\_title\_helper: Simple, internationalized and DRY page titles and headings for Rails.

To customize page titles there are many different methods, among the  
most popular (and best looking) is certainly:  
[#30 Pretty Page Title - RailsCasts](http://railscasts.com/episodes/30-pretty-page-title), even more there  
are numerous plugins on github  
[http://github.com/search?type=Repositories&language=rb&q=title](http://github.com/search?type=Repositories&language=rb&q=title),  
so why was there the need to create yet another one?

Because we required a method to have internationalized titles and this  
soon became very cumbersome und cludgy 🙂 But well, a few code  
examples say more than a thousand words:

# in the layout

…

\<%= h page\_title %\> ...
# then in the translations:

en:  
contacts:  
index:  
title: “All contacts”

Thats it. So if /contacts/ is called and then the view contacts/  
index.html.erb is rendered, the title “All contacts” is used. To  
customize the title e.g. to display the contacts name in contacts/  
show.html.erb do:

# in contacts/show.html.erb

# \<%= h page\_title { @contact.name } %\>

It also features some options to change the format, add custom parts  
to the output etc. It can be installed as a gem, plugin or git  
submodule → [GitHub - lwe/page\_title\_helper: Simple, internationalized and DRY page titles and headings for Rails.](http://github.com/lwe/page_title_helper) If you find any  
issues or problems, I’m sure there are 🙂 just drop me a line or  
create a ticket on github.

Note: this plugin has only been tested and used on Rails 2.3.x.

Grüsse, Lukas  
PS: For those interested: internally the method from railscasts is  
used to set custom titles.  
PPS: More examples and a description of all options can be found on  
github  
PPPS: It’s small LOC = 60, has tests (but Code to Test Ratio is only  
1:1.4) and 100% code coverage.  
PPPPS: Finally some bad news: it relies on some Rails internals to  
e.g. obtain the first renderer etc., so if those change the plugin  
might break… so if anyone knows better alternatives (check  
read\_first\_render\_path and read\_page\_title\_content\_block methods)…
