English is the most illustrated language, used over the Internet, but still there are thousands of other languages available in the World. It is important to add all languages over the internet.
Over the past few years, the demand for transferable themes and plugins is increasing. Therefore, it is necessary to create transferable WordPress themes to facilitate the Worldwide WP users.
If you want to release a theme publicly, then you should consider the localization. Translations are usually carried about by making the use of special code in your WP theme. This file encompasses the actual translations and you can develop one for any language.
Terms like Internationalization and localization are used to translate WordPress in any other languages for web users from assorted locales who use disparate dialects and different languages other than English.
Through this blog, you will learn how to transfer the WordPress theme for any language. You need to follow the following steps:
You can paste the following lines of coding on your functions.php file.
In the first line, you can see the load_theme_textdomain() function. It enables you to load a Text Domain. It gives you the liberty to choose any name but remember it should be unique and different.
Use the php gettext functions to translate WordPress theme. GetText has two functions: _e and __. The _e function is used to print simple text, while __ function is used when the text to be showcased is already covered in PHP tags. Refer to below code block for example:
The worst part is that you need to replace each string by the required function. And this process can take a lot of time as it completely depends on how many strings have been used in the theme.
You can easily translate your WP theme into any language, but to display text in a foreign language, you need to add a .po file. This file stands for Portable Object that incorporates a string, and its translation in another language.
The best part is that you need to find your theme files for all strings that need to be translated. With the help of icanlocalize.com, you can scan all PHP files and create .po files. Then, it will extract all strings enveloped in __("txt", "domain") and _e("txt", "domain") calls.
With the help of POEdit, you can edit the PO files. It is free software which is designed for this particular task.
You have to translate each text string and after this, you can save the .po file.
The last step is to define your WP locale. And, you can do it by getting your language and country code.
If your language is French and France is your residential Country, then your code will be fr_FR. With the support of GNU get text manual that contains pages, will help you find both the Country and language code.
After getting language codes open your wp-config.php file and hunt for the WPLANG constant. If it is available then replace the current code by yours and if it doesn’t exists, then paste the following line with your code.
That was quick and easy, do share your views for the same.