• ResolvedModerator Yui

    (@fierevere)


    永子

    When working with the translation of your plugin I noted one incorrect use of the function _n().

    In https://plugins.trac.wordpress.org/browser/wp-cerber/tags/8.7/cerber-load.php#L354
    sprintf( _n( 'You have only one login attempt remaining.', 'You have %d login attempts remaining.', $remain, 'wp-cerber' ), $remain ), $remain );

    _n() should be used only when the phrase contains a specific number, for instance:
    You have X login attempts remaining.
    X e-mails have been deleted.

    Russian, as an example, the tranlator needs to write three (3) diffeerent translation whenever _n() is used.
    The first one (singular) is used for 1, 21, 31, 41… 101, etc.
    The second one (dual) is used for 2, 3, 4, 22, 23, 24… 102, 103, 104, etc.
    The third one (plural) is used for everything else.

    In other words, if you would happen to have 21 invalid form names, then a website that is configured to use Russian would present that phrase in singular!

    There are other languages that maintain 5 or even 6 different plural forms, all depending on which specific number you’ve got in your phrase.

    Please see:
    https://developer.wordpress.org/reference/functions/_n/
    and subsequent comments.
    You can also refer to this topic: https://wordpress.org/support/topic/incorrect-use-of-_n/

    • This topic was modified 3 years, 4 months ago by Yui.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author gioni

    (@gioni)

    I’ve read all the posts (plus Otto’s post), and I still have no clue what you’re suggesting. Could you please elaborate? What’s the solution? The first argument is always singular. The second one is always plural, no matter what the language is used to translate into.

    Do you mean this approach? How does it help?

    sprintf( _n( 'You have %d attempt remaining.', 'You have %d login attempts remaining.', $remain, 'wp-cerber' ), $remain, $remain );

    Specifically for languages where “singular” can only have the value 1 it can be acceptable not to “consume” the variable in the string.

    But there are a couple of reasons to still not do it that way:
    – Translators may be confused. For languages where “singular” can have more values than “1”, for instance French and Russian, the translator still needs to place the variable in the translation also for singular.
    – Our translation platform checks that variables, like %s, are included in the translation. That extra net of security won’t be there if the source string lacks the variable token.

    If you want a “special string” for singular, then I’d suggest that you in the program logic separate that case and mark it as a normal string.

    Plugin Author gioni

    (@gioni)

    Thanks, @tobifjellner! I was thinking about having an additional singular phrase too. It will be implemented soon.

    Plugin Author gioni

    (@gioni)

    It’s been improved in the last release.

    Moderator Yui

    (@fierevere)

    永子

    Great, thank you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Incorrect use of _n()’ is closed to new replies.