PoEdit keywords - plurals
Asked Answered
D

2

8

I incorporated a gettext-like localization system in my app, 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 tell PoEdit to parse both $string and $plural_string - but it's not :(

It only sees $string, so I don't get the plural forms parsed... How can I fix that? I don't want to switch my function to a different argument format because I like this one :(

Also this function acts like a sprintf replacement:

  • if 3rd argument ($plural_string) is a array, then the function will consider the values from the array as arguments to vsprintf
  • if 3rd argument is a string and $number is provided, the function will consider $vprintf_arguments as arguments to vsprintf (if they are provided), and $plural_string as the plural form of $string

Anyway PoEdit should not interfere with non quoted arguments, right? I mean it will only parse $plural_string as string if it looks like 'abc abc'

Dyne answered 6/12, 2011 at 22:31 Comment(3)
Sorry if these look trivial questions to you, but I have very limited experience with this product. Could you show us the fragment of the .po file containing the string whose plural can not be obtained? Did you populate the msgid_plural field? Are you using in your files the expected charset / encoding?Gainful
Could you please post more of the php function? As well as maybe another example? What you expect and what you get. Thanks -Tim =)Sesquioxide
Yeah, without seeing any code it's quite hard to understand what's wrong.. and, which kind of tokenizer are you using to extract translation strings?Chargeable
S
7

gettext only deals with one string at a time. What you may be after is ngettext. (look it up for syntax)

There, you'll put in one text for singular, another for plural, but also the number.

The smart thing about this is, that many languages have a totally different plural structure, than English. Russian, for instance, uses three different forms. One is for where the count ends in a pronounced 'one': 1, 21, 31, 41 etc. The second form is for counts, which end in a pronounced 2, 3 or 4. The third form is for the rest...

And, with ngettext, this can be done. Yeah, in poedit, one has to correctly define the target language's plural structure, but then, it just works.

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

Saval answered 15/12, 2011 at 1:1 Comment(1)
Welcome to Stack Overflow; awesome first answer. I've been under the impression that gettext couldn't help with proper pluralization for the majority of languages out there. Thanks!Transmigrate
E
1

Like Tor-Bjorn Fjellner has answered, this actually should just work.

If you tell poedit that the language actually has plural forms (Translating Plural Forms with Poedit) and taken your keywords into account, poedit offers them for translation.

Example

Plural Forms: 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 didn't understand in your question was the point about the arrays and such. I could not decipher what you're intending to in the poedit/gettext domain, I think your question would benefit if you add some concrete code examples and how the outcome should be for them.

Edentate answered 15/12, 2011 at 16:20 Comment(2)
ok, I got it to work!! It turns out I had to reverse t:2 and t:2,3 in the keyword list. How come you got it to work with the keywords in that order?Dyne
No idea, I don't think I did something special. Maybe a program version difference?Edentate

© 2022 - 2024 — McMap. All rights reserved.