public function onRun() { $translator = languageTranslator::instance(); $lang = $translator->getLocale(); $this->addJs('assets/js/slider.js'); $this->addCss('assets/css/slider.css'); $this->page['sliders'] = BaseSlider::showSliders($lang); }
public function boot() { /* * Set the page context for translation caching. */ Event::listen('cms.page.beforeDisplay', function ($controller, $url, $page) { if (!$page) { return; } $translate = Translator::instance(); $translate->loadLocaleFromSession(); Message::setContext($translate->getLocale(), $page->url); }); /* * Adds language suffixes to content files. */ Event::listen('cms.page.beforeRenderContent', function ($controller, $fileName) { if (!strlen(File::extension($fileName))) { $fileName .= '.htm'; } /* * Splice the active locale in to the filename * - content.htm -> content.en.htm */ $locale = Translator::instance()->getLocale(); $fileName = substr_replace($fileName, '.' . $locale, strrpos($fileName, '.'), 0); if (($content = Content::loadCached($controller->getTheme(), $fileName)) !== null) { return $content; } }); /* * Automatically replace form fields for multi lingual equivalents */ Event::listen('backend.form.extendFieldsBefore', function ($widget) { if (!($model = $widget->model)) { return; } if (!method_exists($model, 'isClassExtendedWith')) { return; } if (!$model->isClassExtendedWith('RainLab.Translate.Behaviors.TranslatableModel')) { return; } if (!is_array($model->translatable)) { return; } if (!empty($widget->config->fields)) { $widget->fields = $this->processFormMLFields($widget->fields, $model); } if (!empty($widget->config->tabs['fields'])) { $widget->tabs['fields'] = $this->processFormMLFields($widget->tabs['fields'], $model); } if (!empty($widget->config->secondaryTabs['fields'])) { $widget->secondaryTabs['fields'] = $this->processFormMLFields($widget->secondaryTabs['fields'], $model); } }); }
public function registerMarkupTags() { return ['filters' => ['hash' => function ($url) { $file = Theme::getActiveTheme()->getPath() . '/' . $url; if (is_file($file)) { return $url . '?' . filemtime(Theme::getActiveTheme()->getPath() . '/' . $url); } else { return $url; } }], 'functions' => ['lang' => function () { return \RainLab\Translate\Classes\Translator::instance()->getLocale(); }]]; }
/** * Scans the theme configuration for defined messages * @return void */ public function scanThemeConfigForMessages() { $theme = Theme::getActiveTheme(); $config = $theme->getConfigArray('translate'); if (!count($config)) { return; } $translator = Translator::instance(); $keys = []; foreach ($config as $locale => $messages) { $keys = array_merge($keys, array_keys($messages)); } Message::importMessages($keys); foreach ($config as $locale => $messages) { Message::importMessageCodes($messages, $locale); } }
public function boot() { /* * Set the page context for translation caching. */ Event::listen('cms.page.beforeDisplay', function ($controller, $url, $page) { if (!$page) { return; } $translator = Translator::instance(); Message::setContext($translator->getLocale(), $page->url); }); /* * Adds language suffixes to content files. */ Event::listen('cms.page.beforeRenderContent', function ($controller, $fileName) { if (!strlen(File::extension($fileName))) { $fileName .= '.htm'; } /* * Splice the active locale in to the filename * - content.htm -> content.en.htm */ $locale = Translator::instance()->getLocale(); $fileName = substr_replace($fileName, '.' . $locale, strrpos($fileName, '.'), 0); if (($content = Content::loadCached($controller->getTheme(), $fileName)) !== null) { return $content; } }); /* * Import messages defined by the theme */ Event::listen('cms.theme.setActiveTheme', function ($code) { try { (new ThemeScanner())->scanThemeConfigForMessages(); } catch (Exception $ex) { } }); /* * Prune localized content files from template list */ Event::listen('pages.content.templateList', function ($widget, $templates) { return $this->pruneTranslatedContentTemplates($templates); }); }
public function onRender() { $this->file = $this->property('file'); $this->fileMode = File::extension($this->property('file')); /* * Compatability with RainLab.Translate */ if (class_exists('\\RainLab\\Translate\\Classes\\Translator')) { $locale = \RainLab\Translate\Classes\Translator::instance()->getLocale(); $fileName = substr_replace($this->file, '.' . $locale, strrpos($this->file, '.'), 0); if (($content = Content::loadCached($this->page->controller->getTheme(), $fileName)) !== null) { $this->file = $fileName; } } if (!$this->isEditor) { return $this->renderContent($this->file); } $this->content = $this->renderContent($this->file); }
public function dateLocale($dateString, $dateFormat = '%c') { if (class_exists('RainLab\\Translate\\Behaviors\\TranslatableModel')) { $locale = Translator::instance()->getLocale(); $locales = ['ru' => "ru_RU.UTF-8", 'en' => "en_US.UTF-8"]; setlocale(LC_ALL, $locales[$locale]); } else { setlocale(LC_ALL, 'ru_RU.UTF-8'); } $dateString = strtotime($dateString); if ($locale == 'ru') { if ($dateFormat === '%c') { $dateFormat = '%e %h %Y г.'; } $months = explode("|", '|января|февраля|марта|апреля|мая|июня|июля|августа|сентября|октября|ноября|декабря'); $dateFormat = preg_replace("~\\%h~", $months[date('n', $dateString)], $dateFormat); } return strftime($dateFormat, $dateString); }
public function init() { $this->translator = Translator::instance(); }
/** * Initializes this class, sets the default language code to use. * @return void */ public function initTranslatableContext() { $translate = Translator::instance(); $this->translatableContext = $translate->getLocale(); $this->translatableDefault = $translate->getDefaultLocale(); }
/** * Adds language suffixes to content files. * @return string|null */ public function findTranslatedContentFile($controller, $fileName) { if (!strlen(File::extension($fileName))) { $fileName .= '.htm'; } /* * Splice the active locale in to the filename * - content.htm -> content.en.htm */ $locale = Translator::instance()->getLocale(); $fileName = substr_replace($fileName, '.' . $locale, strrpos($fileName, '.'), 0); if (($content = Content::loadCached($controller->getTheme(), $fileName)) !== null) { return $content; } }
<?php use RainLab\Translate\Models\Message; use RainLab\Translate\Classes\Translator; /* * Adds a custom route to check for the locale prefix. */ App::before(function ($request) { $translator = Translator::instance(); if (!$translator->isConfigured()) { return; } $locale = Request::segment(1); if ($translator->setLocale($locale)) { Route::group(['prefix' => $locale], function () use($locale) { Route::any('{slug}', 'Cms\\Classes\\Controller@run')->where('slug', '(.*)?'); }); Route::any($locale, 'Cms\\Classes\\Controller@run'); } }); /* * Save any used messages to the contextual cache. */ App::after(function ($request) { Message::saveToCache(); });
public function registerMarkupTags() { return ['functions' => ['trans' => function ($key) { return Lang::get('algad.bootstrap::lang.' . $key, [], Translator::instance()->getLocale()); }]]; }
/** * Check if the Rainlab.Translate plugin is installed * and if yes, get the translator instance. * * @return Translator|bool */ protected function translator() { return $this->isPluginAvailable('RainLab.Translate') ? Translator::instance() : false; }