如何生成.po文件?

时间:2022-11-23 10:04:13

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 gettext correctly setup up.

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

But HOW in the world do I create a .po file?

但是我在世界上如何创建.po文件?

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

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

Any help is greatly appreciated!

任何帮助是极大的赞赏!

3 个解决方案

#1


9  

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挂断的详细信息,我可能会提供更多帮助。

#2


8  

FOR 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

AND ...如果你使用Apache(例如在Xampp中),请停止并启动(重新启动)它什么时候你想用gettext()测试定义语言的新变化,换句话说,改变不会是受影响

#3


0  

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有任何问题,请随时提供一些细节。

#1


9  

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挂断的详细信息,我可能会提供更多帮助。

#2


8  

FOR 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

AND ...如果你使用Apache(例如在Xampp中),请停止并启动(重新启动)它什么时候你想用gettext()测试定义语言的新变化,换句话说,改变不会是受影响

#3


0  

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有任何问题,请随时提供一些细节。