wordpress插件

tech2022-09-28  82

wordpress插件

If you’ve developed a useful plugin for WordPress, that’s great – but it’s even better if you make your plugin accessible to users speaking other languages.

如果您已经为WordPress开发了一个有用的插件,那就太好了-但是,如果让使用其他语言的用户可以访问该插件,那就更好了。

The good news is that you can easily make your plugin translation ready. That way it will be available in several different languages.

好消息是您可以轻松地准备好插件翻译 。 这样,它将以几种不同的语言提供。

However, there’s a detail which is not always translated by plugin developers: the description of a plugin. In this quick tip, I will cover how you can translate this description.

但是,有一个插件开发者并不总是翻译的细节:插件的描述。 在此快速提示中,我将介绍如何翻译此描述。

允许人们翻译您的插件说明 (Allowing People to Translate Your Plugin’s Description)

To make your plugin translation ready, you generate a POT-file. This file contains all the strings you use in your plugin. To translate your plugin in a given language, one can create a PO-file from this a POT-file and then translate each string, one by one.

为了准备好您的插件翻译,请生成一个POT文件。 该文件包含您在插件中使用的所有字符串。 要以给定的语言翻译您的插件,可以从中创建一个PO文件(即POT文件),然后逐个翻译每个字符串。

By default, the POT-file does not only contain the strings you use with specific functions like __() or _e() it contains three additional strings: the name of the plugin, the URL of the plugin’s website, and the description of the plugin.

默认情况下,POT文件不仅包含您用于__()或_e()之类的特定功能的字符串,还包含三个附加字符串:插件名称,插件网站的网址以及插入。

That means that, by default, contributors can translate this information. There is a problem – these translations are not used unless you indicate to WordPress that they exist.

这意味着默认情况下,贡献者可以翻译此信息。 有一个问题–除非您向WordPress指出它们存在,否则不使用这些翻译。

To do that, go back to the comment that describes your plugin to WordPress. Located in the main file of your plugin, this comment is mandatory and is used by WordPress to know the name of your plugin and other useful information.

为此,请返回描述您的WordPress插件的注释。 此注释位于插件的主文件中,是必需的,WordPress可以使用此注释来了解插件的名称和其他有用信息。

In this comment, there are several required pieces of information to provide, but there are also some optional things you can choose to add. In this list of optional information, we find the text domain used by your plugin to be localized, and the path to the folder containing the localization files.

在此注释中,需要提供一些必需的信息,但是您还可以选择添加一些可选的东西。 在此可选信息列表中,我们找到要本地化您的插件所使用的文本域,以及包含本地化文件的文件夹的路径。

The comment is a list of key / value associations. For example, below is the comment used by previous versions of my plugin WP Photo Sphere.

注释是键/值关联的列表。 例如,以下是我的插件WP Photo Sphere的早期版本使用的注释。

<?php /* Plugin Name: WP Photo Sphere Plugin URI: http://jeremyheleine.me Description: A filter that displays 360×180 degree panoramas. Please read the readme file for instructions. Version: 2.0 Author: Jérémy Heleine Author URI: http://jeremyheleine.me License: MIT */ ?>

The POT file generated for these versions contains the description. However, as there was no mention to the text domain used by WP Photo Sphere in the comment, the translations of the description weren’t used.

为这些版本生成的POT文件包含描述。 但是,由于注释中未提及WP Photo Sphere使用的文本域,因此未使用描述的翻译。

Below is a more recent comment I used since there are several versions.

由于存在多个版本,因此以下是我使用的最新注释。

<?php /* Plugin Name: WP Photo Sphere Plugin URI: http://jeremyheleine.me Description: A filter that displays 360×180 degree panoramas. Please read the readme file for instructions. Version: 3.6.2 Author: Jérémy Heleine Author URI: http://jeremyheleine.me Text Domain: wp-photo-sphere Domain Path: /lang/ License: MIT */ ?>

Two new entries can be seen here: Text Domain and Domain Path. The value to indicate in Text Domain is the text domain used by your plugin, the one you load in your plugin with load_plugin_textdomain(). The Domain Path entry must be filled with a path. In this entry, the root is your plugin’s folder. You have to indicate a subdirectory of this folder, the one that contains all the needed MO-files.

在这里可以看到两个新条目: Text Domain和Domain Path 。 在Text Domain指示的值是您的插件使用的文本域,即您通过load_plugin_textdomain()在插件中加载的文本域。 Domain Path条目必须填充路径。 在此条目中,根目录是插件的文件夹。 您必须指定此文件夹的子目录,其中包含所有需要的MO文件。

If you use these entries, and if translations for the plugin’s description are available in the current language, these translations will be used. If you want, translations for the plugin’s name can also be used (just don’t remove the corresponding entry in the POT-file!). As said above, the plugin’s URL can also be translated. It can be useful if you provide this webpage in several languages, with a parameter in the URL. For instance, you can indicate http://myplugin.com as the default URL for your plugin, and http://myplugin.com/fr as the URL for French users.

如果您使用这些条目,并且使用当前语言提供了插件说明的翻译,则将使用这些翻译。 如果需要,也可以使用插件名称的翻译(只是不要删除POT文件中的相应条目!)。 如上所述,也可以翻译插件的URL。 如果以多种语言提供此网页,并在URL中提供参数,则可能会很有用。 例如,您可以将http://myplugin.com指示为插件的默认URL,并将http://myplugin.com/fr指示为法语用户的URL。

结束语 (Closing Words)

WordPress provides all the tools you need to translate your whole plugin, even its name or description. However, as the Text Domain and Domain Path are not required in the plugin’s header comment, they are often forgotten by developers.

WordPress提供了翻译整个插件所需的所有工具,甚至包括其名称或描述。 但是,由于插件的标题注释中不需要Text Domain和Domain Path ,因此开发人员通常会忘记它们。

Now you can translate the description of your plugin and describe to all users around the world what it does and why it is wonderful!

现在,您可以翻译插件的描述,并向世界各地的所有用户描述它的作用以及为何如此出色!

翻译自: https://www.sitepoint.com/how-to-translate-a-wordpress-plugin-description/

wordpress插件

最新回复(0)