wordpress插件
In the first part of this series on WordPress plugin i18n and l10n, we learned how to internationalize a WordPress plugin.
在本系列有关WordPress插件i18n和l10n的第一部分中,我们学习了如何使WordPress插件国际化 。
This second (and concluding) part will be a walk-through on making a plugin ready for translation, as well as learning how to localize or translate a plugin into a new language.
第二部分(也是结论部分)将逐步介绍如何为翻译准备插件,以及学习如何将插件本地化或翻译成新语言。
The process of making a plugin ready for translation is fairly straight-forward. First of all, you’ll need to generate a .pot file. This file is used by translators to translate your plugin into a new language.
使插件准备好进行翻译的过程非常简单。 首先,您需要生成一个.pot文件。 译员使用此文件将您的插件翻译成新的语言。
This .pot file contains the original strings (in English) of your plugin.
该.pot文件包含插件的原始字符串(英语)。
Here is an example POT file entry:
这是一个示例POT文件条目:
#: plugin-name.php:123 msgid "Welcome to SitePoint" msgstr ""A translator looking to translate the text Welcome to SitePoint (at line 123 in your plugin file) into German will add the translation between the quotation marks.
希望将“ Welcome to SitePoint ”文本(在插件文件中的第123行)翻译成德语的翻译人员将在引号之间添加翻译。
#: plugin-name.php:123 msgid "Welcome to SitePoint" msgstr "Willkommen auf SitePoint"As previously mentioned, the POT file is the one that is handed to translators, so that they can do their work.
如前所述, POT文件是交给翻译人员的文件,以便他们可以完成工作。
Take note: before generating your plugin POT file, ensure you’ve internationalized your plugin.
请注意:在生成插件POT文件之前,请确保已对插件进行了国际化 。
There are a couple of ways to generate a POT file for your plugin.
有两种方法可以为您的插件生成POT文件。
The official WordPress plugin repository has a tool for generating the POT file of a plugin which is located at the Admin page of every plugin listing.
官方WordPress插件存储库具有一个用于生成插件的POT文件的工具,该工具位于每个插件列表的管理页面上。
To access the Admin page of your plugin, login to the plugin repository and click the green Admin button on the sidebar.
要访问插件的“管理”页面,请登录到插件存储库 ,然后单击侧栏上的绿色“ Admin按钮。
Follow the short guide below to see how easy it is to generate POT files using the admin tool.
请遵循以下简短指南,以了解使用管理工具生成POT文件有多么容易。
Click on Continue in the Generate POT file section.
在“ Generate POT file部分中单击“ Continue ”。
Click on Continue in the Generate POT file section.
在“ Generate POT file部分中单击“ Continue ”。
Then click on Get POT to download the POT file.
然后单击“ Get POT以下载POT文件。
There are a number of Gettext translation editors but Poedit is popular among the WordPress faithful.
有许多Gettext翻译编辑器,但Poedit在WordPress忠实者中很受欢迎。
The pro version allows you to create the PO/POT file with one click.
专业版允许您一键创建PO / POT文件。
If you don’t have the pro version you can easily get this Blank POT and use it as the base of your POT file.
如果您没有专业版,则可以轻松获取此Blank POT并将其用作POT文件的基础。
Once you have placed the blank POT in the languages folder of your plugin, double-click on it and open it with Poedit.
将空白POT放置在插件的languages文件夹中后,双击它并使用Poedit打开它。
Click Update in Poedit to update the POT file with your plugin strings.
点击Update在poEdit的更新使用的插件字符串POT文件。
Finally, click File > Save or Ctrl + S to save the changes.
最后,单击File > Save或Ctrl + S保存更改。
If you own a Pro version of this tool, generating the POT file is as easy as following the steps below.
如果您拥有此工具的专业版 ,则生成POT文件非常简单,只需执行以下步骤。
Click File > New WordPress translation and select your plugin folder.
单击File > New WordPress translation然后选择您的插件文件夹。
Poedit will skim over your plugin files and extract the translatable string. Poedit将浏览您的插件文件并提取可翻译字符串。 Select the language of the translation from the pop-up dialog box. 从弹出对话框中选择翻译的语言。Ctrl + S and explicitly save the file as .pot.
Ctrl + S并将文件显式保存为.pot 。
You can save the file as .po and afterwards rename it to .POT.
您可以将文件另存为.po ,然后将其重命名为.POT 。
A PO and a POT file are similar in that they have the same content format. The subtle differences between them are:
PO和POT文件的相似之处在于它们具有相同的内容格式。 它们之间的细微差别是:
It is the .pot file that is used by a translator and not the PO file.
翻译人员使用的是.pot文件,而不是PO文件。
It is from the resulting .po translation file a .mo file is compiled.
从生成的.po转换文件中可以编译出.mo文件。
It is a good idea to offer the POT file along with your plugin, so that translators won’t have to ask you specifically about it.
最好将POT文件与您的插件一起提供,这样翻译人员就不必专门询问您了。
Localization describes the subsequent process of translating an internationalized plugin into a new language.
本地化描述了将国际化插件翻译成新语言的后续过程。
To localize a plugin, grab the plugin POT file, open it in a text editor, and enter the translation of every string at their respective msgstr sections, in between the quotation marks.
要本地化插件,请获取插件的POT文件,在文本编辑器中将其打开,然后在引号之间的相应msgstr部分输入每个字符串的翻译。
Save the file in this format my-plugin-{locale}.po where the {locale} is the language code and/or country code that you defined in the constant WPLANG in the file wp-config.php. For example, the locale for German is de_DE. The my-plugin is the text domain of the plugin.
以my-plugin-{locale}.po格式保存文件,其中{locale}是您在wp-config.php文件中的常量WPLANG中定义的语言代码和/或国家/地区代码。 例如,德语的语言环境是de_DE 。 my-plugin是my-plugin的文本域 。
Remember, it is from the .po file that the resultant .mo file (used by WordPress in translating a plugin) is generated.
请记住,正是从.po文件生成了生成的.mo文件(WordPress在翻译插件时使用)。
Let’s see how to generate the MO file from the PO file.
让我们看看如何从PO文件生成MO文件。
There are a couple of online tools that convert a .po file to a .mo file. Personally, I use the tool at tools.konstruktors.com.
有几个在线 工具可以将.po文件转换为.mo文件。 我个人使用tools.konstruktors.com上的工具。
To generate a MO from a PO file, upload the .pot file. The tool will automatically convert the file, and provide you an .mo file for download.
要从PO文件生成MO,请上载.pot文件。 该工具将自动转换文件,并为您提供.mo文件以供下载。
Poedit provides a simple interface for translating plugin strings or texts and can also generate the required MO file from a PO file.
Poedit提供了一个用于翻译插件字符串或文本的简单界面,还可以从PO文件生成所需的MO文件。
To localize or translate a plugin into a new language using Poedit, follow the guide below.
要使用Poedit将插件本地化或翻译成新语言,请遵循以下指南。
Open the plugin .pot file with Poedit.
用Poedit打开插件.pot文件。
Click on the translatable strings and enter their respective translation in the text area labeled Translation.
单击可翻译的字符串,然后在标记为Translation的文本区域中输入它们各自的翻译 。
Click on the translatable strings and enter their respective translation in the text area labeled Translation.
单击可翻译的字符串,然后在标记为Translation的文本区域中输入它们各自的翻译 。
When you are done with the translation, save the file in this format my-plugin-{locale}.po. E.g. espw-plugin-de_DE.po where espw-plugin is the text domain and de_DE as the locale.
完成翻译后,以my-plugin-{locale}.po格式保存文件。 例如espw-plugin-de_DE.po ,其中espw-plugin是文本域,而de_DE是语言环境。
On saving the PO file, the MO file is automatically generated.
保存PO文件时,将自动生成MO文件。
If a translator sends your plugin translation file (the MO and PO files) to you, copy the MO (.mo) file to your plugin language folder for use by WordPress.
如果翻译将您的插件翻译文件(MO和PO文件)发送给您,请将MO(.mo)文件复制到您的插件language文件夹中,以供WordPress使用。
When a user operating a Localized version of WordPress uses your plugin, the plugin will then be in their language.
当使用WordPress本地化版本的用户使用您的插件时,该插件将使用其语言。
If you want your plugin to reach the widest possible audience, internationalize it and make it translation ready.
如果您希望您的插件能接触到尽可能广泛的受众,请对其进行国际化并准备翻译。
Although you might only be proficient in one language, if you make your plugin ready for translation, it opens up the possibility for people to voluntarily translate your plugin.
尽管您可能只精通一种语言,但是如果您准备好要翻译的插件,则可能会导致人们自愿翻译您的插件。
If you have any questions, suggestions or contributions, I would be happy to hear them in the comments.
如果您有任何问题,建议或意见,我很乐意在评论中听到。
翻译自: https://www.sitepoint.com/wordpress-l10n-translate-your-plugin/
wordpress插件
相关资源:GlotPress-WP:GlotPress是一个WordPress插件,可让您设置自己的基于Web的协作式软件翻译工具-源码