?
avatar brianteeman
brianteeman
1 Jun 2021

What's the difference between %d and %s when used in language strings

COM_CONTACT_N_ITEMS_TRASHED="%d contacts trashed."
COM_CONTENT_N_ITEMS_TRASHED="%s articles trashed."

avatar brianteeman brianteeman - open - 1 Jun 2021
avatar joomla-cms-bot joomla-cms-bot - change - 1 Jun 2021
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 1 Jun 2021
avatar ThisIsFaar
ThisIsFaar - comment - 1 Jun 2021

%d, %s are placeholders that are used to replaced a variable in a string.

%d is used for a Numeric Value and %s is used for a String Value.

avatar brianteeman
brianteeman - comment - 1 Jun 2021

That's what I thought it meant but as you see from the example joomla isnt adhering to it

avatar ThisIsFaar
ThisIsFaar - comment - 1 Jun 2021

oh! I saw, well this one is now out of my context.

but just thinking that "COM_CONTENT_N_ITEMS_TRASHED" may be used somewhere, where the code needs to access some variable value. so that's why %d,%s is used. but I did not get any result of using "COM_CONTENT_N_ITEMS_TRASHED" .can you please describe a brief "what is the role of ini in Joomla". as far as I know ini files are initializing instructions.

avatar infograf768
infograf768 - comment - 2 Jun 2021

When we have only one variable and we are sure it will be a figure, it does not really matter if we use %s instead of %d.

avatar brianteeman
brianteeman - comment - 2 Jun 2021

When we have only one variable and we are sure it will be a figure, it does not really matter if we use %s instead of %d.

Seems very wrong to me. If it doesnt matter then why have the different specifiers

avatar infograf768
infograf768 - comment - 2 Jun 2021

I guess because, in our case, we are sure the variable is always a pure positive integer with no decimals and we do not need to force it.

The only advantage of choosing %d would be if we need to display a negative integer (signed decimal number) and/or the variable value would contain decimals as for example 4.2 to obtain 4

https://www.php.net/manual/en/function.sprintf.php

d | The argument is treated as an integer and presented as a (signed) decimal number.

https://math.stackexchange.com/questions/895848/differences-between-signed-and-unsigned-decimal-values

This has worked fine since 1.5 and can be modified if desired, for no real gain.

avatar brianteeman
brianteeman - comment - 2 Jun 2021

It is just confusing for people to see two (almost) identical strings using two different specifiers. IF anything they should all be changed to %s

avatar infograf768
infograf768 - comment - 2 Jun 2021

Using %d may only be useful to inform a php code-aware Translator (and github PR testers) that the result will be an integer, but it is only useful when there are multiple variables in the string included some %s.
Plus the fact that it is less than certain that all translators are code-aware.

Instead of modifying all existing strings to use %d instead of %s in such cases, it could be decided to use that specifier for all future strings.

Not my problem anymore.

avatar brianteeman brianteeman - change - 19 Jul 2021
Status New Closed
Closed_Date 0000-00-00 00:00:00 2021-07-19 22:37:46
Closed_By brianteeman
avatar brianteeman brianteeman - close - 19 Jul 2021

Add a Comment

Login with GitHub to post a comment