5/28/2023 0 Comments Wordpress domainer pluginsThis is how other plugins make their plugins translation ready. By using this domain, it will allow us to later translate our text into any language. The above code should be written in the following way: Īs can be seen in the above examples, the second parameter was written as ‘udp’, which is our plugin text domain. If it is in HTML then use the code: _e(). ![]() The general rule is that if you are printing text using PHP echo then you should wrap text in the following code: The first is wrapped in HTML directly and the second is displayed using PHP echo function. In our plugin code, we normally have two types of text. Both methods work exactly the same but there is a rule for using both. Use of _() and _e() MethodsĪs we are aiming to make our plugin available in all languages, we should wrap all our plugin text inside either: This code keeps our translation files ready on the WordPress initialization. The third parameter is the path of our ‘languages’ directory. We should keep this domain name as per our name of the plugin. In the above code, we keep the first parameter (domain) as ‘udp’. '/languages/' ) Īdd_action( 'init', 'plugin_load_textdomain' ) Load_plugin_textdomain( 'udp', false, basename( dirname( _FILE_ ) ). Next, add the below code to your plugin main file. In your plugin folder, create a directory called ‘languages’. It may seem a little confusing, but keep reading and we’ll explain how it works shortly.įirst, let’s take a look at how to add this function to our plugin code. This code will load the plugin’s translated strings. ![]() When creating a plugin, we should make sure that we load the plugin text domain. For example, if we wanted to translate a plugin into French, the following steps will allow plugin translation and also make it ready for all supported WordPress languages. ![]() The purpose of this blog is to demonstrate to our readers how they can code a plugin so that it will be localized and translated into any supported WordPress language. These are some of the most popular plugins available and are coded in a way that allows anyone to translate them easily into their native language. You will find this option is available with UpdraftPlus, MetaSlider, WP-Optimize, Contact Form 7 and WooCommerce, as well as many more. If you were wondering how important a translation option is, you can check the repository and see that every single popular plugin is available for language localization. When developing a plugin, it’s always good idea to make it translation ready as it could additionally reach audiences who do not use English as their first language.
0 Comments
Leave a Reply. |