Language files allow you to add your own lines of text in system languages and replace existing ones. It is forbidden to use text in hacks directly without language files.
Creating language files
Language files are created and edited on the "Language files" page by "Files" button in hack settings. Their names correspond to language codes - ru.php
for Russian and en.php
for English.
The language file must return an associative array of strings. The array key is the string identifier, the value is its composition in the selected language. It is recommended to start the keys with the name of the hack.
Language file example:
<?php return [ 'proxy_config_h' => 'Proxy configuration', 'proxy_config_t' => 'In this section, you can set up the configuration.', ];
Using in the code
To access a string by its ID, use the lang
array of the $core
object. This array is collected by concatenating all language files.
$core->lang['proxy_config_h']
Language file cache
With automatic updates and activation of hacks, the language cache is cleared automatically. If you're developing the hack yourself, you'll need to manually clear the cache when changing the language file.
Go to the "Management - Settings" section, click on the "Diagnostics" button. In the "Cache" section, find "Compiled Language Files" and click "Clear".
Adding a new language
You can add a new language to the system and make a full or partial translation. Your language file will be based on one of the base languages of the system - Russian or English. When updates are released, all new phrases will be automatically pulled from the base language. This approach allows you to translate only those sections that are used in your project.
The languages
handler is responsible for compiling the list of languages, which takes an array of languages as input:
Array key
: the symbolic language identifier, such asfr
for French orde
for German. The language files in your hack should have this name.name
- the name of the language that the user will see. It is recommended to use the self-name in the original language.base
- the language file that acts as the basis (ru
oren
).guess
- a string or an array of strings, the presence of which inAccept-Language
will automatically determine the language.
Example handler for adding a language:
function hack_pl_languages( $core, $lang ) { $lang['pl'] = [ 'name' => 'Polski', 'base' => 'en', 'guess' => 'pl' ]; return $lang; }
Don't forget to include the handler in your hack initialization function:
$core->handle( 'languages', 'hack_pl_languages' );