Internationalization in WordPress

According to a research around 37% of WordPress downloads are for non-English, localized versions. So plugin or theme author should be thinking of localization and internationalization (L10N and I18N). Internationalization is the process of developing your theme or plugin so it can be easily translated into other languages.

WordPress used all over the world and it is the good idea to prepare WordPress theme and Plugin so they can easily translated on other languages. It is impossible to localize individual theme on individual language. So if Theme and Plugin is translation ready, user can use their own language .mo file for theme and plugin translation.

Internationalize Theme and Plugin
There are various WordPress fucntion which help internationalize your theme and plugin. Each function have their own working and importance. Use the appropriate function to make string translation ready.

Text Domain:
Text domain denote all text belonging to that theme or plugin. The text domain is unique identifer, which help WordPress to distinguish between all loaded translations. The text domain must match with Theme or Plugin Slug. For example If your theme or plugin name is style.css is ‘WEN Solution’ your text domain should be wen-solutions, and folder of theme or plugin must be same as text domain.
Example :

__($text, $text-domain);
__('Text for making translation ready', 'wen-solutions');

Text domain should be loaded on functions file and .mo file should be kept on languages folder of theme or plugin root folder.

function my_theme_load_theme_textdomain() {
load_theme_textdomain( 'my-theme', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
add_action( 'after_setup_theme', 'my_theme_load_theme_textdomain' );

Some available function with example are listed below:
1. __();
The most commonly used function for translation is __();. It returns the translation of argument:

__('Make string translatable', 'wen-solutions');

2. echo __();
This output the translation of argument.

echo __('Make string translatable', 'wen-solutions');

You can use shortform of it like,

_e('Make string translatable', 'wen-solutions');

3. printf();
If variables are used in strings, you need to use placeholders.

printf(__( 'Your city is %s.', 'wen-solutions' ),$city );

If more than one placeholder is used, used argument swapping.

printf(__( 'Your city is %1$s, and your zip code is %2$s.', 'my-theme' ),$city,$zipcode);

4. _n();
If a string that changes when the number of items changes then _n() function is used. For example, in english you have ‘One Post’, ‘Two Post’ and in other language you have multiple plural form. At that time this function is used.

printf(_n('One comment','%s comments',get_comments_number(),'wen-solutions'), number_format_i18n( get_comments_number() ));

5. _n_noop();
This function is used when to keep structures with translatable plural strings and use them later.

$comments_plural = _n_noop('One comment.','%s comments.');

6. _nx_noop();
Register plural string with contexts in POT file but don’t translate them.

_nx_noop( 'One Comment', '$s comments', $context, 'wen-solutions');

7. translate_nooped_plural();
Translated the result of _n_noop(); or _nx_noop();

$messages = array(
'post' => _n_noop('%s post', '%s posts'),
'page' => _n_noop('%s pages', '%s pages')
$message = $messages[$type];
$usable_text = sprintf( translate_nooped_plural( $message, $count, 'wen-solutions' ), $count );

8. _x();
Retrieve translated string with similar translatable text found in more than two places but with different translated context. For Example if Same word came as a Noun in one place and as a verb in another place.

_x( 'Post', 'noun', 'wen-solutions' );
_x( 'post', 'verb', 'wen-solutions' );

9. _ex();
Echo version of _x().

_ex( 'Post', 'noun', 'wen-solutions' );
_ex( 'post', 'verb', 'wen-solutions' );