PHP本地化最佳做法? gettext? [英] PHP Localization Best Practices? gettext?

查看:68
本文介绍了PHP本地化最佳做法? gettext?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使我们的网站国际化,允许多种语言.

We are in the process of making our website international, allowing multiple languages.

我已经研究过php的"gettext",如果我理解正确的话,会发现一个很大的缺陷:

I've looked into php's "gettext" however, if I understand it right, I see a big flaw:

如果我的网页上有静态文本"Hello World".我可以将字符串作为<?php echo gettext("Hello World"); ?>放置,使用工具生成po/mo文件.然后,我将该文件交给翻译人员进行处理.

If my webpage has let's say "Hello World" as a static text. I can put the string as <?php echo gettext("Hello World"); ?>, generate the po/mo files using a tool. Then I would give the file to a translator to work on.

几天后,我们想将英文文本更改为"Hello Small World"吗? 我是否可以更改gettext中的值?我是否可以创建英文PO文件并在那里进行更改? 如果您更改gettext,它将认为它是一个新字符串,您将立即失去当前的翻译...

A few days later we want to change the text in English to say "Hello Small World"? Do I change the value in gettext? Do I create an english PO file and change it there? If you change the gettext it will consider it as a new string and you'll instantly loose the current translation ...

在我看来,php文件的内容将逐渐到处都是旧文本. 否则,翻译人员可能会被告知当您看到Hello World时,而是翻译Hello Small World".

It seems to me that gradually, the content of the php file will have old text everywhere. Or people translating might have to be told "when you see Hello World, instead, translate Hello Small World".

我不知道我会感到困惑.

I don't know I'm getting confused.

在其他编程语言中,我已经看到它们使用诸如web.home.featured.HelloWorld之类的关键字.

In other programming languages, I've seen that they use keywords such as web.home.featured.HelloWorld.

处理PHP中的翻译的最佳方法是什么?

What is the best way to handle translations in PHP?

谢谢

推荐答案

您基本上是问并回答了自己的问题,答案可能只是对PO文件的工作原理有了更好的了解.

You basically asked and answered your own question, the answer might just be having a slightly better understanding of how PO files work.

在PO文件中,您有一个msgid和一个msgstr. msgid是根据本地化在PHP文件中替换为msgstr的值.

Within the PO file you have a msgid and a msgstr. The msgid is the value which is replaced with the msgstr within the PHP file depending on the localization.

现在,您可以根据自己的喜好创建这些msgid的任何内容,就可以做到:

Now you can make those msgid's anything you would like, you could very well make it:

<?php echo _("web.home.featured.HelloWorld"); ?>

然后您再也不会在源中再次触摸此字符串,只需通过PO文件编辑该字符串.

And then you would never touch this string again within the source, you only edit the string through the PO files.

因此,从根本上来说,您的问题的答案是您为字符串应该说的内容指定gettext值标识符,但是翻译人员通常使用默认语言文件文本作为转换的基础,而不是标识符本身.

So basically the answer to your question is you make the gettext values identifiers for what the string should say, however the translators typically use the default language files text as the basis for conversion, not the identifier itself.

我希望这很清楚.

这篇关于PHP本地化最佳做法? gettext?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆