• Hi Edward,
    While quickly checking your Swedish translations, I noted three strings that would be much better off if you used _n() instead, since that would allow correct translations to be made to Russian and some other languages with complicated plural handling.
    The phrases are:
    ? %s rows left to check…
    ? %s seconds
    ? How many seconds to add for each image that is attached to the post. %s seconds is the default value to upload the image, caption it and then insert it into the post.
    Note that with _n() you need to include the number twice: one time as a text string to be injected into the string, the other time as an argument to pick the correct plural form.

    By the way, when you need to inject a decimal integer into a printf() then %d may be a more convenient placeholder choice.

    EditAdd: One more thing: When you use placeholders in a string, it may sometimes be good to give a hint to the translator about what kind of content will be placed into the phrase (say, a user name or the total number of seconds since midnight, or whatever. Here’s the example from https://codex.www.ads-software.com/I18n_for_WordPress_Developers on how to include a hint for translators that will be visible while translating:

    /* translators: draft saved date format, see https://php.net/date */
    $draft_saved_date_format = esc_html__( 'g:i:s a', 'my-text-domain' );
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author edward_plainview

    (@edward_plainview)

    Noted. None of your examples need _n, although I added it to the second example just for the sake of experience.

    I’ll keep that in mind for the future.

    If you know for sure how many of something will be there, then it’s better to “hard code” that number into the string. Say:
    ‘This cache is renewed every 24 hours’
    But otherwise, for, say, ‘%s rows left to check…’ you should have in mind that not all languages are as straightforward as English and Swedish.
    In Russian, for example, you’ve got THREE different plural forms:
    Singular is used for: 1, 21, 31, 41, 51, 61… 101, 121, 131…
    “dual” is used for: 2, 3, 4, 22, 23, 24, 32, 33, 34…
    Plural is used for: 5-20, 25-30, 35-40…
    and the good news is that ngettext will take care of this!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Use correct plural handling for some strings’ is closed to new replies.