Início / Optitravel / Core / Language
Use translations
Basic usage
To use the translation system we only need to call the following function:
<?php
echo __('module.translation');
// Tradução
The function argument is composed by: - module: the module file; - translation: the requested translation key
It will search the module.php file for the requested key and if it is not found, the return will be the argument itself, in this case, module.translation. This is usefull during development because it will not cause a fatal error if no translation found.
Passing variables
This system also allows passing variables to the translation system.
For a translation like this:
// pt/hotels.php
return [
'mapped_hotel_found' => 'Encontrado hotel mapeado: :hotel',
];
We can call it like this:
<?php
echo __('hotels.mapped_hotel_found', ['hotel' => 'Nome do Hotel']);
// Encontrado hotel mapeado: Nome do Hotel
The variables are passed as an array with key/value. The key must have the name of the variable found in the module file.
↑ (Última atualização: 10/04/2025)