PHP本地化最佳实践?获取文本? [英] PHP Localization Best Practices? gettext?

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

问题描述

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

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本地化最佳实践?获取文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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