使用.po .mo文件
5 个回答
- 投票数
-
- 2012-07-02
编辑器
还有其他方法,但这是最常用的方法: Poedit ,跨平台的gettext目录(.po文件)编辑器.
格式
-
.mo
代表机器对象
-编译WordPress使用的.po
文件的导出文件 -
.po
代表可移植对象
-具有翻译字符串的可编辑文本文件
-基于主.pot
文件,使用从POT文件更新 PoEdit函数
-有些人将其作为主文件分发,但应仅用于翻译 -
.pot
代表可移植对象模板
-使用从源代码更新 PoEdit功能 可编辑的文本文件,用于从WordPress本身以及主题和插件中获取所有可翻译字符串.
程序
- 复制.pot文件并将其重命名为
plugin-basename-lang_COUNTRY.po
- 所引用插件案例的示例:
subscribe-reloaded-pt_BR.po
-pt_BR 表示葡萄牙语巴西,但是许多语言没有国家/地区差异...
-您必须用自己的语言填写 -
WPLANG
中的 -
wp-config.php
>文件必须设置为您的语言,例如pt_BR
- 每次保存
.po
文件时,PoEdit都会自动生成一个.mo
文件,这是WordPress使用的文件,基本上是您唯一需要上传的文件
观察
- 如果您进行了完整或不错的部分翻译,请将其提交给插件作者,以便他可以将其包括在存储库中,您为此获得荣誉
- 不要忘记备份翻译,因为如果升级插件,文件将会丢失
- @ user17078插件建议非常好,但我从未使用过
The Editor
There are others, but this is most used: Poedit, a cross-platform gettext catalogs (.po files) editor.
The Formats
.mo
stands for Machine Object
-- compiled export of the.po
file which is used by WordPress.po
stands for Portable Object
-- editable text file with the translations strings
-- based on the master.pot
file, using Update from POT file PoEdit function
-- some folks distribute this as a master file, but it should be used only for translations.pot
stands for Portable Object Template
-- editable text file used to grab all the translatable strings from WordPress itself and Themes and Plugins, using Update from Sources PoEdit function
The Procedure
- Duplicate the .pot file and rename it to
plugin-basename-lang_COUNTRY.po
- Example for the referenced plugin case:
subscribe-reloaded-pt_BR.po
-- pt_BR means Portuguese Brazil, but many languages don't have a country variation...
-- you'll have to fill in with your own language WPLANG
inwp-config.php
file must be set to your language, e.g.,pt_BR
- Every time you save the
.po
file, PoEdit automatically generates a.mo
file, which is the one WordPress uses and basically the only one you need to upload
Observations
- If you do a full or a decent partial translation, submit it to the plugin author so he can include it in the Repository and you get credited for it
- Don't forget to make a backup of your translation, because if you upgrade the plugin your file will be lost
- @user17078 plugin suggestion is quite nice, but I never used it much
-
新的mo/po文件应生效多长时间?How long is the new mo/po file supposed to take to have effect?
- 2
- 2015-12-14
- Nemo
-
- 2012-07-02
您可以尝试以下代码样式本地化插件:.您可以使用此翻译您的插件和主题.
You can try this codestyling-localization plugin:. You can translate you plugins and themes using this.
-
这是我见过的最好的翻译插件.该插件可以随时拥有poedit,最好的部分是它免费且用户友好.这个答案应该至少被投票通过.This is the best translation plugin I have ever seen. This plugin can own poedit anyday and the best part is that it is free and user-friendly. This answer should be voted up atleast.
- 1
- 2014-10-02
- Gogol
-
不复存在.No longer exists.
- 1
- 2015-06-03
- Chris Cox
-
这看起来是一个不错的选择:https://wordpress.org/plugins/say-what/This looks like a good alternative: https://wordpress.org/plugins/say-what/
- 1
- 2015-06-10
- jetlej
-
@jetlej有趣,虽然对我的po文件似乎无效://@jetlej interesting, doesn't seem to work for my po file though :/
- 0
- 2015-12-14
- Nemo
-
- 2013-10-24
(这里是翻译为DEUTSCH的示例.将习俗更改为您想要的习惯.)
在每个插件头中都有一个唯一的名称. (例如:
/* Plugin Name: my-pluginname ....... */
然后,在该插件的文件夹中,创建一个文件夹" languages";
然后,在您的插件.php文件(位于顶部的某个位置)中,插入初始化代码:
class load_language { public function __construct() { add_action('init', array($this, 'load_my_transl')); } public function load_my_transl() { load_plugin_textdomain('my-pluginname', FALSE, dirname(plugin_basename(__FILE__)).'/languages/'); } } $zzzz = new load_language;
然后打开任何文本编辑器,然后插入如下代码(注意,我们只添加了两个示例消息" hello"和"bye",因此,您可以根据需要添加许多消息,并使用类似的行)
# English translations for PACKAGE package. # Copyright (C) 2012 THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. # Automatically generated, 2012. # msgid "" msgstr "" "Project-Id-Version: my-pluginname 1.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2012-08-06 13:46-0400\n" "PO-Revision-Date: 2013-03-21 11:20+0400\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "X-Poedit-SourceCharset: iso-8859-1\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" "X-Generator: Poedit 1.5.4\n" #: mypluginindex.php:87 (it is just a line of a note, to remind where our code appears) msgid "mymessage1" msgstr "Hello" #: mypluginindex.php:88 msgid "mymessage2" msgstr "Bye"
然后将该文件另存为"my-pluginname-en_US.po"(请注意,.po是文件的扩展名,因此请检查您的文本编辑器程序是否未保存到"my-pluginname-en_US.po.TXT" ").
然后下载POEDIT软件,然后打开此文件.然后编辑"翻译"字段,然后另存为"my-pluginname-de_DE" 将会生成两个文件(如果poEdit没有自动生成第二个.mo文件,只需转到文件->首选项->编辑器,然后选中"保存时自动编译.mo文件"复选框,
然后将这两个文件放入"语言"文件夹.
在此之后,打开wp-config.php并找到以下代码:
define ('WPLANG, '');
并更改为
define ('WPLANG, 'de_DE');
仅此而已. 加载WordPress时,它将读取您的插件语言文件,其前缀为-de_DE.
因此,在插件的.php文件中,而不是:
echo "Something string";
您应该使用:
echo __("mymessage1", 'my-pluginname');
完了现在您应该测试您的插件.p.s.二手链接:
(Here is an EXAMPLE of translation to DEUTSCH. CHANGE the customs to YOUR DESIRED ones.)
in every plugins head, there is an unique name. (for example:
/* Plugin Name: my-pluginname ....... */
then, in that plugin's folder, create a folder "languages";
then, into your plugin .php file (somewhere in the top), insert the initialization code:
class load_language { public function __construct() { add_action('init', array($this, 'load_my_transl')); } public function load_my_transl() { load_plugin_textdomain('my-pluginname', FALSE, dirname(plugin_basename(__FILE__)).'/languages/'); } } $zzzz = new load_language;
then open any text editor, then insert like this code (NOTE, THAT we are only adding two sample messages, "hello" and "bye", so , you can ADD AS MANY messages AS YOU WANT with the similar lines).
# English translations for PACKAGE package. # Copyright (C) 2012 THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. # Automatically generated, 2012. # msgid "" msgstr "" "Project-Id-Version: my-pluginname 1.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2012-08-06 13:46-0400\n" "PO-Revision-Date: 2013-03-21 11:20+0400\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "X-Poedit-SourceCharset: iso-8859-1\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" "X-Generator: Poedit 1.5.4\n" #: mypluginindex.php:87 (it is just a line of a note, to remind where our code appears) msgid "mymessage1" msgstr "Hello" #: mypluginindex.php:88 msgid "mymessage2" msgstr "Bye"
then save this file as "my-pluginname-en_US.po" (note, that .po is an extension of file, so check that your text editor program has not saved to "my-pluginname-en_US.po.TXT").
then download POEDIT software, and open this file. then edit the "translation" field, and then save as "my-pluginname-de_DE" there will be generated two files ( If poEdit does not generate the second .mo file automatically, just go to File -> Preferences -> Editor and check the box that says "Automatically compile .mo file on save"),
then put those two file into "languages" folder.
after this, open wp-config.php and find this code:
define ('WPLANG, '');
and change to
define ('WPLANG, 'de_DE');
That's all. When WordPress is loaded, it will read your plugins language file, with prefix -de_DE.
So, in the plugin's .php file, instead of:
echo "Something string";
you should use:
echo __("mymessage1", 'my-pluginname');
Finished. Now you should test your plugin.p.s. used links:
-
我尝试了以我的主题.在header.php中,我有`echo __("thanks-for-visiting",'transparent');`.在theme \ languages \transparent-en_US.po中,我有`msgid"感谢访问" msgstr"您好!感谢您的光临.环顾四周并订阅"`.这会在前端输出"感谢访问".I tried this with my theme. In header.php, I have `echo __("thanks-for-visiting", 'transparent');`. In theme\languages\transparent-en_US.po, I have `msgid "thanks-for-visiting"` `msgstr "Hello! Thank you for visiting. Take a look around and subscribe to the "`. This outputs "thanks-for-visiting" on the front end.
- 0
- 2014-03-10
- Steve
-
- 2012-07-02
-
- 2013-01-29
我还建议h ttp://poeditor.com/.它是基于Web的翻译工具,可与.po,.mo,.pot和其他类型的文件配合使用.
I suggest also http://poeditor.com/. It is a web-based translation tool that works great with .po, .mo, .pot and other types of files.
我想翻译此插件.
该插件已经被翻译成其他语言,并且它具有用于添加新语言的
.pot
文件(据我从描述中了解).如何为我的新语言创建
.po
和.mo
文件,并使其可访问以供插件使用?我试图通过在下面的定义中插入wp-config.php
文件中的俄语定义: