diff --git a/administrator/language/en-GB/en-GB.lib_joomla.ini b/administrator/language/en-GB/en-GB.lib_joomla.ini index 1ba6cd81db5e7..d7e14da7cfd2e 100644 --- a/administrator/language/en-GB/en-GB.lib_joomla.ini +++ b/administrator/language/en-GB/en-GB.lib_joomla.ini @@ -628,6 +628,7 @@ JLIB_INSTALLER_ERROR_EXTENSION_INVALID_CLIENT_IDENTIFIER="Invalid client identif JLIB_INSTALLER_ERROR_PACK_UNINSTALL_UNKNOWN_EXTENSION="Attempting to uninstall unknown extension from package. This extension may have already been removed earlier." JLIB_INSTALLER_NOT_ERROR="If the error is related to the installation of TinyMCE language files it has no effect on the installation of the language(s). Some language packs created prior to Joomla! 3.2.0 may try to install separate TinyMCE language files. As these are now included in the core they no longer need to be installed." JLIB_INSTALLER_UPDATE_LOG_QUERY="Ran query from file %1$s. Query text: %2$s." +JLIB_INSTALLER_WARNING_UNABLE_TO_INSTALL_CONTENT_LANGUAGE="Unable to create a content language for %s language: %s" JLIB_JS_AJAX_ERROR_CONNECTION_ABORT="A connection abort has occurred while fetching the JSON data." JLIB_JS_AJAX_ERROR_NO_CONTENT="No content was returned." diff --git a/installation/controller/install/languages.php b/installation/controller/install/languages.php index 37a94f4c9c309..60c9222da5c7d 100644 --- a/installation/controller/install/languages.php +++ b/installation/controller/install/languages.php @@ -62,6 +62,10 @@ public function execute() { // Install selected languages $model->install($lids); + + // Publish the Content Languages. + $model->publishContentLanguages(); + $app->enqueueMessage(JText::_('INSTL_LANGUAGES_MORE_LANGUAGES'), 'notice'); } diff --git a/installation/controller/setdefaultlanguage.php b/installation/controller/setdefaultlanguage.php index 1e21c5999a28c..f2bf9dbd7cde1 100644 --- a/installation/controller/setdefaultlanguage.php +++ b/installation/controller/setdefaultlanguage.php @@ -126,24 +126,6 @@ public function execute() foreach ($siteLanguages as $siteLang) { - // Add Language Manager: Content Languages - $tableLanguage = JTable::getInstance('Language'); - - // Search if just added - $return = $tableLanguage->load(array('lang_code' => $siteLang->language)); - - if ($return === false) - { - $sefLangString = $model->getSefString($siteLang, $siteLanguages); - - if (!$model->addLanguage($siteLang, $sefLangString)) - { - $app->enqueueMessage(JText::sprintf('INSTL_DEFAULTLANGUAGE_COULD_NOT_CREATE_CONTENT_LANGUAGE', $siteLang->name)); - - continue; - } - } - if (!$model->addMenuGroup($siteLang)) { $app->enqueueMessage(JText::sprintf('INSTL_DEFAULTLANGUAGE_COULD_NOT_CREATE_MENU', $siteLang->name), 'warning'); diff --git a/installation/model/languages.php b/installation/model/languages.php index aa751a82c9700..fb33824c90414 100644 --- a/installation/model/languages.php +++ b/installation/model/languages.php @@ -687,6 +687,39 @@ public function addModuleInModuleMenu($moduleId) return true; } + /** + * Publish the Installed Content Languages. + * + * @return boolean + * + * @since __DEPLOY_VERSION__ + */ + public function publishContentLanguages() + { + $app = JFactory::getApplication(); + + // Publish the Content Languages. + $tableLanguage = JTable::getInstance('Language'); + + $siteLanguages = $this->getInstalledlangs('site'); + + // For each content language. + foreach ($siteLanguages as $siteLang) + { + if ($tableLanguage->load(array('lang_code' => $siteLang->language, 'published' => 0))) + { + if (!$tableLanguage->publish()) + { + $app->enqueueMessage(JText::sprintf('INSTL_DEFAULTLANGUAGE_COULD_NOT_CREATE_CONTENT_LANGUAGE', $siteLang->name), 'warning'); + + continue; + } + } + } + + return true; + } + /** * Gets a unique language SEF string. * @@ -701,6 +734,7 @@ public function addModuleInModuleMenu($moduleId) * @return string * * @since 3.2 + * @depreacted 4.0 Not used anymore. */ public function getSefString($itemLanguage, $siteLanguages) { @@ -737,6 +771,7 @@ public function getSefString($itemLanguage, $siteLanguages) * @return boolean * * @since 3.2 + * @depreacted 4.0 Not used anymore. */ public function addLanguage($itemLanguage, $sefLangString) { diff --git a/language/en-GB/en-GB.lib_joomla.ini b/language/en-GB/en-GB.lib_joomla.ini index 845d99cefe6a0..5ce3d39415fa0 100644 --- a/language/en-GB/en-GB.lib_joomla.ini +++ b/language/en-GB/en-GB.lib_joomla.ini @@ -628,6 +628,7 @@ JLIB_INSTALLER_ERROR_EXTENSION_INVALID_CLIENT_IDENTIFIER="Invalid client identif JLIB_INSTALLER_ERROR_PACK_UNINSTALL_UNKNOWN_EXTENSION="Attempting to uninstall unknown extension from package. This extension may have already been removed earlier." JLIB_INSTALLER_NOT_ERROR="If the error is related to the installation of TinyMCE language files it has no effect on the installation of the language(s). Some language packs created prior to Joomla! 3.2.0 may try to install separate TinyMCE language files. As these are now included in the core they no longer need to be installed." JLIB_INSTALLER_UPDATE_LOG_QUERY="Ran query from file %1$s. Query text: %2$s." +JLIB_INSTALLER_WARNING_UNABLE_TO_INSTALL_CONTENT_LANGUAGE="Unable to create a content language for %s language: %s" JLIB_JS_AJAX_ERROR_CONNECTION_ABORT="A connection abort has occurred while fetching the JSON data." JLIB_JS_AJAX_ERROR_NO_CONTENT="No content was returned." diff --git a/libraries/cms/installer/adapter/language.php b/libraries/cms/installer/adapter/language.php index b403abec808b1..bc4d5711ce5d8 100644 --- a/libraries/cms/installer/adapter/language.php +++ b/libraries/cms/installer/adapter/language.php @@ -107,17 +107,17 @@ public function install() $basePath = $client->path; $clientId = $client->id; - $element = $this->getManifest()->files; + $element = $this->getManifest()->files; return $this->_install($cname, $basePath, $clientId, $element); } else { // No client attribute was found so we assume the site as the client - $cname = 'site'; + $cname = 'site'; $basePath = JPATH_SITE; $clientId = 0; - $element = $this->getManifest()->files; + $element = $this->getManifest()->files; return $this->_install($cname, $basePath, $clientId, $element); } @@ -300,6 +300,68 @@ protected function _install($cname, $basePath, $clientId, &$element) return false; } + // Create an unpublished content language. + if ((int) $clientId === 0) + { + // Load the site language manifest. + $siteLanguageManifest = JLanguage::parseXMLLanguageFile(JPATH_SITE . '/language/' . $this->tag . '/' . $this->tag . '.xml'); + + // Set the content language title as name in site xx-XX.ini. + $contentLanguageTitle = $siteLanguageManifest['name']; + + // Set the content language as installation native title language variable, fallback to content language title. + $contentLanguageNativeTitle = $contentLanguageTitle; + + if (file_exists(JPATH_INSTALLATION . '/language/' . $this->tag . '/' . $this->tag . '.xml')) + { + $installationLanguage = new JLanguage($this->tag); + $installationLanguage->load('', JPATH_INSTALLATION); + + if ($installationLanguage->hasKey('INSTL_DEFAULTLANGUAGE_NATIVE_LANGUAGE_NAME')) + { + // Make sure it will not use the en-GB fallback. + $defaultLanguage = new JLanguage('en-GB'); + $defaultLanguage->load('', JPATH_INSTALLATION); + + $defaultLanguageNativeTitle = $defaultLanguage->_('INSTL_DEFAULTLANGUAGE_NATIVE_LANGUAGE_NAME'); + $installationLanguageNativeTitle = $installationLanguage->_('INSTL_DEFAULTLANGUAGE_NATIVE_LANGUAGE_NAME'); + + if ($defaultLanguageNativeTitle != $installationLanguageNativeTitle) + { + $contentLanguageNativeTitle = $installationLanguage->_('INSTL_DEFAULTLANGUAGE_NATIVE_LANGUAGE_NAME'); + } + } + } + + // Prepare language data for store. + $languageData = array( + 'lang_id' => 0, + 'lang_code' => $this->tag, + 'title' => $contentLanguageTitle, + 'title_native' => $contentLanguageNativeTitle, + 'sef' => $this->getSefString($this->tag), + 'image' => strtolower(str_replace('-', '_', $this->tag)), + 'published' => 0, + 'ordering' => 0, + 'access' => (int) JFactory::getConfig()->get('access', 1), + 'description' => '', + 'metakey' => '', + 'metadesc' => '', + 'sitename' => '', + ); + + $tableLanguage = JTable::getInstance('language'); + + if (!$tableLanguage->bind($languageData) || !$tableLanguage->check() || !$tableLanguage->store() || !$tableLanguage->reorder()) + { + JLog::add( + JText::sprintf('JLIB_INSTALLER_WARNING_UNABLE_TO_INSTALL_CONTENT_LANGUAGE', $siteLanguageManifest['name'], $tableLanguage->getError()), + JLog::WARNING, + 'jerror' + ); + } + } + // Clobber any possible pending updates $update = JTable::getInstance('update'); $uid = $update->find(array('element' => $this->get('tag'), 'type' => 'language', 'folder' => '')); @@ -312,6 +374,47 @@ protected function _install($cname, $basePath, $clientId, &$element) return $row->get('extension_id'); } + + /** + * Gets a unique language SEF string. + * + * This function checks other existing language with the same code, if they exist provides a unique SEF name. + * For instance: en-GB, en-US and en-AU will share the same SEF code by default: www.mywebsite.com/en/ + * To avoid this conflict, this function creates an specific SEF in case of existing conflict: + * For example: www.mywebsite.com/en-au/ + * + * @param string $itemLanguageTag Language Tag. + * + * @return string + * + * @since __DEPLOY_VERSION__ + */ + protected function getSefString($itemLanguageTag) + { + $langs = explode('-', $itemLanguageTag); + $prefixToFind = $langs[0]; + $numberPrefixesFound = 0; + + // Get the sef value of all current content languages. + $db = JFactory::getDbo(); + $query = $db->getQuery(true) + ->select($db->qn('sef')) + ->from($db->qn('#__languages')); + $db->setQuery($query); + + $siteLanguages = $db->loadObjectList(); + + foreach ($siteLanguages as $siteLang) + { + if ($siteLang->sef === $prefixToFind) + { + $numberPrefixesFound++; + } + } + + return $numberPrefixesFound === 0 ? $prefixToFind : strtolower($itemLanguageTag); + } + /** * Custom update method *