Word press development for intermediate users: Internationalization

Internationalization or I18N is the process of developing plug-ins or themes and making them easy to translate into other languages. WordPress is used all over the world, so it is important to ensure that the code can be easily translated into all the required languages. This is the seventh post in the WordPress development series for intermediate users. This series is the follow-up part of the WordPress development tutorial. It introduces the basic knowledge of developing websites with WordPress, the method to start coding with PHP, and the construction method of topics and plug-ins. In the last post in the intermediate series, you will learn how to prepare code translations for users or how to internationalize code. The
To work together, you must have themes and \/ or plug-ins. Continue to use the code developed in the series or from the source file. Part 6: develop word press for intermediate users: code that requires custom fields and metadata. The last tutorial in this series will do three things. Learn about internationalization and what it is. Prepare to use some word press features to translate code. In WordPress, create a text field for translating code. Let’s start with an overview of translation and internationalization. Have you missed the word press development series for intermediate users? Here, you can view all 7 posts. The
WordPress development for intermediate users: detailed topic development for intermediate users WordPress development for intermediate users: WordPress development for intermediate users: WordPress development for plug-in building intermediate users: WordPress development for user-defined post types and classification intermediate users: query and cycle intermediate companies Word press development for users: word press development for intermediate users of custom fields and metadata: translate text on the internationalization overview front end and management screen, allowing more listeners to access topics or plug-ins. According to Wikipedia statistics, 54% of websites are in English, 26% of Internet users use English, and 21% of Chinese users are very close. In contrast, only 3% of websites are in Chinese. The results of scanning wordcamps in the past show that WordPress developers are all over the world, such as Europe, India, Nepal, Japan and so on. The
Many non English developers and Internet users are used to coding or reading in English, but this is not ideal. Allow code translation to open plug-ins, themes, and client sites to a wide range of rapidly growing global prospects. Translation is not difficult. Just use some of the features provided by WordPress. Note: do not translate the code. In the browser, you can always read American English. What you want to translate is the public websites that use your themes and plug-ins and the text that appears on all the management screens you create or modify. The
It is easy to confuse the two terms used in translation (localization and I18N). You can find a lot of tutorials and articles using wrong terms online. Two terms can be defined as: Internationalization is a process that allows you to translate code using the relevant word press functions performed here. Localization is a process performed by translators to translate code into the user’s language. You don’t have to do that. If your users need it, they will. Let’s take a look at the method of code internationalization. In internationalization, there are 18 characters between \
Preparing the code for translation consists of three steps. Internationalize text using word press features
whole Load the text field. Generate language files. Start with skills. Internationalization functions word press uses four main functions to internationalize text__ (\
Our topic has two files that already contain internationalized text. Custom machine. PHP functionality. There are also eight files that contain text that requires PHP internationalization. loop PHP ring – single. PHP loop project. PHP archive. PHP Archive Project. PHP classification service. Php search. PHP 404 Let’s take a look at the different I18N features of PHP in turn and look at them__ Use the () function to translate text \u () function to translate text, but it is not environmentally friendly. Used to define text strings used elsewhere. Our topic contains some files that have been executed when defining the administrator screen text. The
Let me give you an example. Customizer PHP has the following code: The load summary a24151f5a8557bfcf2c594c57abbbbbd2 uses the \\u () function to translate the names of the sections generated by this function in the customizer__ The () function has two parameters: the text to be translated and the text field. Use wpmu in all files, and set wpmu after adding all functions. Customr After scrolling through the PHP file, you will see that the \u () function is used in different places. The
Next is the other file functions with internationalized existing code. Let’s take a look at PHP. In the code for registering components, you can find the following: Load summary a24151f5a8557bfcf2c594c57abbbd2 use the __ () function again. Now we will go to the project archive template. Archive project Open the PHP file and look for the next line. The load summary a24151f5a8557bfcf2c594c57abbbd2 contains some static text inside the filter. Let’s set the text up for translation. Edit code: The
Load summary a24151f5a8557bfcf2c594c57abbbd2 as the second parameter, and add the I18N function in the apply_filters() function. Using the printf() function with placeholders uses the printf() function to internationalize more complex text, including variable values added to the text to be translated with placeholders. To do this, three actions must be performed. Defines the variable used for placeholder text. Create the printf () function with internationalized text as the first parameter and variables as subsequent parameters. Internationalize the text in the first argument of a function using a correlation function. Add placeholders to the text to be translated into the same order as the variables added as parameters. It’s hard to explain, but first of all, from the perspective of action, you will understand it better. The
Let’s use printf () to internationalize some of the text on the front end of the site. Loop You must start translating this code from PHP. Load summary a24151f5a8557bfcf2c594c57abb
BBD 2 the specific location that needs to be translated is the title attribute of the link. Modify the code to display as follows: The load summary a24151f5a8557bfcf2c594c57abbbd2 uses the printf() function again because we work with placeholders. Let’s take a closer look. The first argument to the printf() function is the esc\u attr\u() function used to translate text. There are two parameters. Text (placeholder%s) and text field wpmu. The second parameter is the value of the placeholder text (imported by the_title_attribute()). It has an echo=0 parameter. Because we don’t want to reverse it, we just want to get it back. Now it’s loop The change to the PHP file is loop project. Repeat with the same code in the PHP file. Loop-single You can also find the same code in the PHP file. The title of an individual file is linked to itself, so the link to the title is removed from the file. If blocked, check the source file_ The text translated using the E () function is now loop in reverse. You are ready to translate the PHP file, and you can close it. But loop single. PHP and loop project. PHP has more code to translate. Loop-single Open PHP and find the following code: Load the summary a24151f5a8557bfcf2c594c57abbbd2. Use the_terms() function to output the term list of the current post. Let’s edit the function instead of inside it and add translated text before it. Where \u e() will be used. Because they not only want to import the translated text, but also want to echo. Edit the text to read: Load summary a24151f5a8557bfcf2c594c57abbbd2 now loop project. Open the PHP file and make the same changes. I won’t tell you about it, but if you need it, you can look at the series of files. Finally, loop single In the PHP file, locate the entry meta Div. You must use the load summary a24151f5a8557bfcf2c594c57abbbd2_e() function and the printf() function that we have already looked at. When the code is complete, the following is displayed: Let’s learn more about the operation performed by the corresponding code of the load summary a24151f5a8557bfcf2c594c57abbbd2. The condition label has been moved outside the entry meta Div. This is to avoid being displayed in a single post, not in a post type. Variables that define the author name, author archive link, and date. All of these functions use the function started by get_, so there is no echo, just import from the database. Added printf() function. The first parameter is the \u () translation function containing the place holder. This is because esc\u attr() instead of esc\u attr() uses \u() to include HTML in esc\u attr() output. The three final parameters are variables, the values of these placeholders. We get the category of the current post, assign it to the $cats variable, and then check whether the variable has content (that is, whether there are categories)_ Translated the text before the category list using E (). Although the_terms() similar to the untranslated version is used, the translated static text is deleted. Repeat steps 4 through 6 for the marking. Since no translation files have been added, it is recommended that you check the individual posts to ensure that the site has not changed but is still valid in the default language. Nothing should change. Male therefore, it is edited to include I18N
Circular file. Next archive. Open the PHP file. Find this line. The function to be used in the loading summary a24151f5a8557bfcf2c594c57abbbd2 is \u e() again. Apply what you have learned so far and add functions directly without my guidance. If blocked, check the source file (7 files required). Problem: when accessing the creator template and testing the archive template, you may find that the creator name is missing. However, it works well in tag and category archives. Archive to display the author name. Edit the PHP file. Alternatively, author is used to display the author archive. Create a PHP file. If blocked, check the source file. Prompt: archive. If you work in PHP, you need conditional tags. In both cases, $title->display\u name must be used. Where $title is based on the object Archive of the current query. PHP defined variables. Authors also output author profiles and web site links. Created a PHP template. Can be found in the source file. There is another archive template that needs to be internationalized: our taxonomy service. PHP file. Open it and find the next line. Load summary a24151f5a8557bfcf2c594c57abbbd2 this is our archive. This is similar to the line you edit in your PHP file, so it looks familiar. Please apply the actions performed here to the file as well. If there is a problem, check the source code. Search now. PHP and 404. Only PHP files are left. Both have static text inside the title and \/ or paragraph. Translate this text using the \u e() function learned so far. This is a good way for you to practice. If you follow, it will be very simple. In other words, if there is a problem, refer to the source file for this part (Part 7) of this series. Note: 404. In PHP, you must use special characters in the suffix. The HTML special character of postropi is \
Use the defined variable as a placeholder. The plug-in for registering custom post types and categories has added I18N, which can save work. Because you need to use the topic technologies already shown, we won’t cover each topic in detail. Apply what you have learned to plug-in internationalization. As always, if there is a problem, you can reference the source file. After all I18N features have been added to the theme and plug-in, you can add text fields. The text field settings are now ready for all I18N functions. In the future, when you create code using the methods learned here, you should write it into the code. It’s much easier to go back to my experience than to add it all later. But it’s not over yet. The next step is to add text fields to the theme and plug-in. Remember to add the second parameter to the \

Author:

Leave a Reply

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