public function onRun() { if ($redirect = $this->redirectForceUrl()) { return $redirect; } $this->page['locales'] = $this->locales = LocaleModel::listEnabled(); $this->page['activeLocale'] = $this->activeLocale = $this->translator->getLocale(); $this->page['activeLocaleName'] = $this->activeLocaleName = array_get($this->locales, $this->activeLocale); }
/** * {@inheritDoc} */ protected function loadAssets() { $this->actAsParent(); parent::loadAssets(); $this->actAsParent(false); if (Locale::isAvailable()) { $this->loadLocaleAssets(); $this->addJs('js/mlricheditor.js'); } }
/** * {@inheritDoc} */ public function render() { $this->isAvailable = Locale::isAvailable(); $this->prepareLocaleVars(); if ($this->isAvailable) { return $this->makePartial('mltext'); } else { return $this->renderFallbackField(); } }
/** * {@inheritDoc} */ public function loadAssets() { $this->actAsParent(); parent::loadAssets(); $this->actAsParent(false); if (Locale::isAvailable()) { $this->loadLocaleAssets(); $this->addJs('js/mlswitcher.js'); } }
protected function seedSampleSourceAndData() { $datasource = new FileDatasource($this->themePath, new Filesystem()); $resolver = new Resolver(['theme1' => $datasource]); $resolver->setDefaultDatasource('theme1'); Model::setDatasourceResolver($resolver); LocaleModel::unguard(); LocaleModel::firstOrCreate(['code' => 'fr', 'name' => 'French', 'is_enabled' => 1]); LocaleModel::reguard(); $this->recycleSampleData(); }
/** * Changes the locale in the application and optionally stores it in the session. * @param string $locale Locale to use * @param boolean $remember Set to false to not store in the session. * @return boolean Returns true if the locale exists and is set. */ public function setLocale($locale, $remember = true) { if (!Locale::isValid($locale)) { return false; } App::setLocale($locale); $this->activeLocale = $locale; if ($remember) { $this->setSessionLocale($locale); } return true; }
public function prepareTable() { $fromCode = post('locale_from', null); $toCode = post('locale_to', Locale::getDefault()->code); $this->hideTranslated = post('hide_translated', false); /* * Page vars */ $this->vars['hideTranslated'] = $this->hideTranslated; $this->vars['defaultLocale'] = Locale::getDefault(); $this->vars['locales'] = Locale::all(); $this->vars['selectedFrom'] = $selectedFrom = Locale::findByCode($fromCode); $this->vars['selectedTo'] = $selectedTo = Locale::findByCode($toCode); /* * Make table config, make default column read only */ $config = $this->makeConfig('config_table.yaml'); if (!$selectedFrom) { $config->columns['from']['readOnly'] = true; } if (!$selectedTo) { $config->columns['to']['readOnly'] = true; } /* * Make table widget */ $widget = $this->makeWidget('Backend\\Widgets\\Table', $config); $widget->bindToController(); /* * Populate data */ $dataSource = $widget->getDataSource(); $dataSource->bindEvent('data.getRecords', function ($offset, $count) use($selectedFrom, $selectedTo) { $messages = $count ? Message::orderBy('message_data', 'asc')->limit($count)->offset($offset)->get() : Message::orderBy('message_data', 'asc')->get(); $result = $this->processTableData($messages, $selectedFrom, $selectedTo); return $result; }); $dataSource->bindEvent('data.getCount', function () { return Message::count(); }); $dataSource->bindEvent('data.updateRecord', function ($key, $data) { $message = Message::find($key); $this->updateTableData($message, $data); CacheHelper::clear(); }); $dataSource->bindEvent('data.deleteRecord', function ($key) { if ($message = Message::find($key)) { $message->delete(); } }); $this->vars['table'] = $widget; }
/** * Changes the locale in the application and optionally stores it in the session. * @param string $locale Locale to use * @param boolean $remember Set to false to not store in the session. * @return boolean Returns true if the locale exists and is set. */ public function setLocale($locale, $remember = true) { $languages = array_keys(Locale::listEnabled()); if (in_array($locale, $languages)) { App::setLocale($locale); $this->activeLocale = $locale; if ($remember) { $this->setSessionLocale($locale); } return true; } return false; }
protected function seedSampleTableAndData() { if (Schema::hasTable('translate_test_countries')) { return; } Model::unguard(); Schema::create('translate_test_countries', function ($table) { $table->engine = 'InnoDB'; $table->increments('id'); $table->string('name')->nullable(); $table->string('code')->nullable(); $table->text('states')->nullable(); $table->timestamps(); }); LocaleModel::firstOrCreate(['code' => 'fr', 'name' => 'French', 'is_enabled' => 1]); $this->recycleSampleData(); Model::reguard(); }
public function prepareGrid() { $fromCode = post('locale_from', null); $toCode = post('locale_to', Locale::getDefault()->code); /* * Page vars */ $this->vars['hideTranslated'] = post('hide_translated', false); $this->vars['defaultLocale'] = Locale::getDefault(); $this->vars['locales'] = Locale::all(); $this->vars['selectedFrom'] = $selectedFrom = Locale::findByCode($fromCode); $this->vars['selectedTo'] = $selectedTo = Locale::findByCode($toCode); /* * Make grid config, make default column read only */ $config = $this->makeConfig('config_grid.yaml'); $config->data = $this->getGridData($selectedFrom, $selectedTo); if (!$selectedFrom) { $config->columns['from']['readOnly'] = true; } if (!$selectedTo) { $config->columns['to']['readOnly'] = true; } /* * Make grid widget */ $widget = new Grid($this, $config); $widget->bindEvent('grid.dataChanged', function ($action, $changes) { if ($action == 'remove') { $this->removeGridData($changes); } else { $this->updateGridData($changes); } }); $widget->bindToController(); $this->vars['grid'] = $widget; }
public function run() { Locale::create(['code' => 'en', 'name' => 'English', 'is_default' => true, 'is_enabled' => true]); }
<?php /** * @author Alex Carrega <*****@*****.**> * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 */ /* * Add route to the logo. * Adds custom routes. * @param Illuminate\Http\Request $request * @return null */ App::before(function ($request) { Route::get('/logo', function () { $response = Response::make(\Backend\Models\BrandSettings::instance()->logo->output(), 200); $response->header('Content-Type', 'image/png'); return $response; }); $ctrl = new \Cms\Classes\Controller(); foreach (\AxC\DataManagement\Models\Route::published() as $route) { $language[] = (object) ['code' => $route->language]; if ($route->language == '') { $language = array_merge($language, \RainLab\Translate\Models\Locale::get(['code'])->all()); } foreach ($language as $l) { Route::any("{$l->code}/{$route->path}", function () use($ctrl, $route) { return $ctrl->run($route->page); }); } } });
public function getLanguageOptions($keyValue = null) { return array_merge(['' => trans('axc.framework::lang.system.any')], \RainLab\Translate\Models\Locale::listEnabled()); }
/** * Removes localized content files from templates collection * @param \October\Rain\Database\Collection $templates * @return \October\Rain\Database\Collection */ public function pruneTranslatedContentTemplates($templates) { $locales = LocaleModel::listAvailable(); $extensions = array_map(function ($ext) { return '.' . $ext; }, array_keys($locales)); return $templates->filter(function ($template) use($extensions) { return !Str::endsWith($template->getBaseFileName(), $extensions); }); }
/** * Prepares the list data */ public function prepareLocaleVars() { $this->vars['defaultLocale'] = $this->defaultLocale; $this->vars['locales'] = Locale::listAvailable(); $this->vars['field'] = $this->makeRenderFormField(); }
/** * Returns true if the supplied locale is valid. * @return boolean */ public static function isValid($locale) { $languages = array_keys(Locale::listEnabled()); return in_array($locale, $languages); }
public function onDelete() { LocaleModel::clearCache(); $this->asExtension('FormController')->update_onDelete(post('record_id')); return $this->listRefresh(); }
/** * Returns the path prefixed with language code. * * @param string $path Path to rewrite * @param string $locale optional language code, default to the system default language * @return string */ public function getPathInLocale($path, $locale = null) { $segments = explode('/', $path); $segments = array_values(array_filter($segments, function ($v) { return $v != ''; })); if (is_null($locale) || !Locale::isValid($locale)) { $locale = $this->defaultLocale; } if (count($segments) == 0 || Locale::isValid($segments[0])) { $segments[0] = $locale; } else { array_unshift($segments, $locale); } return implode('/', $segments); }
<?php use RainLab\Translate\Models\Locale; 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 (!Locale::isValid($locale)) { return; } $translator->setLocale($locale); /* * Register routes */ Route::group(['prefix' => $locale], function () { Route::any('{slug}', 'Cms\\Classes\\CmsController@run')->where('slug', '(.*)?'); }); Route::any($locale, 'Cms\\Classes\\CmsController@run'); /* * Ensure Url::action() retains the localized URL * by re-registering the route after the CMS. */ Event::listen('cms.route', function () use($locale) { Route::group(['prefix' => $locale], function () {
public function onRun() { $this->page['activeLocale'] = $this->activeLocale = $this->translator->getLocale(); $this->page['locales'] = $this->locales = LocaleModel::listEnabled(); }
/** * Returns the current path prefixed with language code. * * @param string $locale optional language code, default to the system default language * @return string */ public function getCurrentPathInLocale($locale = null) { if (is_null($locale) || !Locale::isValid($locale)) { $locale = $this->defaultLocale; } $segments = Request::segments(); if (count($segments) == 0 || Locale::isValid($segments[0])) { $segments[0] = $locale; } else { array_unshift($segments, $locale); } return implode('/', $segments); }