Fixing translation errors with @placeholders

Events happening in the community are now at Drupal community events on www.drupal.org.
spudley's picture

Hi.

I have a problem with a few translations that have been done for our Drupal site.

A number of the translatable strings in our system contain @placeholders for inserting variables into a string at run-time. These are generally fine, but a few of them are breaking when the site is translated.

The problem appears to be due to punctuation on either the original or translated strings.

For example, an original English string may look like this:

@user's picture

But when it's translated (in this case to Danish), it comes out looking like this:

@users billede

This breaks Drupal's t() function because Danish doesn't use an aspostrophie for possessives, and so the placeholder @user is not in the translated string, so it simply shows on the site as "@users billede".

Similarly, the following string:

Template file for !langname translations

is translated into German with a hyphen:

Vorlagendatei für die !language-Übersetzung

In this case, the hyphen is picked up as part of the placeholder, which breaks the placeholder system. And in fact there is potential in languages like German, where words can often joined together without spaces, for it to be even harder to deal with.

Does Drupal have a mechanism for getting around this sort of problem?

(By the way, in case it makes any difference to the answer, we're on Drupal 6)

Comments

Can't find the string

Thomas_Zahreddin's picture

maybe you check the string 'Vorlagendatei für die !language-Übersetzung' again:
http://localize.drupal.org/translate/languages/de/translate?project=&status=0&release=all&search=!language&author=&context=all&limit=50&sid=0

(I can't find it, so i suppose it is fixed).

Best
Thomas Zahreddin

Not specific to those strings.

spudley's picture

@Thomas_Zahreddin - thanks for the reply.

Actually, it shows up if you search for '!langname' rather than '!language':
http://localize.drupal.org/translate/languages/de/translate?project=&status=0&release=all&search=!langname&author=&context=all&limit=50&sid=0

So it is still there.

But I'm not looking for fixes for the specific strings I mentioned (although that would be nice), but rather a solution for the general problem of how to use placeholders in a string when punctuation in either the source or destination language could break the placeholder. The ones I mentioned above are in standard modules, but I have similar issues with translations for my own custom code, so I need a more general solution.

I guess the real question is how should a placeholder be formatted to prevent issues like this from ever happening?

I note that the manual page for Drupal's t() function (http://api.drupal.org/api/drupal/includes--bootstrap.inc/function/t/7) explicitly uses the following as an example of how to use placeholders:

<?php
$text
= t("@name's blog", array('@name' => format_username($account)));
?>

This example could break in exactly the way I've described, but it's given as an example of how to do it. This is a bit worrying as it implies that the issue hasn't been thought about.

should not break

gábor hojtsy's picture

Well, the replacement used is a simple text replacement so if your text contains @user @users and @username and have only a @user replacement value, it should replace all occasions and leave the 's' and 'name' intact. In your second example above, you replace !langname with !language in the translation. That would not work... However, adding anything at the end of the placeholder should work. On the other hand I doubt that adding an s after the username would be correct with all usernames, will it? What if the username is 'hass' (a prominent member of the German team)? Is 'hasss' right then?

Translations

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: