Success

User tests: Successful: Unsuccessful:

avatar ghost
ghost
27 Jul 2013

http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=31587

This PR makes it possible to place named placeholders for the sprintf variables in a string.

Instead of doing:

SOME_STRING="Hello %s, Welcome to %s. You can log in with %s (%s)"

You can now do:

SOME_STRING="Hello [[%1:name]], Welcome to [[%2:sitename]]. You can log in with [[%3:username]] ([[%4:password]])"

This gives translators a much better sense of what is going on.
It also makes it easier for translators to change the order of the variables, as this approach forces numbered variables.

The syntax is [[ + % + number of the variable (in order passed to the JText::sprintf method) + : + a custom name + ]].
So for the 5th variable string used for the 'error message' you could do:
[[%5:Error Message]]

The name given in the tag is ignored and is purely for readability and reference.
So it doesn't even matter if the translator translates these too, like:

SOME_STRING="Hallo [[%1:Naam]], Welkom op [[%2:Websitenaam]]. Je kan inloggen met [[%3:Gebruikersnaam]] ([[%4:Wachtwoord]])"

This change only adds the ability to do above. It does not change current behaviour.
This change should not affect any currently used strings.
(It will affect string that have the ```[[%1:foobar]] syntax in them. But I the chances of that currently being used anywhere are very slim. Not used in core anyway.)

Testing instructions

Add a custom string to - for example - the main .ini language file (or via overrides):

TEST_STRING="My email is [[%2:email]], my name is [[%1:name]]."

And test this php code in - for instance - your templates index.php:

echo JText::sprintf('TEST_STRING', 'Fred', 'fred@domain.com');
avatar nonumber nonumber - open - 27 Jul 2013
avatar nonumber nonumber - reference | - 27 Jul 13
avatar mbabker mbabker - reference | - 20 Aug 13
avatar mbabker mbabker - merge - 20 Aug 2013
avatar mbabker mbabker - close - 20 Aug 2013
avatar nonumber nonumber - head_ref_deleted - 20 Aug 2013
avatar garyamort garyamort - reference | - 2 Dec 13

Add a Comment

Login with GitHub to post a comment