Translations in PHP files work straight-forward. Translations functions such as `__()` and `_n()` are part of the WordPress core. Therefore, they are available globally and do not have to be imported.
## Usage of localization functions
### `__()`
The function `__()` retrieves the translation of `$text`. This function is available both for PHP & JS/TS.
_ex( 'Place Order', 'Place order button text', 'woo-gutenberg-products-block' );
```
See also <https://developer.wordpress.org/reference/functions/_ex/>.
### `_n()`
The function `_n()` translates and retrieves the singular or plural form based on the supplied number. This function is available both for PHP & JS/TS.
See also <https://developer.wordpress.org/reference/functions/_x/>.
### `_nx()`
The function `_nx()` translates and retrieves the singular or plural form based on the supplied number, with gettext context. This function is available both for PHP & JS/TS.
esc_html_e( 'Select a category', 'woo-gutenberg-products-block' );
```
See also <https://developer.wordpress.org/reference/functions/esc_html_e/>.
### `esc_html_x()`
The function `esc_html_x()` translates a string with gettext context, and escapes it for safe use in HTML output. This function is only available for PHP.
See also <https://developer.wordpress.org/reference/functions/esc_attr_e/>.
### `esc_attr_x()`
The function `esc_attr_x()` translates the string with gettext context, and escapes it for safe use in an attribute. This function is only available for PHP.
🐞 Found a mistake, or have a suggestion? [Leave feedback about this document here.](https://github.com/woocommerce/woocommerce-blocks/issues/new?assignees=&labels=type%3A+documentation&template=--doc-feedback.md&title=Feedback%20on%20./docs/internal-developers/translations/translations-in-PHP-files.md)