Documentation

loadMessages

 public static
\Bitrix\Main\Localization\Loc::loadMessages(
 string $file
);

Static method defines, into which file you would like to upload language files in the future. Searching for the folder and connecting language file will occur only when required, when calling Loc::getMessage (or function GetMessage from the old core, which calls Loc::getMessage).

Loc::getMessage searches the first folder /lang in the file tree top levels relative to the passed file.

Similar to methods IncludeModuleLangFile and IncludeTemplateLangFile from the old core.

Parameters

ParameterDescriptionVersion
$fileFile.

Example

Method application to site files outside of modules and templates. The method Loc::loadMessages is more practical, than both IncludeModuleLangFile and IncludeTemplateLangFile from the old core. The old functions clearly specify, where to search the folder with lang-files: in the module's root or in template root. Loc::loadMessages can search for other folders.

Example of folder tree:

local
   php_interface
      askaron
         tools.php
      lang
         ru
            askaron
               tools.php
            init.php
            test.php
      init.php
      test.php

Take any file. For example, init.php

File /local/php_interface/lang/ru/init.php.

<?
$MESS["HELLO_WORLD"] = "Hello, world";
?>

File /local/php_interface/init.php

<?
use Bitrix\Main\Localization\Loc;
Loc::loadMessages(__FILE__);

function getHelloWorld()
{
   return Loc::getMessage('HELLO_WORLD');
}
?>

Similar structure

use Bitrix\Main\Localization\Loc;
Loc::loadMessages(__FILE__);

will work in test.php and in askaron/tools.php.



© «Bitrix24», 2001-2024
Up