# Making parts of text clickable

**URL:** <https://www.ruby-forum.com/t/making-parts-of-text-clickable/183237>\
**Category:** Rails I18n\
**Created:** [February 10, 2010, 1:24pm UTC](https://www.ruby-forum.com/t/making-parts-of-text-clickable/183237 "2010-02-10T13:24:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rasmus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7993a0/32.png) [@rasmus](https://www.ruby-forum.com/u/rasmus)\
**Post date:** [February 10, 2010, 1:24pm UTC](https://www.ruby-forum.com/t/making-parts-of-text-clickable/183237/1 "2010-02-10T13:24:21Z")

</div>

Hi,

I need to make specific parts of a translated text clickable. One way  
to do this is:

Translations:  
rules: rules  
terms: terms  
do\_you\_accept: Do you accept the %{rules} and %{terms}?

In view:  
t :do\_you\_accept, :rules =\> link\_to(t(:rules), ‘/rules’), :terms =\>  
link\_to(t(:terms), ‘/terms’)

This works fine in English. However it introduces some issues for  
other languages that do not put the word “the” in front of nouns to  
express it in definite form. For instance, in the example above, the  
translator would be asked to translate the word “terms” without  
knowing it is in definite form. This means the resulting text  
translated back to English would be:  
“Do you accept rules and terms?”

The definite form “disappears”.

At the moment my best solution to problem is to write a wrapper method  
for the t method in ApplicationController making this possible:

Translation:  
do\_you\_accept: Do you accept the %{=rules|rules} and %{=terms|terms}?

# english

do\_you\_accept: Accepterer du %{=reglerne|rules} og %{=betingelser|  
terms}? # danish

In view:  
t :do\_you\_accept, :links =\> { :rules =\> ‘/rules’, :terms =\> ‘/terms’ }

This enable translators to define what part of the translation should  
actually be clickable.

I am hoping you guys could help me out with a better solution to this  
or tell me what you think of the above suggested solution proposal 🙂

- Rasmus

---

<div class="post-metadata">

**Author:** ![rasmus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7993a0/32.png) [@rasmus](https://www.ruby-forum.com/u/rasmus)\
**Post date:** [February 10, 2010, 1:38pm UTC](https://www.ruby-forum.com/t/making-parts-of-text-clickable/183237/2 "2010-02-10T13:38:59Z")

</div>

Hi,

I don’t quite follow. You have a text that has two links, that need to  
be replaced.  
I admit that the current way to do this is a bit verbose, but I don’t  
see how any of this implicates any grammar rules.

It’s true that your “terms” needn’t be a real translation of this  
keyword, but just whatever you want to be inside the link.

The only problem I can see is that you want to reuse the translation,  
but can’t because it needs to be used in different contexts and thus  
different forms.

One possible solution is to define multiple versions of the word:

terms:  
header: Terms  
link\_text: the terms

Does this help?

As for you suggestion, it is very specific, so it might be okay in a  
helper method for links, but I don’t think it belongs in Rails by  
default.

Cheers,  
Iain

---

<div class="post-metadata">

**Author:** ![rasmus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7993a0/32.png) [@rasmus](https://www.ruby-forum.com/u/rasmus)\
**Post date:** [February 10, 2010, 3:06pm UTC](https://www.ruby-forum.com/t/making-parts-of-text-clickable/183237/3 "2010-02-10T15:06:11Z")

</div>

On Wed, Feb 10, 2010 at 11:42, rasmusrn [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> In view:  
> t :do\_you\_accept, :rules =\> link\_to(t(:rules), ‘/rules’), :terms =\>  
> link\_to(t(:terms), ‘/terms’)
> 
> This works fine in English. However it introduces some issues for  
> other languages that do not put the word “the” in front of nouns to  
> express it in definite form. For instance, in the example above, the  
> translator would be asked to translate the word “terms” without  
> knowing it is in definite form. This means the resulting text  
> translated back to English would be:  
> “Do you accept rules and terms?”

You could just use more explicit translation keys, e.g.

```
t :'accept_terms.sentence', :rules =>

```

link\_to(t(:‘accept\_terms.the\_rules’), ‘/rules’), :the\_terms =\>  
link\_to(t(:‘accept\_terms.the\_terms’), ‘/terms’)

Grouping them together like this would help the translator figure it  
out.

---

<div class="post-metadata">

**Author:** ![rasmus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7993a0/32.png) [@rasmus](https://www.ruby-forum.com/u/rasmus)\
**Post date:** [February 11, 2010, 9:02am UTC](https://www.ruby-forum.com/t/making-parts-of-text-clickable/183237/4 "2010-02-11T09:02:06Z")

</div>

Thanks, but I’m not sure I follow. You mean like this:

accept\_terms.sentence = ‘Do you accept the %{rules} and %{terms}?’  
accept\_terms.the\_rules = ‘rules’  
accept\_terms.the\_terms = ‘terms’

I guess it would help the translator a little, but ideally I would  
like to be able name the keys so they make most sense for the  
developer without being forced to also regard the translators. But  
thanks for the suggestion, I will consider it 🙂

- Rasmus

---

<div class="post-metadata">

**Author:** ![rasmus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7993a0/32.png) [@rasmus](https://www.ruby-forum.com/u/rasmus)\
**Post date:** [February 11, 2010, 8:56am UTC](https://www.ruby-forum.com/t/making-parts-of-text-clickable/183237/5 "2010-02-11T08:56:14Z")

</div>

Thank you for your reply.

No, I don’t need different versions.

What I want is this:  
Do you accept the rules and terms? // English  
Accepter du reglerne og betingelserne // Danish

Using a traditional approach I thus need a translation for “rules” and  
for “terms”.

When the Danish translator is asked to translate the word “rules”, he  
does not know that it is definite form. “Rules” is not in definite  
form, as the “the” word is not there. That is ok in English (because  
the “the”-word is added in “Do you accept”-sentence), but in Danish  
the noun itself is changed when expressed in definite form.

The Danish translator will translate “rules” into the plural non-  
definte form. This means that “rules” will now be expressed in the non  
definite form in the resulting “Do you accept…”-sentence. Danish  
have no word like “the” - the noun is expressed in definite form by  
adding a suffix to the noun):

Example translation:  
Rules = Regler  
The rules = Reglerne

I hope you now understand my problem and why it affects grammar.

- Rasmus

---

<div class="post-metadata">

**Author:** ![rasmus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7993a0/32.png) [@rasmus](https://www.ruby-forum.com/u/rasmus)\
**Post date:** [February 11, 2010, 12:41pm UTC](https://www.ruby-forum.com/t/making-parts-of-text-clickable/183237/6 "2010-02-11T12:41:01Z")

</div>

You can simple write filter for R18n, to have link like %{=reglerne|  
rules}. See: [http://r18n.rubyforge.org/](http://r18n.rubyforge.org/)

For example:

R18n::Filters.add(String, :links) do |content|  
content.gsub(/%{=(\w+)|(\w+)}/, ‘\1’)  
end

P.S. and R18n total compatibility with Rails I18n 🙂
