Ata*_*adj 14 php wordpress gettext internationalization
请参阅此_n();函数示例(http://codex.wordpress.org/Function_Reference/_n):
sprintf( _n('%d comment.', '%d comments.', $number, 'text-domain'), $number );
用英语讲:
1 Comment
2 Comments
Run Code Online (Sandbox Code Playgroud)
在波兰语等语言中有不同的模式和多种复数形式:
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
Run Code Online (Sandbox Code Playgroud)
如果他们的语言支持多种复数形式,我正在寻找一些方法来让翻译人员设置他们自己的模式.您能想到任何有创意的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’);
}
Run Code Online (Sandbox Code Playgroud)
编辑:我在波兰语的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();支持它的功能.
akk*_*kky 16
首先,您的语言环境文件需要具有复数的定义.正如您在问题上添加的那样,在波兰案例中您可能会看到
"Plural-Forms: nplurals=3; plural=n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"
Run Code Online (Sandbox Code Playgroud)
或(domain_name)-pl.po文件中的类似定义.
然后,您需要在.po文件中准备"%d Comment"/"%d Comments"的翻译.例如,
msgid "%d Comment"
msgid_plural "%d Comments"
msgstr[0] "%d Komentarz"
msgstr[1] "%d Komentarze"
msgstr[2] "%d Komentarzy"
Run Code Online (Sandbox Code Playgroud)
请将.po文件编译成.mo文件并放入适当的文件夹.(例如languages /(domain_name)-pl.mo
在你的Wordpress(插件/主题我假设)代码中,你可以这样称呼它,
for ($i=1;$i<15;$i++) {
printf(_n("%d Comment", "%d Comments", $i, "(domain_name)"), $i);echo "<br />";
}
printf(_n("%d Comment", "%d Comments", 112, (domain_name)"), 112);echo "<br />";
Run Code Online (Sandbox Code Playgroud)
当然,在wp-config.php中将WordPress的语言环境设置为波兰语,
define ('WPLANG', 'pl');
Run Code Online (Sandbox Code Playgroud)
你应该看到正确的复数形式的结果.
| 归档时间: |
|
| 查看次数: |
5951 次 |
| 最近记录: |