Loading...
Loading...
Covers Bitrix localization — Bitrix\Main\Localization\Loc, lang/<code/>/ language files, loadMessages, placeholders in getMessage, Context::getCulture() and culture formats, JS localization via BX.message and $Bitrix.Loc, translate:index for phrase indexing. Applied when adding and translating phrases, working with multi-language sites, JS translations in components and templates. Key terms — Loc, getMessage, lang file, Culture, BX.message, loadMessages, i18n.
npx skill4agent add bxmaximum/bitrix-framework-skills bitrix-localization.../lang/<lang>/<...>/local/modules/vendor.module/lib/Application/Service/PostService.php
/local/modules/vendor.module/lib/Application/Service/lang/ru/PostService.php
/local/modules/vendor.module/lib/Application/Service/lang/en/PostService.php<?php
$MESS['VENDOR_MODULE_POST_PUBLISHED'] = 'Post #NAME# published';
$MESS['VENDOR_MODULE_POST_EMPTY_TITLE'] = 'Post title is empty';<VENDOR>_<MODULE>_<CONTEXT>_<CODE>Loc::getMessageuse Bitrix\Main\Localization\Loc;
Loc::loadMessages(__FILE__); // knowing where we are — the kernel will find the translation file
echo Loc::getMessage('VENDOR_MODULE_POST_PUBLISHED', ['#NAME#' => $post->getTitle()]);
echo Loc::getMessage('VENDOR_MODULE_POST_PUBLISHED', ['#NAME#' => 'x'], 'en');Loc::getMessage(string $code, ?array $replace = null, ?string $language = null)#PLACEHOLDER#$replace$languageruenLoc::loadMessages(__FILE__)lang/<lang>/<same_file>.phpLoc::loadLanguageFile($path)__FILE__lang/<lang>/<same_file>.phpLoc::loadMessages(__FILE__)/local/php_interface/Loc::loadLanguageFile($_SERVER['DOCUMENT_ROOT'] . '/local/php_interface/custom.php');$lang = Loc::getDefaultLang(LANGUAGE_ID); // fallback from language settings: 'ru' → 'ru', 'ua' → 'ru'uakzruBX_MESS_LOGgetMessage(...)getMessage('FOO_BAR')/local/php_interface/init.phpdefine('BX_MESS_LOG', $_SERVER['DOCUMENT_ROOT'] . '/var/log/bitrix/mess.log');[ru]SOME_MESSAGE: not found for /path/to/file.php
CTranslateUtils::CopyMessage('DEMO_CODE', '/path/a.php', '/path/b.php');getMessageCultureBitrix\Main\Context\Culture$culture = \Bitrix\Main\Context::getCurrent()->getCulture();
$culture->getDateTimeFormat(); // 'DD.MM.YYYY HH:MI:SS'
$culture->getDateFormat(); // 'DD.MM.YYYY'
$culture->getShortTimeFormat(); // 'HH:MI'
$culture->getNameFormat(); // '#LAST_NAME# #NAME# #SECOND_NAME#'
$culture->getNumberDecimals();
$culture->getNumberDecSeparator();
$culture->getNumberThousandsSeparator();use Bitrix\Main\Type\DateTime;
$date = new DateTime();
echo $date->format($culture->getDateTimeFormat());
// Via classic helpers:
echo \FormatDate($culture->getDateFormat(), $date->getTimestamp());
echo \CurrencyFormat(1234.5, 'RUB');BX.message(...)\Bitrix\Main\Page\Asset::getInstance()->addString(
'<script>' . \Bitrix\Main\Web\Json::encode([
'VENDOR_POST_SAVE' => Loc::getMessage('VENDOR_POST_SAVE'),
'VENDOR_POST_CANCEL' => Loc::getMessage('VENDOR_POST_CANCEL'),
]) . '</script>'
);config.phpreturn [
'js' => 'script.js',
'css' => 'style.css',
'rel' => ['main.core'],
'lang_additional' => [
'VENDOR_POST_SAVE', 'VENDOR_POST_CANCEL',
],
];BX.message('VENDOR_POST_SAVE');
BX.message({ VENDOR_POST_DYNAMIC: 'Loaded asynchronously' });
const welcome = BX.message('WELCOME_TEXT').replace('#NAME#', userName);// template
<button>{{ $Bitrix.Loc.getMessage('UI_BUTTON_SAVE') }}</button>
// with replacement + reactivity
{{ $Bitrix.Loc.getMessage('DEMO_COUNTER', { '#COUNTER#': this.counter }) }}
// programmatically
this.$Bitrix.Loc.setMessage({ DEMO_COUNTER: 'Counter: #COUNTER#' });
// optimization for heavy templates — (vueInstance, phrasePrefix, phrases?)
import { BitrixVue } from 'ui.vue3';
computed: {
localize() { return BitrixVue.getFilteredPhrases(this, 'MYCOMP_'); }
}translate:indexphp bitrix/bitrix.php translate:indexlang/ru/lang/en/lang/de/install/index.phpLoc::loadMessages(__FILE__)Loc::getDefaultLang(LANGUAGE_ID)rukzua.settings.phpErrorLoc::getMessagegetMessage('CODE')BX_MESS_LOGdate('d.m.Y')Culture::getDateFormat()lang/htmlspecialcharsbxdefault_language.settings.phpbitrix-vue