Views: 6533 (Data available since 06.02.2017)
Language file - is a PHP script storing translations of language phrases to a foreign language. This script consists of the $MESS array that keys are identifiers of language phrases and values are translations to the relevant language.
Language files are not mandatory.
Example of a language file for the German language:
$MESS ['SUP_SAVE'] = "Speichern";
$MESS ['SUP_APPLY'] = "Anwenden";
$MESS ['SUP_RESET'] = "Zurücksetzen";
$MESS ['SUP_EDIT'] = "Bearbeiten";
$MESS ['SUP_DELETE'] = "Löschen";
Example of a language file for the English language:
$MESS ['SUP_SAVE'] = "Save";
$MESS ['SUP_APPLY'] = "Apply";
$MESS ['SUP_RESET'] = "Reset";
$MESS ['SUP_EDIT'] = "Change";
$MESS ['SUP_DELETE'] = "Delete";
Each language has its own set of language files stored in subcatalogs /lang/ (for more details please refer to the documentation system file structure and module file structure).
Language files are normally used in the administrative scripts of modules or in the components and it defines which of the following functions is used to connect them:
In order to make searching more convenient and to modify the language phrases further, the page parameter show_lang_files=Y, can be used, which permits you to quickly locate and correct any language phrase using means of the module Localization.
Language Files in Own Components
When creating own component the path to the language file must look as follows:
Where the language code, for example, = lt.
In this case language files will be connected automatically.
The following function can be used to connect to the component language messages of another component:
function IncludeComponentLangFile ($abs_path, $lang = false)
if ($lang === false) $lang = LANGUAGE_ID;
$filepath = rtrim (preg_replace ("'[\\\\/]+'", "/", $abs_path), "/ ");
if (strpos ($filepath, $BX_DOC_ROOT) !== 0)
$relative_path = substr ($filepath, strlen ($BX_DOC_ROOT));
if (preg_match ("~^/bitrix/components/([-a-zA-Z0-9_\.%]+)/([-a-zA-Z0-9\._%]+)/templates/([-a-zA-Z0-9\._%]+)/(.*)$~", $relative_path, $matches))
$lang_path = $BX_DOC_ROOT."/bitrix/components/$matches/$matches/templates/$matches/lang/$lang/$matches";
if (preg_match ("~^/bitrix/components/([-a-zA-Z0-9_\.%]+)/([-a-zA-Z0-9\._%]+)/(.*)$~", $relative_path, $matches))
$lang_path = $BX_DOC_ROOT."/bitrix/components/$matches/$matches/lang/$lang/$matches";
Replacement of Language Phrases of a Product
Sometimes the development of a website requires that some words or phrases be changed in components or modules.
Let us look into this technique wherein the bottom line is that after a language file is connected, product phrases are replaced with those determined by the developer.
File path is replaced:
Note: If php_interface contains no required folders, they must be created.
The file must determine the elements of the array $MESS in the form $MESS['language file']['phrase code'] = 'new phrase', for example:
$MESS["/bitrix/components/bitrix/system.auth.form/templates/.default/lang/en/template.php"]["AUTH_PROFILE"] = "Profile";
$MESS["/bitrix/modules/main/lang/en/public/top_panel.php"]['top_panel_tab_view'] = "View";
$MESS["/bitrix/modules/main/lang/en/interface/index.php"]['admin_index_sec'] = "Pro&Pro";
The first line changes link text in the authorization form component; the second line changes the name of the public panel tab; the third line changes the name of the index page of the control panel.
Important! Problems may occur in file maintenance when a phrase code or language file location are changed.