请参阅此_n();
函数示例(http://codex.wordpress.org/Function_Reference/_n):
sprintf( _n('%d comment.', '%d comments.', $number, 'text-domain'), $number );
用英语讲:
1 Comment
2 Comments
在波兰语等语言中,有不同的模式和多种复数形式:
1 Komentarz
2 Komentarze
3 Komentarze
4 Komentarze
5 Komentarzy
6 Komentarzy
...
21 Komentarzy
22 Komentarze
23 Komentarze
24 Komentarze
25 Komentarzy
...
31 Komentarzy
32 Komentarze
...
91 Komentarzy
92 Komentarze
...
111 Komentarzy
112 Komentarzy (!)
...
121 Komentarzy
122 Komentarze
如果他们的语言支持多种复数形式,我正在寻找某种方法使翻译人员能够设置自己的模式。你能想到任何创造性的 PHP 方法来做到这一点吗?
我能想到的一些解决方案(但翻译人员仍然无法设置任何模式):
if($number == 1){
$message = __(‘1 Komentarz’ , ‘text-domain’);
}else if($number == 2){
$message = __(‘2 Komentarze’ , ‘text-domain’);
}else if($number == 3){
$message = __(‘3 Komentarze’ , ‘text-domain’);
}
编辑:我在波兰语的 PO 文件中找到了这个:"Plural-Forms: nplurals=3; plural=n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"
但我仍然不知道如何准备_n();
函数来支持它。