Internationalization is building your plugin that can be translated into other languages.
How to implement internationalization in the theme and plugin?
The text in the theme should be given as an argument through one of the localization functions in WordPress rather than being hardcoded in the theme for ease of translation.
A step-by-step guide is provided below that includes how to implement i18n:
1. Prepare your code for localization
All hardcoded strings and texts should be replaced with functions allowing translation.
For that, use functions like _e() and _().
2. Load text domain
First, load the text domain in your theme or plugin for the translation. This will instruct WordPress to load and use specific translations. Add the following code in your plugin’s main file or your theme’s function.php file.
The text domain name needs to be lowercase, with dashes instead of underscores.
Example:
3. Domain path
The domain path specifies where a plugin's translation will be stored. This serves a number of purposes, chief among them being the ability for WordPress to locate the translation even when the plugin or theme is turned off. The default value for this is the folder where your plugin is l located.
For instance, the domain path must begin with the first slash and be expressed as follows if the translation is in the plugin's /languages folder:
4. Loading translation
WordPress stores that translation in .po and .mo files. They can be loaded using load_theme_textdomain($domain, $transaltion_directory) and load_plugin_textdomain($domain, $transaltion_directory).
This loads either {text-domain}-{locale}.mo from the WordPress theme language folder in /wp-content/languages/themes/ or locale. mo file from the base directory of your theme.
This code includes in your theme’s function.php
5. Update wp-config.php file
Edit your wp-config.php file, and add define(WPLANG, language).
Remember to update your translations when you make changes to the strings that can be translated in your theme or plugin. You must keep your translations current to give your users a seamless multilingual experience.
Comment