[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Administrator 5 * @subpackage com_languages 6 * 7 * @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 namespace Joomla\Component\Languages\Administrator\Controller; 12 13 use Joomla\CMS\Factory; 14 use Joomla\CMS\Language\LanguageHelper; 15 use Joomla\CMS\Language\Language; 16 use Joomla\CMS\Language\Multilanguage; 17 use Joomla\CMS\Language\Text; 18 use Joomla\CMS\MVC\Controller\BaseController; 19 20 // phpcs:disable PSR1.Files.SideEffects 21 \defined('_JEXEC') or die; 22 // phpcs:enable PSR1.Files.SideEffects 23 24 /** 25 * Languages Controller. 26 * 27 * @since 1.5 28 */ 29 class InstalledController extends BaseController 30 { 31 /** 32 * Task to set the default language. 33 * 34 * @return void 35 */ 36 public function setDefault() 37 { 38 // Check for request forgeries. 39 $this->checkToken(); 40 41 $cid = (string) $this->input->get('cid', '', 'string'); 42 $model = $this->getModel('installed'); 43 44 if ($model->publish($cid)) { 45 // Switching to the new administrator language for the message 46 if ($model->getState('client_id') == 1) { 47 $language = Factory::getLanguage(); 48 $newLang = Language::getInstance($cid); 49 Factory::$language = $newLang; 50 $this->app->loadLanguage($language = $newLang); 51 $newLang->load('com_languages', JPATH_ADMINISTRATOR); 52 } 53 54 if (Multilanguage::isEnabled() && $model->getState('client_id') == 0) { 55 $msg = Text::_('COM_LANGUAGES_MSG_DEFAULT_MULTILANG_SAVED'); 56 $type = 'message'; 57 } else { 58 $msg = Text::_('COM_LANGUAGES_MSG_DEFAULT_LANGUAGE_SAVED'); 59 $type = 'message'; 60 } 61 } else { 62 $msg = $model->getError(); 63 $type = 'error'; 64 } 65 66 $clientId = $model->getState('client_id'); 67 $this->setRedirect('index.php?option=com_languages&view=installed&client=' . $clientId, $msg, $type); 68 } 69 70 /** 71 * Task to switch the administrator language. 72 * 73 * @return void 74 */ 75 public function switchAdminLanguage() 76 { 77 // Check for request forgeries. 78 $this->checkToken(); 79 80 $cid = (string) $this->input->get('cid', '', 'string'); 81 $model = $this->getModel('installed'); 82 83 // Fetching the language name from the langmetadata.xml or xx-XX.xml respectively. 84 $file = JPATH_ADMINISTRATOR . '/language/' . $cid . '/langmetadata.xml'; 85 86 if (!is_file($file)) { 87 $file = JPATH_ADMINISTRATOR . '/language/' . $cid . '/' . $cid . '.xml'; 88 } 89 90 $info = LanguageHelper::parseXMLLanguageFile($file); 91 92 if ($model->switchAdminLanguage($cid)) { 93 // Switching to the new language for the message 94 $languageName = $info['nativeName']; 95 $language = Factory::getLanguage(); 96 $newLang = Language::getInstance($cid); 97 Factory::$language = $newLang; 98 $this->app->loadLanguage($language = $newLang); 99 $newLang->load('com_languages', JPATH_ADMINISTRATOR); 100 101 $msg = Text::sprintf('COM_LANGUAGES_MSG_SWITCH_ADMIN_LANGUAGE_SUCCESS', $languageName); 102 $type = 'message'; 103 } else { 104 $msg = $model->getError(); 105 $type = 'error'; 106 } 107 108 $this->setRedirect('index.php?option=com_languages&view=installed', $msg, $type); 109 } 110 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |