Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Latest commit

 

History

History
39 lines (26 loc) · 1.35 KB

handling-translations.md

File metadata and controls

39 lines (26 loc) · 1.35 KB
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.

Configuration

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.

Translation Strings

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'))

Translating

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.