views:

200

answers:

2

Hi there!

I'd like to i18n a text that looks like this:

Already signed up? Log in!

Note that there is a link on the text. On this example it points to google - in reality it will point to my app's log_in_path.

I've found two ways of doing this, but none of them looks "right".

The first way I know involves having this my en.yml:

log_in_message: "Already signed up? <a href='{{url}}'>Log in!</a>"

And in my view:

<p> <%= t('log_in_message', :url => login_path) %> </p>

This works, but having the <a href=...</a> part on the en.yml doesn't look very clean to me.

The other option I know is using localized views - login.en.html.erb, and login.es.html.erb.

This also doesn't feel right since the only different line would be the aforementioned one; the rest of the view (~30 lines) would be repeated for all views. It would not be very DRY.

I guess I could use "localized partials" but that seems too cumberstone; I think I prefer the first option to having so many tiny view files.

So my question is: is there a "proper" way to implement this?

A: 

Why not use the first way, but splitting it up like

log_in_message: Already signed up?
log_in_link_text: Log in!

And then

<p> <%= t('log_in_message') %> <%= link_to t('log_in_link_text'), login_path %> </p>
neutrino
Sorry, this solution will not work. Keep in mind that I wanted to translate the text to other languages. This means that in some occassions the "link" could be at the beginning, or in the middle of the text. Your solution forces the link to be at the end (doesn't translate well).
egarcia
+3  A: 
log_in_message: This is a text, with a {{href}} inside.
log_in_href: link

<p> <%= t("log_in_message", :href => link_to(t("log_in_href"), login_path)) %> </p>
Simone Carletti
Mm. Convoluted, but seems the cleanest solution. Thanks!
egarcia