WordPress Translation Ready Reference Guide

Quick Reference:

e is for echo
x is for context
n is for plurals

# Translate Strings:

__()Retrieve a translated string.
_e()Display a translated string.
_x()Retrieve a translated string with context.
_ex()Display a translated string with context.
_n()Retrieve a plural or singular form based on amount.
_nx() – Hybrid of _n() and _x(). Supports context and plurals.


# Examples:

__()

Retrieve a translated string.
echo __( 'Hello.', 'text-domain' );

_e()

Display a translated string.
_e( 'Hello.', 'text-domain' );

_x()

Retrieve a translated string with context.
echo_x( 'post link', 'A link to the post', 'text-domain' );

_ex()

Display a translated string with context.
_ex( 'post link', 'A link to the post', 'text-domain' );

_n()

Retrieve a plural or singular form based on amount.
echo _n( 'There is a comment', 'There are comments', get_comments_number(), 'text-domain');

_nx()

() – Hybrid of _n() and _x(). Supports context and plurals.
_nx( '%s Comment', '%s Comments', get_comments_number(), 'comments title', 'text-domain' )


#  Using sprintf & printf:

Using sprintf
echo sprintf( __( 'You have chosen the %s theme.' ) , $color )

Using printf
printf( __( 'You have chosen the %s theme.' ) , $color );


# Only Register Strings:

Only register strings for Translation don’t translate them.

_n_noop() – Register plural strings in POT file. But, don’t translate them.
_nx_noop() – Register plural strings with context in POT file. But, don’t translate them.

translate_nooped_plural() – Translate the result of _n_noop() or _nx_noop().


More Details @see https://codex.wordpress.org/I18n_for_WordPress_Developers