extends | title | group | subgroup | prev | next | order |
---|---|---|---|---|---|---|
docs |
Handling translations |
Basics |
Setup |
adding-theme-supports |
using-service-container |
4 |
It is better to make your theme multilanguage ready. To help you with that starter comes preconfigured and ready for translating.
Your translation .po
and .mo
files should be stored in resources/languages
directory.
Translations are loaded by load_textdomain()
function inside app/Setup/support.php
component.
Project textdomain string can be configured inside config/app.php
file with textdomain
option.
When project translations are properly loaded you can start making your theme multilanguage ready. You can retrieve sentences from language files using the __
gettext function.
echo __('Hello world!')
Note! Instead of explicitly entering your project textdomain string you should take advantage of theme configuration. Use config()
helper function to pull textdomain directly from config/app.php
file.
use function Tonik\Theme\App\config;
echo __('Hello world!', config('textdomain'))
Inside resources/languages
directory you will find tonik.pot
. This is a template file for your new translation. Open it with an editor of your choice (like Poedit) and translate available sentences.