Encodera

Thanks for reading!

Donate to the site — we work hard for you.

Contents

Language files

A language file holds all the texts of one page: the heading, labels, button captions, error messages. Texts are not written in the controller or the template — then the shop can be translated by adding a file, without touching the code.

Where it lives

Storefront language files are in catalog/language/, one folder per language. The path inside repeats the path of the controller:

catalog/
├── controller/information/hello.php
└── language/
    ├── en-gb/information/hello.php
    └── de-de/information/hello.php

en-gb is the language installed with the shop.

Creating the file

Create catalog/language/en-gb/information/hello.php by hand:

// catalog/language/en-gb/information/hello.php
$_['heading_title'] = 'Hello';
$_['text_welcome'] = 'Welcome to our shop!';

The file fills the array $_: the key is used in code, the value is shown to the visitor. In the real file the first line is the <?php tag.

Loading in the controller

// catalog/controller/information/hello.php
public function index(): void
{
    $this->load->language('information/hello');
 
    $this->response->setOutput($this->language->get('text_welcome'));
}

Open index.php?route=information/hello — the page shows «Welcome to our shop!». load->language() reads the file of the current language, language->get() returns the text by key. If the key is missing, get() returns the key itself — the page will show text_welcome.

Text with a value

A place for a value is marked with %s and filled with sprintf():

// in the language file
$_['text_hello'] = 'Hello, %s!';
 
// in the controller
$text = sprintf($this->language->get('text_hello'), 'Anna');

$text contains «Hello, Anna!».

Key prefixes

The core uses the same prefixes everywhere, and it is convenient to follow them:

PrefixWhat for
heading_Page heading
text_Ordinary text
entry_Label of a form field
button_Button caption
column_Table column heading
error_Error message

A second language

The language itself is added in the admin panel: System → Localisation → Languages. For your page, create the same file in the folder of that language:

// catalog/language/de-de/information/hello.php
$_['heading_title'] = 'Hallo';
$_['text_welcome'] = 'Willkommen in unserem Shop!';

Open index.php?route=information/hello&language=de-de — the page shows the German text.

Common mistake

The file is created only for one language, and on the other language the page shows keys like text_welcome instead of texts. Whether the engine falls back to en-gb depends on the release, so create the file for every language installed in the shop.

Thanks for reading!

Donate to the site — we work hard for you.