Making parts of text clickable

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 :slight_smile:

  • Rasmus

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

On Wed, Feb 10, 2010 at 11:42, rasmusrn [email protected]
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.

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 :slight_smile:

  • Rasmus

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

You can simple write filter for R18n, to have link like %{=reglerne|
rules}. See: 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 :slight_smile: