• Hello,

    I have a sentence , it has singular and plural pen and book:

    The total price of two pens and two books.

    but the quantity of pen and books is uncertain, so how to use function “_n” to translate?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    Presumably the price is always singular, so that can remain the same. I’m assuming you could have 1 pen and 3 books. If the pen and book count were always the same, this could be done as one _n() phrase, otherwise you need to breakup the phrase to handle the potential of different quantities for each.

    You also need to use numerals for quantities because _n() requires an integer be passed and translating quantities becomes cumbersome unless there are very few quantities to account for.

    printf( _n('The total price of %d pen', 'The total price of %d pens', $x, 'my-domain'), $x );
    printf( _n(' and %d book', ' and %d books', $y, 'my-domain'), $y );
    Thread Starter gdtv

    (@gdtv)

    @bcworkz
    thanks for you reply, but if “breakup the phrase”, I can not translate them to chinese , the two phrase does not conform to Chinese grammar.

    printf( _n('The total price of %d pen', 'The total price of %d pens', $x, 'my-domain'), $x );
    printf( _n(' and %d book', ' and %d books', $y, 'my-domain'), $y );

    the chinese result will be:

    N支笔的总价和N本书

    this sentence does not conform to Chinese grammar.

    Moderator bcworkz

    (@bcworkz)

    I was afraid of that. This is why the polyglot folks admonish us to only use complete phrases. It’s probably not just Chinese too. I was thinking that each fragment does not need to be a literal translation, the two considered together could be reconstructed as needed to work properly. But it’s difficult to communicate this to translators. The only other choice is to use three completely independent phrases. You ordered %d pens. You ordered %d books. The total price is %s.

    Thread Starter gdtv

    (@gdtv)

    @bcworkz Thank you.

    Thread Starter gdtv

    (@gdtv)

    I finally do it like this:

    printf( 'The total price of %1$s and %2$s.', _n( '1 pen', '%d pens', $pen_count ), _n( '1 book', '%d books', $book_count ) );

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to translate this sentence using the function “_n” ?’ is closed to new replies.