Translation Ready Themes & Plugins

Advertisement

Quick Reference: Quick Reference:

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

Top ↑

# Translate Strings: # 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' );

Top ↑

_e() _e()

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

Top ↑

_x() _x()

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

Top ↑

_ex() _ex()

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

Top ↑

_n() _n()

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

Top ↑

_nx() _nx()

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


Top ↑

#  Using sprintf & printf: #  Using sprintf & printf:

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

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


Top ↑

# Only Register Strings: # 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