No Code Attached Yet
avatar brianteeman
brianteeman
4 Apr 2022

There are a lot of lazy uses of %s in language strings passed through sprintf. For example this string was just merged

COM_TEMPLATES_COPY_CHILD_TEMPLATE_STYLES="%s, copy of %s"

The problem here is that both instances of %s are not the same

$styleName = Text::sprintf('COM_TEMPLATES_COPY_CHILD_TEMPLATE_STYLES', ucfirst($template->element . '_' . $newName), $style->title);

This string should have been "%1$s, copy of %2$s" otherwise it is not possible to translate the string correctly where the language uses a different order of parts.

@tecpromotion

avatar brianteeman brianteeman - open - 4 Apr 2022
avatar joomla-cms-bot joomla-cms-bot - change - 4 Apr 2022
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 4 Apr 2022
avatar nikosdion
nikosdion - comment - 28 Apr 2022

I disagree on principle.

The positional format of sprint arguments, e.g. %1$s, must ONLY be used when a. an argument is used more than once; or b. an argument is no longer used but the code is not updated for legacy reasons (e.g. supporting old language files); or c. the code passes the arguments in a certain order but the language string author needs them in another.

The canonical language of the Joomla CMS is “English (United Kingdom)”. Therefore the developers need to provide language files in this language and code which passes the arguments in the correct order for this argument.

When a translator needs to transpose the elements of the string in their own language's strings they can do so by employing the aforementioned format.

Example in English (United Kingdom) and Greek (Greece).

$englishString = "%d %s thingamajics are already present in the %s container.";
$greekString = "O περιέκτης %3$s έχει ήδη %1$d ματζαφλάρια του τύπου %2$s."

As a translator I chose to rephrase this to make it read better in Greek, putting the counters where they need to be. I could have also gone for the direct but uglier translation:

$greekString = "%d ματζαφλάρια του τύπου %s βρίσκονται ήδη στον περιέκτη %s."

So, no, Brian. Not including the position arguments in the canonical string DOES NOT make it impossible to translate. It is still absolutely and perfectly possible. The translator CAN use the positional arguments wherever they need to. Please read https://www.php.net/sprintf

avatar brianteeman
brianteeman - comment - 28 Apr 2022

This convention is already used throughout joomla (with just a few exceptions hence this issue).

avatar brianteeman brianteeman - change - 22 Jun 2022
Status New Closed
Closed_Date 0000-00-00 00:00:00 2022-06-22 22:05:56
Closed_By brianteeman
avatar brianteeman brianteeman - close - 22 Jun 2022

Add a Comment

Login with GitHub to post a comment