Avoid using `_n()` for differentiating singular and plural (without number)
See original GitHub issueAs outlined in e.g. this article, _n()
must only be used for strings which include a number to differentiate the different versions of the translation string. It must not be used to only differentiate between singular and plural when there is no number involved.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- The usages of
_n()
which do not include any number placeholder in the translation string should be replaced with two individual__()
strings that are conditionally used based on the number.- Concretely, these usages are in the
AdSense
andAnalytics
PHP classes.
- Concretely, these usages are in the
- A sentence must never be split across multiple translation strings.
- Concretely, the TwG message in the
SetupSuccessBannerNotification
JS component needs to be modified to become one string with the link inside it (usingcreateInterpolateElement
).
- Concretely, the TwG message in the
- Translation strings should never start or end with a space. Instead such spaces should be included outside of the translation string.
- Concretely, one occurrence in the
Dialog
JS component needs to be fixed.
- Concretely, one occurrence in the
Implementation Brief
- In
includes/Modules/AdSense.php
andincludes/Modules/Analytics.php
:- Locate the usages of the
_n()
function. - Since the current usages do not include any number placeholders, instead of using the
_n()
function, we will assign the$message
variable twice conditionally based on the number of invalid items (metrics
ordimensions
). - After the existing check to see if the number of invalid items (
metrics
ordimensions
) is more than zero:- Check if it is more than one (i.e. plural), and if so, assign the
$message
variable as it is right now, but replacing_n()
with__()
, removing the first and third parameters. - If it is not more than one (i.e. singular), assign the
$message
variable as it is now, but replacing_n()
with__()
, removing the second and third parameters. The argument for the placeholder should be changed to the array of invalid items (e.g.$invalid_metrics
) converted to a string (usingtoString()
).
- Check if it is more than one (i.e. plural), and if so, assign the
- Locate the usages of the
- In
assets/js/components/notifications/SetupSuccessBannerNotification.js
:- Locate the
winData
object property assignments for theslug
variable beingthank-with-google
. - In the
description
property assignment, an external link should be added to the end of the current string that saysopen the administrator panel
pointing to thepublicationURL
variable. This should be done usingcreateInterpolateElement
.
- Locate the
- In
assets/js/googlesitekit/components-gm2/Dialog.js
:- Locate the
p.mdc-dialog__dependecies
element. - Instead of displaying the
Note:
text anddependentModules
prop separately, usecreateInterpolateElement
containing asprintf
function with a translatable string like this:__( '<strong>Note:</strong> %s' )
. The placeholder value should bedependentModules
.
- Locate the
Test Coverage
- No tests need to be added/updated.
QA Brief
- This issue updates the way how the error message (Unsupported (metric|dimension)/s requested: SOME_METRIC) mentioned in the fifth point of this QAB is rendered. Follow this QAB and verify that the error message still appears as expected.
- On a Site Kit installation with Thank with Google active and connected, go to this URL
/wp-admin/admin.php?page=googlesitekit-dashboard¬ification=authentication_success&slug=thank-with-google
so that the success banner for connecting Thank with Google shows up. Verify that the success banner shows up correctly as expected with the links working. - Activate the following services in Site Kit: Analytics, Analytics 4, Optimize. Now, try to disconnect Analytics. In the disconnection confirmation modal, verify that the
Note: these active modules depend on...
text appears correctly.
Changelog entry
- Avoid using _n() as a shortcut for singular/plural without using a number.
Issue Analytics
- State:
- Created a year ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Choosing between Singular and Plural Pronouns - dummies
English pronouns are either singular or plural. Singular pronouns replace singular nouns, which are those that name one person, place, thing, or idea....
Read more >An Algorithmic Approach to English Pluralization
The following algorithm takes the singular form of an English adjective (or article or genitive pronoun) and returns its plural form. Note that...
Read more >Handling Singular and Plural Controllers/Routes
As far as routing goes, best practices seems to favor that routes be pluralized nouns, and to avoid using verbs. This Apigee blog...
Read more >The Number vs. A Number
A Number. The expression the number is followed by a singular verb while the expression a number is followed by a plural verb....
Read more >Singular and plural nouns | EF | United States
Regular nouns Most singular nouns form the plural by adding -s. ... They are not used in the singular, or they have a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@felixarntz @hussain-t created the ticket! 👍
@wpdarren @hussain-t +1, a quick issue for this would be good, it should indeed not say “(Alpha)”.