Forum: Rails I18n Making parts of text clickable

1e782845563c051556143a36ee9cf365?d=identicon&s=25 Rasmus Nielsen (rasmus)
on 2010-02-10 13:24
(Received via mailing list)
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
42ec9fd08c179b547dcb60d977e29941?d=identicon&s=25 Iain Hecker (Guest)
on 2010-02-10 13:38
(Received via mailing list)
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
4a551074ddba4460f95d011c47190d0e?d=identicon&s=25 Henrik --- (malesca)
on 2010-02-10 15:06
(Received via mailing list)
On Wed, Feb 10, 2010 at 11:42, rasmusrn <rasmusrnielsen@gmail.com>
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.
1e782845563c051556143a36ee9cf365?d=identicon&s=25 Rasmus Nielsen (rasmus)
on 2010-02-11 08:56
(Received via mailing list)
Thank you for your reply.

No, I don't need different versions.

What I want is this:
Do you accept the <a>rules</a> and <a>terms</a>? // English
Accepter du <a>reglerne</a> og <a>betingelserne</a> // 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
1e782845563c051556143a36ee9cf365?d=identicon&s=25 Rasmus Nielsen (rasmus)
on 2010-02-11 09:02
(Received via mailing list)
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
Cd32d17c95d3bfb352504c36462b98bd?d=identicon&s=25 A.I. (Guest)
on 2010-02-11 12:41
(Received via mailing list)
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+)}/, '<a href="\2">\1</a>')
end


P.S. and R18n total compatibility with Rails I18n :)
This topic is locked and can not be replied to.