Keywords PoEdit - Plural

The local gettext-like system was enabled in my application, but my translation function looks like this:

t($category, $string, [$plural_string, $number, $vprintf_arguments]) 

My PoEdit keywords:

 t:2 t:2,3 
  • t: 2 tells PoEdit to parse $string , and it works, apparently
  • t: 2,3 should indicate PoEdit for parsing both $string and $plural_string - but this is not: (

It only sees $string , so I do not handle multiple forms ... How can I fix this? I don't want to switch my function to a different argument format, because I like this one :(

This function also acts as a replacement for sprintf:

  • if the third argument ($ plural_string) is an array, then the function will consider the values ​​from the array as arguments for vsprintf
  • if the 3rd argument is a string and $ number is supplied, the function will consider $ vprintf_arguments as vsprintf arguments (if provided), and $ plural_string as the plural form of $ string

In any case, PoEdit should not interfere with non-displayable arguments, right? I mean, it will parse $ plural_string as a string if it looks like 'abc abc'

+8
php localization gettext poedit
source share
2 answers

gettext uses only one line at a time. There may be ngettext for you. (look at the syntax)

There you will put one text for the singular, another for the plural, but also a number.

The clever thing about this is that many languages ​​have a completely different plural structure than English. For example, the Russian language uses three different forms. One - for where the score ends with a pronounced "one": 1, 21, 31, 41, etc. The second form is for counting, which ends with a pronounced 2, 3 or 4. The third form for the rest ...

And with ngettext this can be done. Yes, in poedit, you need to correctly define the plural structure of the target language, but then it just works.

http://www.gnu.org/s/hello/manual/gettext/Plural-forms.html

+6
source share

As Thor-BjΓΆrn Fjelner said, it really should work.

If you tell poedit that the language actually has multiple forms ( Translating multiple forms using Poedit ) and takes into account your keywords, poedit suggests them for translation.

Example

Multiple forms: nplurals=2; plural=n != 1; nplurals=2; plural=n != 1;

Keywords:

  • t:2
  • t:2,3

PHP code:

 <?php t("cat", "strA"); t("cat", "strB1", "strB2", 2, array()); t("cat", "strC1", "strC2", 3, array()); 

Poedit UI:

Poedit Plural Forms

What I did not understand in your question was the question about arrays, etc. I could not decrypt what you intend in the poedit / gettext domain, I think your question will be useful if you add some specific code examples and as a result it should be for them.

+1
source share

All Articles