-
Notifications
You must be signed in to change notification settings - Fork 4
Localisation and internationalisation
You can read about internationalization at the I18n for WordPress Developers page in the WordPress codex.
If you are using Blade as your template language, or simply PHP, you can skip this article. However, if you are using Twig, those functions are not accessible by default, because of the way Twig works.
The L10N class within the plugin allows you to actually use those same functions within your .twig templates.
There are a couple of things you should have in mind:
As you probably saw in the codex, most internationalization functions look like this:
__( 'My string', 'my-theme-textdomain' )
The second argument, the text domain, can be quite annoying if you need to type it in each function within your template. Because of that, the framework supports a default text domain, which you can set through the rila.default_textdomain
filter, like this:
add_filter( 'rila.default_textdomain', 'my_theme_default_textdomain' );
function my_theme_default_textdomain( $domain ) {
return 'my-theme-textdomain';
}
If you copy that code in your theme, the __
example above becomes a bit shorter:
{{ __( 'My string' ) }}
In order to translate the string into a different language, you need to collect them first. Normally, this is done through gettext or another application, which utilizes it, like Poedit.
However, those applications are not meant to support .twig
files by default. There is an excellent article in Timber's documentation which covers this topic.
Next article: Shortcodes
- Overview
- The basics
- Data types
- Extending the framework
- Helpers
- Others/Advanced
- Performance