Creating translatable word press themes and plug-ins: a developer’s Guide

Last year, we launched a multi-faceted WordPress translation series, focusing on the internationalization of existing themes or plug-ins. Today’s post will provide some information for theme and plug-in developers, such as how to localize or translate themes or plug-ins to extend and supplement the series. Let’s take a look at what you need to do to create a new product so that users can easily translate the product into their own language. 29% of the WordPress websites use foreign languages and pay more attention to internationalization in the WordPress community. Therefore, it is more important than ever to confirm whether the themes and plug-ins are ready for translation. The
Let’s look at the process in detail so that we can use the correct functions and methods when creating themes and plug-ins. The first thing to do for a text field is to define the text field. What is a text field? A text field is a method of displaying generic translations. It makes language files more portable, modular and readable. Specifying the name of the text field is a simple problem because the name of the plug-in \/ topic determines what it is. The text field must match the slug of the topic or plug-in, usually the name of the folder containing the topic. The
For the upcoming Tweety fifth topic, it is not only the topic name, but also the Tweety fifth. The folder name slug is \
The load summary f3a3426f38efccb8e190db00bd35ba2a displays the string to be translated. Most developers know that to translate a string, you must return it to the \u () function or replace it with the \u e () function. In most cases, you will actually use the above two functions, but in order to complete the translation, there are still 11 functions that can be actually used. Let’s look at all the options and their uses__ () one of the most basic translation functions. Like other brothers, you use two parameters: the string to be translated and the text field. Used to display a simple string used to load the summary 38520494733 ecef68827cfcec47b9e67 translation and return values used elsewhere. This often happens in functions. Please consider registering the post type. In the Codex example below, you can see how all the members in the array are displayed as translation targets. The
It is almost the same as the above function except that the summary 0e48a7845e20db9d310f2a26c99b5f8c_e() value is loaded reversely. It can be translated in the HTML content directory. Load summary 68ddad1f60a825295b4570e2afb7148\u n() this function is used to translate strings containing conditional complex numbers. This means that the string depends on the instantaneous value of a parameter, so it is impossible to know in advance that the string will be plural or singular. A good example is the number of comments. For example, if the number of comments is 1, the singular form of \
Four parameters are used: singular, plural, number to check, and text area. Load summary b9dd17ca47e6fe866ce77db9dd6ac024 sprintf() function uses sprintf()
The default PHP function that outputs a string formatted according to some parameters. Often used with more complex translations of variables that are commonly used. Common methods include: Load summary df266a46ff7375e65b1227de33cc9aa the two most commonly used placeholders are the string%s is%s and the integer is%d. If you use these placeholders, you must pass the sprintf additional parameter to the number of placeholders in use. You can also use the second placeholder first and then index the placeholder. For advanced usage of this feature, refer to the PHP documentation. The
You can use \u n() in conjunction with sprintf() to describe the 0 value to make the above translation example better. Load summary 53697387 bae65a2d2eb62e0ca7594bea in this example, the use of the $comment\u count variable may be confusing_ When used in the n () function, the version to be used is determined according to the value, singular or multiple versions. At the end of the line, when it is used as the second parameter of sprintf (), we use it as an alternative value for%s_ The function with \
The load summary d0fa466e6504cd16620954a12f71ee2e consists of two sets of functions, which are used to escape the string of the escape attribute. One group handles strings used in attributes, and the other handles escaping HTML. Here: esc\u attr\u() esc\u attr\u e() esc\u attr\u n() esc\u html\u e() esc\u html\u n() we have looked at all these types of functions, so it should be clear. Here is a simple example: Load summary 237322aea9804062e0b833dffd7df96 bare metal translation this function name is not very good. It is only useful in specific cases and is difficult to explain_ N\u noop() and \nx\u noop() register strings for translation, but not immediately. The
English has singular and plural forms, so it is very simple. In other languages (such as Russian), it is not that simple. The nooped feature allows you to register translations separately. The actual output is generated using the translate\u nooped\u plural() function. Codex provides an excellent example of how it works: the load summary 958 a351186e7c6def1bf58ac8748fe96 JavaScript has no translation function, but can be executed on the server side using the original wp_localize_script() function. The idea is to create a string object, add it to the document, and pass it to the script. If a translation file is available, it will be translated before the string is output. The
The load summary 5b1635bcbb097b3e68e39de1bcd1e0 script will be queued first and then localized. The first parameter to the localization function is the name of the script to be localized. The second is the unique object name used to hold the string. The following parameters are arrays of keys and values to be used in the script: Finally, it can be implemented in JavaScript. Loading points b51f60e7305a0da4d275ffc4ec
To activate the 06ac5a text field to load translated strings, a translation file must be provided. Every time WordPress views the translation function, it will find the translation file of the current language and the text specified in the function. If the text is not found, it will be returned directly. The
You must notify the WordPress plug-in \/ theme of the location of the translation file. This can be done using the load\u plugin\textdomain() function that must be connected to the plugins\u load operation. Load summary e881bc43d51a89c090d50e547a38d36 in this phase, everything must work. HTML and JavaScript must be easy to translate. To help users, you must create a translation template file pot file. During the translation of translated files, three file formats are displayed. First. The pot file is a translation template file. This file is a human readable translation file and is a translation file of other types. Mo files are machine readable translation files. After creating a new language file, you usually start with the pot file. Zh\u ch.po uses the same locale for copying and naming (zh is the Chinese language code, ch is the Chinese country code). Then, if you open it using tools such as poedit, all strings will be translated. If you save it, poedit is Create MO version. Ultimately, WordPress is highly compressed for efficiency. Use Mo version. It’s all great, but at the beginning. How to create a pot file? There are several ways. It was initially recommended to use poedit. Install the open poedit, then navigate to file > new directory and enter details. Switch to the next label (source path) under the attribute of partial composition directory and set the path. The way is. The location of the pot file must be relative. If you are using a plug-in and the catalog file is a language, the\/ Must be used. You must set the features to verify on the source keywords tab. If you only use basic functions, you can add \u and \u e, but it is best to add them all. ‹ click \

Author:

Leave a Reply

Your email address will not be published. Required fields are marked *