Skip to main content
Internationalization (i18n) is essential for making your blocks and editor components accessible to users worldwide. The @wordpress/i18n package provides client-side localization utilities.

Installation

Install the package:

Basic Usage

Import and use translation functions:
Always include a text domain as the last parameter to ensure your translations don’t conflict with other plugins or themes.

Translation Functions

__()

Translate a string:

_x()

Translate with context for disambiguation:
Use _x() when the same English word has different meanings. The context helps translators provide accurate translations.

_n()

Handle singular and plural forms:

_nx()

Combine plural forms with context:

Using sprintf()

Format strings with placeholders:

Block Editor Examples

Block Registration

Inspector Controls

Notices and Messages

RTL Language Support

Check if the current locale uses right-to-left text:
Use isRTL() to adjust layouts and styles for right-to-left languages like Arabic and Hebrew.

Advanced Usage

Checking for Translations

Custom I18n Instance

Setting Locale Data

Best Practices

  • Always use a unique text domain for your plugin or theme
  • Keep translatable strings simple and avoid complex concatenation
  • Provide context with _x() for ambiguous terms
  • Use placeholders with sprintf() instead of string concatenation
  • Never split sentences across multiple translation calls
  • Include translator comments for complex strings

Good Examples

Bad Examples

PHP Integration

Load JavaScript translations in PHP:

Resources