php 如何生成 .po 文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2514449/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 06:46:33  来源:igfitidea点击:

How to generate a .po file?

phplocalizationgettextpoedit

提问by tobefound

On Windows using WAMPserver (Apache, MySQL, PHP) I have the following:

在使用 WAMPserver(Apache、MySQL、PHP)的 Windows 上,我有以下内容:

//test.php
if (!defined('LC_MESSAGES'))
define('LC_MESSAGES', 6);

$lang = "sv";
putenv("LANG=$lang");
setlocale(LC_ALL, $lang);

$domain = "messages";
bindtextdomain($domain, "./locale");
textdomain($domain);

echo _("This is a string");

It works fine, i.e. it outputs "This is a string" which means I have gettextcorrectly setup up.

它工作正常,即它输出“这是一个字符串”,这意味着我已gettext正确设置。

But HOW in the world do I create a .pofile?

但是我.po到底如何创建文件?

I downloaded Poedit but I can't see how to make this happen with that software.

我下载了 Poedit,但我看不到如何使用该软件实现这一点。

Any help is greatly appreciated!

任何帮助是极大的赞赏!

采纳答案by Colleen Kitchen

PoEdit is the tool to create the .po file. You have to do a little configuration with it and it's not the easiest. The way it should work is that it finds all the text in your source code that's wrapped in the marker string that you configure. This becomes the source text that you give to your translator. They then translate it into the target language(s) and save the translation files and return them to you. You then dump those files into a special directory in your php application and whenever the gettext extension sees one of the translation strings it fetches the appropriate translation.

PoEdit 是创建 .po 文件的工具。你必须用它做一些配置,这不是最简单的。它应该工作的方式是找到源代码中包含在您配置的标记字符串中的所有文本。这将成为您提供给翻译人员的源文本。然后他们将其翻译成目标语言并保存翻译文件并将其返回给您。然后将这些文件转储到 php 应用程序中的一个特殊目录中,每当 gettext 扩展看到翻译字符串之一时,它就会获取适当的翻译。

I can probably help more if you show some details about where you got hung up with poedit.

如果您显示一些有关您在何处挂断 poedit 的详细信息,我可能会提供更多帮助。

回答by Lupen

FOR php:

对于 php:

I have a file like ---- test_1.php ----

我有一个像 ---- test_1.php ---- 这样的文件

<?php
  echo _("Test phrase");
  echo gettext("Test phrase two");
  // NOTE: _ == gettext()
?>

File -> New catalog... In the "Source paths" tab, you have to click in New Folder, Add the path of the folder in which do you have the file (in this example test_1.php)

文件 -> 新建目录...在“源路径”选项卡中,您必须单击新建文件夹,添加文件所在文件夹的路径(在本例中为 test_1.php)

... They caught ALL the strings that get invoked with gettext()or _()... The useful for those function is explained here http://www.php.net/manual/es/function.gettext.php

...他们捕获了所有使用gettext()或调用的字符串_()... 这里解释了对这些函数的有用 http://www.php.net/manual/es/function.gettext.php

AND... If do you use Apache (for example in Xampp), please, Stop and Start (Restart) it when do you wanna test a new change in a defined language with gettext(), in another way the change will not be affected

并且...如果您使用 Apache(例如在 Xampp 中),请停止并启动(重新启动)它什么时候您想使用 测试定义语言中的新更改gettext(),以另一种方式更改不会受到影响

回答by álvaro González

There're many tools, such as Poedit. In PHP, it's handled by the Gettext extension.

有很多工具,例如Poedit。在 PHP 中,它由Gettext 扩展处理。

See also:

也可以看看:

If you are any problems with Poedit, feel free to give some details.

如果您对 Poedit 有任何问题,请随时提供一些详细信息。