I have ready website built with Bitrix CMS. Now I want to add couple of other languages to the website. Where can I set the multilanguage property for the website?
-
__Nowhere__. There's no such property. – u_mulder May 30 '19 at 14:30
1 Answers
It is possible. If everything is custom for you, then you need to do it by changing the program code of the site. I will describe the option when a version of a site with a different language is on the same server in one section (< domain of the main language >, < domain of the main language > / < code of another language > / - version of the site with a different language).
You need to add the settings in the administration panel:
- make new languages in - “Regional settings”;
- make new sites by selecting the languages created above and indicating the site section. (this is described here https://training.bitrix24.com/support/training/course/?COURSE_ID=68&LESSON_ID=6214)
For example, the second language will be in the section of the current site as /es/.
It is necessary to change the site code:
all texts that are in the component templates (if custom) should be placed in the sections /lang/es/template.php or /lang/en/template.php (each component has such folders, or create them) or /lang/ru/template.php (depending on how many sites are created in the admin panel), in these files the words are set like this
$MESS['TITLE'] = '...';
and in the template you can output like this
<?=GetMessage("TITLE")?>;
you need to create a second version of the site in the /es/ section, you can simply create the same sections and index.php files by specifying in them, for example, for the /es/index.php file
<? require ($_SERVER["DOCUMENT_ROOT"]."/index.php");
that is, the pages in all versions of the site will be the same (the same components will be launched).
The language change depends on which site is opened from which section, bitrix sets the global variable LANGUAGE_ID in which there will be the language code of the current site (specified in the admin panel), if we are in the /es/ section, then in the LANGUAGE_ID there will be “es” (if we are in section /ru/ then LANGUAGE_ID will be “ru”). So you can check the current language in the code.
If in the admin panel, in the information blocks, data is set that is displayed on the site or where they are collected from the site, then you need to create the same data for another version of the site (just checkmarks in the setting of the information block). Or to come up with something of your own, you can make a subscript to the code of the information block of the _es type, and in the code check LANGUAGE_ID to search for the necessary information block.
An example of how to implement it in the code can be found here https://github.com/ssv32/site-asisg.ru-web, this is not an ideal implementation, but you can follow the train of thought. (in this case, the information blocks are the same, but the elements have a list type property that determines which language the data is for, and the code is filtered by this property)

- 56
- 1
- 1
- 4