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."
Labels |
Added:
?
|
%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.
That's what I thought it meant but as you see from the example joomla isnt adhering to it
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.
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.
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
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.
This has worked fine since 1.5 and can be modified if desired, for no real gain.
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
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.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2021-07-19 22:37:46 |
Closed_By | ⇒ | brianteeman |
https://www.php.net/manual/en/function.sprintf.php