question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Avoid using `_n()` for differentiating singular and plural (without number)

See original GitHub issue

As 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 and Analytics PHP classes.
  • 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 (using createInterpolateElement).
  • 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.

Implementation Brief

  • In includes/Modules/AdSense.php and includes/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 or dimensions).
    • After the existing check to see if the number of invalid items (metrics or dimensions) 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 (using toString()).
  • In assets/js/components/notifications/SetupSuccessBannerNotification.js:
    • Locate the winData object property assignments for the slug variable being thank-with-google.
    • In the description property assignment, an external link should be added to the end of the current string that says open the administrator panel pointing to the publicationURL variable. This should be done using createInterpolateElement.
  • In assets/js/googlesitekit/components-gm2/Dialog.js:
    • Locate the p.mdc-dialog__dependecies element.
    • Instead of displaying the Note: text and dependentModules prop separately, use createInterpolateElement containing a sprintf function with a translatable string like this: __( '<strong>Note:</strong> %s' ). The placeholder value should be dependentModules.

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&notification=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:closed
  • Created a year ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
wpdarrencommented, Nov 15, 2022
1reaction
felixarntzcommented, Nov 14, 2022

@wpdarren @hussain-t +1, a quick issue for this would be good, it should indeed not say “(Alpha)”.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found