From 6fbfee8d58a63907ab71cc15935ce56d1a9d6f2e Mon Sep 17 00:00:00 2001 From: andrepereiradasilva Date: Wed, 31 Aug 2016 23:18:58 +0100 Subject: [PATCH 01/20] initial commit --- libraries/cms/installer/adapter/language.php | 47 ++++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/libraries/cms/installer/adapter/language.php b/libraries/cms/installer/adapter/language.php index 66755b52432de..322e60793ab15 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,47 @@ protected function _install($cname, $basePath, $clientId, &$element) return false; } + // Create an unpublished content language. + if ((int) $clientId === 0) + { + $siteLanguageManifest = JLanguage::parseXMLLanguageFile(JPATH_SITE . '/language/' . $this->get('tag') . '/' . $this->get('tag') . '.xml'); + + $row = JTable::getInstance('language'); + $row->lang_code = $this->name; + $row->title = $siteLanguageManifest['name']; + $row->title_native = $this->get('name'); + $row->image = strtolower(str_replace('-', '_', $this->get('tag'))); + $row->description = ''; + $row->metakey = ''; + $row->metadesc = ''; + $row->sitename = ''; + $row->published = 0; + $row->access = (int) JFactory::getConfig()->get('access', 1); + $row->ordering = 0; + + $sefs = array( + preg_replace('#([a-z]{2,3})-[A-Z]{2}#', '$1', $this->get('tag')), + strtolower($this->get('tag')), + ); + + // Try both sef types (xx or xx-xx). For instance, for en-US when you have en-GB installed. + foreach ($sefs as $sef) + { + $row->sef = $sef; + + if ($row->check() && $row->store()) + { + $created = true; + break; + } + } + + if (!$created) + { + JLog::add(JText::_('Unable to create a content language for ' . $this->get('name') . ' language. ' . $row->getError()), JLog::WARNING, 'jerror'); + } + } + // Clobber any possible pending updates $update = JTable::getInstance('update'); $uid = $update->find(array('element' => $this->get('tag'), 'type' => 'language', 'folder' => '')); From 57f4926b0cf3797c00f6ee0aeaf8b308f13b0c2c Mon Sep 17 00:00:00 2001 From: andrepereiradasilva Date: Wed, 31 Aug 2016 23:22:57 +0100 Subject: [PATCH 02/20] Update language.php --- libraries/cms/installer/adapter/language.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libraries/cms/installer/adapter/language.php b/libraries/cms/installer/adapter/language.php index 322e60793ab15..5fcb1fd382eab 100644 --- a/libraries/cms/installer/adapter/language.php +++ b/libraries/cms/installer/adapter/language.php @@ -337,7 +337,11 @@ protected function _install($cname, $basePath, $clientId, &$element) if (!$created) { - JLog::add(JText::_('Unable to create a content language for ' . $this->get('name') . ' language. ' . $row->getError()), JLog::WARNING, 'jerror'); + JLog::add( + JText::sprintf('JLIB_INSTALLER_WARNING_UNABLE_TO_INSTALL_CONTENT_LANGUAGE', $this->get('name'), $row->getError()), + JLog::WARNING, + 'jerror' + ); } } From 1cb7f1f88770be5a006776eea5a584fda045b731 Mon Sep 17 00:00:00 2001 From: andrepereiradasilva Date: Wed, 31 Aug 2016 23:23:10 +0100 Subject: [PATCH 03/20] Update en-GB.lib_joomla.ini --- administrator/language/en-GB/en-GB.lib_joomla.ini | 1 + 1 file changed, 1 insertion(+) 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." From 3dc390b94817de15fb204c9a2a75f9030913adad Mon Sep 17 00:00:00 2001 From: andrepereiradasilva Date: Wed, 31 Aug 2016 23:23:23 +0100 Subject: [PATCH 04/20] Update en-GB.lib_joomla.ini --- language/en-GB/en-GB.lib_joomla.ini | 1 + 1 file changed, 1 insertion(+) 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." From 9902f77912c766c413482a6513f8d075873dc9c3 Mon Sep 17 00:00:00 2001 From: andrepereiradasilva Date: Wed, 31 Aug 2016 23:44:26 +0100 Subject: [PATCH 05/20] ups --- libraries/cms/installer/adapter/language.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/cms/installer/adapter/language.php b/libraries/cms/installer/adapter/language.php index 5fcb1fd382eab..e58a4207f51ca 100644 --- a/libraries/cms/installer/adapter/language.php +++ b/libraries/cms/installer/adapter/language.php @@ -306,7 +306,7 @@ protected function _install($cname, $basePath, $clientId, &$element) $siteLanguageManifest = JLanguage::parseXMLLanguageFile(JPATH_SITE . '/language/' . $this->get('tag') . '/' . $this->get('tag') . '.xml'); $row = JTable::getInstance('language'); - $row->lang_code = $this->name; + $row->lang_code = $this->get('tag'); $row->title = $siteLanguageManifest['name']; $row->title_native = $this->get('name'); $row->image = strtolower(str_replace('-', '_', $this->get('tag'))); From 1a87e4075b8214c2b78b1a7075744e73e3425696 Mon Sep 17 00:00:00 2001 From: andrepereiradasilva Date: Thu, 1 Sep 2016 00:10:06 +0100 Subject: [PATCH 06/20] Update language.php --- libraries/cms/installer/adapter/language.php | 51 ++++++++++++-------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/libraries/cms/installer/adapter/language.php b/libraries/cms/installer/adapter/language.php index e58a4207f51ca..e9b0c3c2211b7 100644 --- a/libraries/cms/installer/adapter/language.php +++ b/libraries/cms/installer/adapter/language.php @@ -303,32 +303,45 @@ protected function _install($cname, $basePath, $clientId, &$element) // Create an unpublished content language. if ((int) $clientId === 0) { - $siteLanguageManifest = JLanguage::parseXMLLanguageFile(JPATH_SITE . '/language/' . $this->get('tag') . '/' . $this->get('tag') . '.xml'); - - $row = JTable::getInstance('language'); - $row->lang_code = $this->get('tag'); - $row->title = $siteLanguageManifest['name']; - $row->title_native = $this->get('name'); - $row->image = strtolower(str_replace('-', '_', $this->get('tag'))); - $row->description = ''; - $row->metakey = ''; - $row->metadesc = ''; - $row->sitename = ''; - $row->published = 0; - $row->access = (int) JFactory::getConfig()->get('access', 1); - $row->ordering = 0; + // Load the site language manifest. + $siteLanguageManifest = JLanguage::parseXMLLanguageFile(JPATH_SITE . '/language/' . $this->tag . '/' . $this->tag . '.xml'); + + // Load the native language name. + $installedLanguage = new JLanguage($this->tag, false); + $nativeLanguageName = $installedLanguage->_('INSTL_DEFAULTLANGUAGE_NATIVE_LANGUAGE_NAME'); + + // If the local name do not exist in the translation file we use the international standard name. + $nativeLanguageName = $nativeLanguageName == 'INSTL_DEFAULTLANGUAGE_NATIVE_LANGUAGE_NAME' ? $siteLanguageManifest['name'] : $nativeLanguageName; + + // Prepare language data for store. + $languageData = array( + 'lang_id' => 0, + 'lang_code' => $this->tag, + 'title' => $siteLanguageManifest['name'], + 'title_native' => $nativeLanguageName, + 'image' => strtolower(str_replace('-', '_', $this->tag)), + 'published' => 0, + 'ordering' => 0, + 'access' => (int) JFactory::getConfig()->get('access', 1), + 'description' => '', + 'metakey' => '', + 'metadesc' => '', + 'sitename' => '', + ); $sefs = array( - preg_replace('#([a-z]{2,3})-[A-Z]{2}#', '$1', $this->get('tag')), - strtolower($this->get('tag')), + preg_replace('#([a-z]{2,3})-[A-Z]{2}#', '$1', $this->tag), + strtolower($this->tag), ); - // Try both sef types (xx or xx-xx). For instance, for en-US when you have en-GB installed. + $tableLanguage = JTable::getInstance('language'); + + // Try storing sef type (xx), fallback to (xx-xx). For instance, for en-US when you have en-GB installed. foreach ($sefs as $sef) { - $row->sef = $sef; + $languageData['sef'] = $sef; - if ($row->check() && $row->store()) + if ($tableLanguage->bind($languageData) && $tableLanguage->check() && $tableLanguage->store() && $tableLanguage->reorder()) { $created = true; break; From 755c18fad22d4876b58cf6009443ed4eccb12aff Mon Sep 17 00:00:00 2001 From: andrepereiradasilva Date: Thu, 1 Sep 2016 00:11:51 +0100 Subject: [PATCH 07/20] Update language.php --- libraries/cms/installer/adapter/language.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/cms/installer/adapter/language.php b/libraries/cms/installer/adapter/language.php index e9b0c3c2211b7..26e4cd66b894d 100644 --- a/libraries/cms/installer/adapter/language.php +++ b/libraries/cms/installer/adapter/language.php @@ -351,7 +351,7 @@ protected function _install($cname, $basePath, $clientId, &$element) if (!$created) { JLog::add( - JText::sprintf('JLIB_INSTALLER_WARNING_UNABLE_TO_INSTALL_CONTENT_LANGUAGE', $this->get('name'), $row->getError()), + JText::sprintf('JLIB_INSTALLER_WARNING_UNABLE_TO_INSTALL_CONTENT_LANGUAGE', $siteLanguageManifest['name'], $row->getError()), JLog::WARNING, 'jerror' ); From 4bbfd4c4649c00870a10c0c5ccd7410ca79f4f82 Mon Sep 17 00:00:00 2001 From: andrepereiradasilva Date: Thu, 1 Sep 2016 00:12:20 +0100 Subject: [PATCH 08/20] Update language.php --- libraries/cms/installer/adapter/language.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/cms/installer/adapter/language.php b/libraries/cms/installer/adapter/language.php index 26e4cd66b894d..c4305b9c43349 100644 --- a/libraries/cms/installer/adapter/language.php +++ b/libraries/cms/installer/adapter/language.php @@ -336,6 +336,8 @@ protected function _install($cname, $basePath, $clientId, &$element) $tableLanguage = JTable::getInstance('language'); + $created = false; + // Try storing sef type (xx), fallback to (xx-xx). For instance, for en-US when you have en-GB installed. foreach ($sefs as $sef) { From 661ff82590dede6b02cbe8464ae3a1844fd2d19b Mon Sep 17 00:00:00 2001 From: andrepereiradasilva Date: Thu, 1 Sep 2016 10:57:16 +0100 Subject: [PATCH 09/20] change native to $siteLanguageManifest['name'] --- libraries/cms/installer/adapter/language.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/libraries/cms/installer/adapter/language.php b/libraries/cms/installer/adapter/language.php index c4305b9c43349..d9c4434e66e54 100644 --- a/libraries/cms/installer/adapter/language.php +++ b/libraries/cms/installer/adapter/language.php @@ -306,19 +306,12 @@ protected function _install($cname, $basePath, $clientId, &$element) // Load the site language manifest. $siteLanguageManifest = JLanguage::parseXMLLanguageFile(JPATH_SITE . '/language/' . $this->tag . '/' . $this->tag . '.xml'); - // Load the native language name. - $installedLanguage = new JLanguage($this->tag, false); - $nativeLanguageName = $installedLanguage->_('INSTL_DEFAULTLANGUAGE_NATIVE_LANGUAGE_NAME'); - - // If the local name do not exist in the translation file we use the international standard name. - $nativeLanguageName = $nativeLanguageName == 'INSTL_DEFAULTLANGUAGE_NATIVE_LANGUAGE_NAME' ? $siteLanguageManifest['name'] : $nativeLanguageName; - // Prepare language data for store. $languageData = array( 'lang_id' => 0, 'lang_code' => $this->tag, 'title' => $siteLanguageManifest['name'], - 'title_native' => $nativeLanguageName, + 'title_native' => $siteLanguageManifest['name'], 'image' => strtolower(str_replace('-', '_', $this->tag)), 'published' => 0, 'ordering' => 0, From 69a02b51644bcba46c22fc2524508058f380c1ae Mon Sep 17 00:00:00 2001 From: andrepereiradasilva Date: Fri, 2 Sep 2016 23:56:12 +0100 Subject: [PATCH 10/20] allow to install published content languages on install 1 --- installation/model/languages.php | 43 ++++++-------------------------- 1 file changed, 7 insertions(+), 36 deletions(-) diff --git a/installation/model/languages.php b/installation/model/languages.php index aa751a82c9700..3bdc5fd0de264 100644 --- a/installation/model/languages.php +++ b/installation/model/languages.php @@ -738,12 +738,10 @@ public function getSefString($itemLanguage, $siteLanguages) * * @since 3.2 */ - public function addLanguage($itemLanguage, $sefLangString) + public function addLanguage($itemLanguage, $sefLangString = '') { $tableLanguage = JTable::getInstance('Language'); - $flag = strtolower(str_replace('-', '_', $itemLanguage->language)); - // Load the native language name. $installationLocalisedIni = new JLanguage($itemLanguage->language, false); $nativeLanguageName = $installationLocalisedIni->_('INSTL_DEFAULTLANGUAGE_NATIVE_LANGUAGE_NAME'); @@ -754,40 +752,13 @@ public function addLanguage($itemLanguage, $sefLangString) $nativeLanguageName = $itemLanguage->name; } - $langData = array( - 'lang_id' => 0, - 'lang_code' => $itemLanguage->language, - 'title' => $itemLanguage->name, - 'title_native' => $nativeLanguageName, - 'sef' => $sefLangString, - 'image' => $flag, - 'published' => 1, - 'ordering' => 0, - 'description' => '', - 'metakey' => '', - 'metadesc' => '', - ); - - // Bind the data. - if (!$tableLanguage->bind($langData)) - { - return false; - } - - // Check the data. - if (!$tableLanguage->check()) - { - return false; - } - - // Store the data. - if (!$tableLanguage->store()) - { - return false; - } + // Load the content language. + $tableLanguage->load(array('lang_code' => $itemLanguage->language)); + $tableLanguage->title_native = $nativeLanguageName; + $tableLanguage->published = 1; - // Reorder the data. - if (!$tableLanguage->reorder()) + // Check and store the data. + if (!$tableLanguage->check() || !$tableLanguage->store()) { return false; } From cb55d3288df8088a7950b81bccf77bdfdc45f350 Mon Sep 17 00:00:00 2001 From: andrepereiradasilva Date: Fri, 2 Sep 2016 23:56:35 +0100 Subject: [PATCH 11/20] allow to install published content languages on install 2 --- installation/controller/setdefaultlanguage.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/installation/controller/setdefaultlanguage.php b/installation/controller/setdefaultlanguage.php index 3f510e1626b70..0c3ed8d3acf44 100644 --- a/installation/controller/setdefaultlanguage.php +++ b/installation/controller/setdefaultlanguage.php @@ -130,13 +130,11 @@ public function execute() $tableLanguage = JTable::getInstance('Language'); // Search if just added - $return = $tableLanguage->load(array('lang_code' => $siteLang->language)); + $return = $tableLanguage->load(array('lang_code' => $siteLang->language, 'published' => 1)); if ($return === false) { - $sefLangString = $model->getSefString($siteLang, $siteLanguages); - - if (!$model->addLanguage($siteLang, $sefLangString)) + if (!$model->addLanguage($siteLang)) { $app->enqueueMessage(JText::sprintf('INSTL_DEFAULTLANGUAGE_COULD_NOT_CREATE_CONTENT_LANGUAGE', $siteLang->name)); From 0cd03f8e2372fdf4f1dfbb0036bf39aa0b6d1727 Mon Sep 17 00:00:00 2001 From: andrepereiradasilva Date: Sat, 3 Sep 2016 00:29:10 +0100 Subject: [PATCH 12/20] solve remaining issues --- installation/controller/install/languages.php | 24 +++++- .../controller/setdefaultlanguage.php | 16 ---- installation/model/languages.php | 77 +++++++++++++++++-- 3 files changed, 92 insertions(+), 25 deletions(-) diff --git a/installation/controller/install/languages.php b/installation/controller/install/languages.php index 567f2207dbd62..197a27f2f2a31 100644 --- a/installation/controller/install/languages.php +++ b/installation/controller/install/languages.php @@ -56,13 +56,33 @@ public function execute() if (!$lids) { // No languages have been selected - $app->enqueueMessage(JText::_('INSTL_LANGUAGES_NO_LANGUAGE_SELECTED')); + $app->enqueueMessage(JText::_('INSTL_LANGUAGES_NO_LANGUAGE_SELECTED'), 'warning'); } else { // Install selected languages $model->install($lids); - $app->enqueueMessage(JText::_('INSTL_LANGUAGES_MORE_LANGUAGES')); + + // Publish the Content Languages. + $tableLanguage = JTable::getInstance('Language'); + + $siteLanguages = $model->getInstalledlangsFrontend(); + + // For each content language. + foreach ($siteLanguages as $siteLang) + { + if ($tableLanguage->load(array('lang_code' => $siteLang->language, 'published' => 0))) + { + if (!$model->publishLanguage($tableLanguage)) + { + $app->enqueueMessage(JText::sprintf('INSTL_DEFAULTLANGUAGE_COULD_NOT_CREATE_CONTENT_LANGUAGE', $siteLang->name), 'warning'); + + continue; + } + } + } + + $app->enqueueMessage(JText::_('INSTL_LANGUAGES_MORE_LANGUAGES'), 'notice'); } // Redirect to the page. diff --git a/installation/controller/setdefaultlanguage.php b/installation/controller/setdefaultlanguage.php index 0c3ed8d3acf44..9a37f09df800e 100644 --- a/installation/controller/setdefaultlanguage.php +++ b/installation/controller/setdefaultlanguage.php @@ -126,22 +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, 'published' => 1)); - - if ($return === false) - { - if (!$model->addLanguage($siteLang)) - { - $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)); diff --git a/installation/model/languages.php b/installation/model/languages.php index 3bdc5fd0de264..8e438fd76e4ea 100644 --- a/installation/model/languages.php +++ b/installation/model/languages.php @@ -728,6 +728,39 @@ public function getSefString($itemLanguage, $siteLanguages) return strtolower($itemLanguage->language); } + /** + * Publish a Content Language. + * + * @param object $tableLanguage Table Language Object. + * + * @return boolean + * + * @since __DEPLOY_VERSION__ + */ + public function publishLanguage($tableLanguage) + { + // Load the native language name. + $installationLocalisedIni = new JLanguage($tableLanguage->lang_code, false); + $nativeLanguageName = $installationLocalisedIni->_('INSTL_DEFAULTLANGUAGE_NATIVE_LANGUAGE_NAME'); + + // If the local name do not exist in the translation file we use the international standard name. + if ($nativeLanguageName == 'INSTL_DEFAULTLANGUAGE_NATIVE_LANGUAGE_NAME') + { + $nativeLanguageName = $tableLanguage->name; + } + + $tableLanguage->title_native = $nativeLanguageName; + $tableLanguage->published = 1; + + // Check and store the data. + if (!$tableLanguage->store()) + { + return false; + } + + return true; + } + /** * Add a Content Language. * @@ -737,11 +770,14 @@ public function getSefString($itemLanguage, $siteLanguages) * @return boolean * * @since 3.2 + * @depreacted 4.0 Not used anymore. */ - public function addLanguage($itemLanguage, $sefLangString = '') + public function addLanguage($itemLanguage, $sefLangString) { $tableLanguage = JTable::getInstance('Language'); + $flag = strtolower(str_replace('-', '_', $itemLanguage->language)); + // Load the native language name. $installationLocalisedIni = new JLanguage($itemLanguage->language, false); $nativeLanguageName = $installationLocalisedIni->_('INSTL_DEFAULTLANGUAGE_NATIVE_LANGUAGE_NAME'); @@ -752,13 +788,40 @@ public function addLanguage($itemLanguage, $sefLangString = '') $nativeLanguageName = $itemLanguage->name; } - // Load the content language. - $tableLanguage->load(array('lang_code' => $itemLanguage->language)); - $tableLanguage->title_native = $nativeLanguageName; - $tableLanguage->published = 1; + $langData = array( + 'lang_id' => 0, + 'lang_code' => $itemLanguage->language, + 'title' => $itemLanguage->name, + 'title_native' => $nativeLanguageName, + 'sef' => $sefLangString, + 'image' => $flag, + 'published' => 1, + 'ordering' => 0, + 'description' => '', + 'metakey' => '', + 'metadesc' => '', + ); - // Check and store the data. - if (!$tableLanguage->check() || !$tableLanguage->store()) + // Bind the data. + if (!$tableLanguage->bind($langData)) + { + return false; + } + + // Check the data. + if (!$tableLanguage->check()) + { + return false; + } + + // Store the data. + if (!$tableLanguage->store()) + { + return false; + } + + // Reorder the data. + if (!$tableLanguage->reorder()) { return false; } From 9ab5e304c9e6a61969e1823a6acd13c90714f678 Mon Sep 17 00:00:00 2001 From: andrepereiradasilva Date: Sat, 3 Sep 2016 13:14:32 +0100 Subject: [PATCH 13/20] cs --- installation/model/languages.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installation/model/languages.php b/installation/model/languages.php index 8e438fd76e4ea..278c4e53dd0d6 100644 --- a/installation/model/languages.php +++ b/installation/model/languages.php @@ -731,7 +731,7 @@ public function getSefString($itemLanguage, $siteLanguages) /** * Publish a Content Language. * - * @param object $tableLanguage Table Language Object. + * @param object $tableLanguage Table Language Object. * * @return boolean * From 49037b45900c5b381a5041a9ba21f10abdca4b7a Mon Sep 17 00:00:00 2001 From: andrepereiradasilva Date: Sat, 3 Sep 2016 13:32:01 +0100 Subject: [PATCH 14/20] fix language names and simplify --- installation/controller/install/languages.php | 18 +--------- installation/model/languages.php | 34 +++++++++---------- 2 files changed, 17 insertions(+), 35 deletions(-) diff --git a/installation/controller/install/languages.php b/installation/controller/install/languages.php index 197a27f2f2a31..60c9222da5c7d 100644 --- a/installation/controller/install/languages.php +++ b/installation/controller/install/languages.php @@ -64,23 +64,7 @@ public function execute() $model->install($lids); // Publish the Content Languages. - $tableLanguage = JTable::getInstance('Language'); - - $siteLanguages = $model->getInstalledlangsFrontend(); - - // For each content language. - foreach ($siteLanguages as $siteLang) - { - if ($tableLanguage->load(array('lang_code' => $siteLang->language, 'published' => 0))) - { - if (!$model->publishLanguage($tableLanguage)) - { - $app->enqueueMessage(JText::sprintf('INSTL_DEFAULTLANGUAGE_COULD_NOT_CREATE_CONTENT_LANGUAGE', $siteLang->name), 'warning'); - - continue; - } - } - } + $model->publishContentLanguages(); $app->enqueueMessage(JText::_('INSTL_LANGUAGES_MORE_LANGUAGES'), 'notice'); } diff --git a/installation/model/languages.php b/installation/model/languages.php index 278c4e53dd0d6..e560ab903efb9 100644 --- a/installation/model/languages.php +++ b/installation/model/languages.php @@ -729,33 +729,31 @@ public function getSefString($itemLanguage, $siteLanguages) } /** - * Publish a Content Language. - * - * @param object $tableLanguage Table Language Object. + * Publish the Installed Content Languages. * * @return boolean * * @since __DEPLOY_VERSION__ */ - public function publishLanguage($tableLanguage) + public function publishContentLanguages() { - // Load the native language name. - $installationLocalisedIni = new JLanguage($tableLanguage->lang_code, false); - $nativeLanguageName = $installationLocalisedIni->_('INSTL_DEFAULTLANGUAGE_NATIVE_LANGUAGE_NAME'); - - // If the local name do not exist in the translation file we use the international standard name. - if ($nativeLanguageName == 'INSTL_DEFAULTLANGUAGE_NATIVE_LANGUAGE_NAME') - { - $nativeLanguageName = $tableLanguage->name; - } + // Publish the Content Languages. + $tableLanguage = JTable::getInstance('Language'); - $tableLanguage->title_native = $nativeLanguageName; - $tableLanguage->published = 1; + $siteLanguages = $this->getInstalledlangs('site'); - // Check and store the data. - if (!$tableLanguage->store()) + // For each content language. + foreach ($siteLanguages as $siteLang) { - return false; + if ($tableLanguage->load(array('lang_code' => $siteLang->language, 'published' => 0))) + { + if (!$tableLanguage->publish()) + { + JFactory::getApplication()->enqueueMessage(JText::sprintf('INSTL_DEFAULTLANGUAGE_COULD_NOT_CREATE_CONTENT_LANGUAGE', $siteLang->name), 'warning'); + + continue; + } + } } return true; From 58d6e68b8935a9fd05e483739df286495ea9c839 Mon Sep 17 00:00:00 2001 From: andrepereiradasilva Date: Sat, 3 Sep 2016 14:21:11 +0100 Subject: [PATCH 15/20] cs --- installation/model/languages.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/installation/model/languages.php b/installation/model/languages.php index e560ab903efb9..fb66383f83fa7 100644 --- a/installation/model/languages.php +++ b/installation/model/languages.php @@ -737,6 +737,8 @@ public function getSefString($itemLanguage, $siteLanguages) */ public function publishContentLanguages() { + $app = JFactory::getApplication(); + // Publish the Content Languages. $tableLanguage = JTable::getInstance('Language'); @@ -749,7 +751,7 @@ public function publishContentLanguages() { if (!$tableLanguage->publish()) { - JFactory::getApplication()->enqueueMessage(JText::sprintf('INSTL_DEFAULTLANGUAGE_COULD_NOT_CREATE_CONTENT_LANGUAGE', $siteLang->name), 'warning'); + $app->enqueueMessage(JText::sprintf('INSTL_DEFAULTLANGUAGE_COULD_NOT_CREATE_CONTENT_LANGUAGE', $siteLang->name), 'warning'); continue; } From 5bff1fa4046c3139d56bb4651c4d5c21ca5f2686 Mon Sep 17 00:00:00 2001 From: andrepereiradasilva Date: Sat, 3 Sep 2016 15:45:12 +0100 Subject: [PATCH 16/20] improve code and deprecate unneed code --- installation/model/languages.php | 67 ++++++++++---------- libraries/cms/installer/adapter/language.php | 63 ++++++++++++------ 2 files changed, 77 insertions(+), 53 deletions(-) diff --git a/installation/model/languages.php b/installation/model/languages.php index fb66383f83fa7..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) { @@ -728,39 +762,6 @@ public function getSefString($itemLanguage, $siteLanguages) return strtolower($itemLanguage->language); } - /** - * 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; - } - /** * Add a Content Language. * diff --git a/libraries/cms/installer/adapter/language.php b/libraries/cms/installer/adapter/language.php index d9c4434e66e54..d7a859a0931a2 100644 --- a/libraries/cms/installer/adapter/language.php +++ b/libraries/cms/installer/adapter/language.php @@ -312,6 +312,7 @@ protected function _install($cname, $basePath, $clientId, &$element) 'lang_code' => $this->tag, 'title' => $siteLanguageManifest['name'], 'title_native' => $siteLanguageManifest['name'], + 'sef' => $this->getSefString($this->tag), 'image' => strtolower(str_replace('-', '_', $this->tag)), 'published' => 0, 'ordering' => 0, @@ -322,28 +323,9 @@ protected function _install($cname, $basePath, $clientId, &$element) 'sitename' => '', ); - $sefs = array( - preg_replace('#([a-z]{2,3})-[A-Z]{2}#', '$1', $this->tag), - strtolower($this->tag), - ); - $tableLanguage = JTable::getInstance('language'); - $created = false; - - // Try storing sef type (xx), fallback to (xx-xx). For instance, for en-US when you have en-GB installed. - foreach ($sefs as $sef) - { - $languageData['sef'] = $sef; - - if ($tableLanguage->bind($languageData) && $tableLanguage->check() && $tableLanguage->store() && $tableLanguage->reorder()) - { - $created = true; - break; - } - } - - if (!$created) + if (!$tableLanguage->bind($languageData) || !$tableLanguage->check() || !$tableLanguage->store() || !$tableLanguage->reorder()) { JLog::add( JText::sprintf('JLIB_INSTALLER_WARNING_UNABLE_TO_INSTALL_CONTENT_LANGUAGE', $siteLanguageManifest['name'], $row->getError()), @@ -365,6 +347,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 * From 63e9589bf70e4d2a24a4c491c5a0aaa790ac41d9 Mon Sep 17 00:00:00 2001 From: andrepereiradasilva Date: Sun, 4 Sep 2016 14:49:31 +0100 Subject: [PATCH 17/20] fix title issues (as possible with current xml scenario) --- libraries/cms/installer/adapter/language.php | 30 ++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/libraries/cms/installer/adapter/language.php b/libraries/cms/installer/adapter/language.php index d7a859a0931a2..470370e8bedd9 100644 --- a/libraries/cms/installer/adapter/language.php +++ b/libraries/cms/installer/adapter/language.php @@ -306,12 +306,38 @@ protected function _install($cname, $basePath, $clientId, &$element) // Load the site language manifest. $siteLanguageManifest = JLanguage::parseXMLLanguageFile(JPATH_SITE . '/language/' . $this->tag . '/' . $this->tag . '.xml'); + // Set the content language title as international_name in site xx-XX.ini, fallback to name in site xx-XX.ini. + $contentLanguageTitle = $siteLanguageManifest['name']; + + if (isset($siteLanguageManifest['international_name']) && $siteLanguageManifest['international_name']) + { + $contentLanguageTitle = $siteLanguageManifest['international_name']; + } + + // Set the content language as native_name in site xx-XX.ini, fallback to installation language variable, fallback to content language title. + $contentLanguageNativeTitle = $contentLanguageTitle; + + if (isset($siteLanguageManifest['native_name']) && $siteLanguageManifest['native_name']) + { + $contentLanguageNativeTitle = $siteLanguageManifest['native_name']; + } + elseif (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')) + { + $contentLanguageNativeTitle = $installationLanguage->_('INSTL_DEFAULTLANGUAGE_NATIVE_LANGUAGE_NAME'); + } + } + // Prepare language data for store. $languageData = array( 'lang_id' => 0, 'lang_code' => $this->tag, - 'title' => $siteLanguageManifest['name'], - 'title_native' => $siteLanguageManifest['name'], + 'title' => $contentLanguageTitle, + 'title_native' => $contentLanguageNativeTitle, 'sef' => $this->getSefString($this->tag), 'image' => strtolower(str_replace('-', '_', $this->tag)), 'published' => 0, From 5f1eda6aede48aa3e287f3f80ed54697010890bb Mon Sep 17 00:00:00 2001 From: andrepereiradasilva Date: Mon, 5 Sep 2016 22:32:41 +0100 Subject: [PATCH 18/20] remove non existent metadata values --- libraries/cms/installer/adapter/language.php | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/libraries/cms/installer/adapter/language.php b/libraries/cms/installer/adapter/language.php index da41dea137ea5..85269882d1064 100644 --- a/libraries/cms/installer/adapter/language.php +++ b/libraries/cms/installer/adapter/language.php @@ -306,22 +306,13 @@ protected function _install($cname, $basePath, $clientId, &$element) // Load the site language manifest. $siteLanguageManifest = JLanguage::parseXMLLanguageFile(JPATH_SITE . '/language/' . $this->tag . '/' . $this->tag . '.xml'); - // Set the content language title as international_name in site xx-XX.ini, fallback to name in site xx-XX.ini. + // Set the content language title as name in site xx-XX.ini. $contentLanguageTitle = $siteLanguageManifest['name']; - if (isset($siteLanguageManifest['international_name']) && $siteLanguageManifest['international_name']) - { - $contentLanguageTitle = $siteLanguageManifest['international_name']; - } - - // Set the content language as native_name in site xx-XX.ini, fallback to installation language variable, fallback to content language title. + // Set the content language as installation native title language variable, fallback to content language title. $contentLanguageNativeTitle = $contentLanguageTitle; - if (isset($siteLanguageManifest['native_name']) && $siteLanguageManifest['native_name']) - { - $contentLanguageNativeTitle = $siteLanguageManifest['native_name']; - } - elseif (file_exists(JPATH_INSTALLATION . '/language/' . $this->tag . '/' . $this->tag . '.xml')) + if (file_exists(JPATH_INSTALLATION . '/language/' . $this->tag . '/' . $this->tag . '.xml')) { $installationLanguage = new JLanguage($this->tag); $installationLanguage->load('', JPATH_INSTALLATION); From 6abce718f586db2f1589bd2c938bb6d1bca303fa Mon Sep 17 00:00:00 2001 From: andrepereiradasilva Date: Tue, 6 Sep 2016 11:28:29 +0100 Subject: [PATCH 19/20] shoudl not be row, it should be tableLanguage --- libraries/cms/installer/adapter/language.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/cms/installer/adapter/language.php b/libraries/cms/installer/adapter/language.php index 85269882d1064..6cb033e6a3c5a 100644 --- a/libraries/cms/installer/adapter/language.php +++ b/libraries/cms/installer/adapter/language.php @@ -345,7 +345,7 @@ protected function _install($cname, $basePath, $clientId, &$element) if (!$tableLanguage->bind($languageData) || !$tableLanguage->check() || !$tableLanguage->store() || !$tableLanguage->reorder()) { JLog::add( - JText::sprintf('JLIB_INSTALLER_WARNING_UNABLE_TO_INSTALL_CONTENT_LANGUAGE', $siteLanguageManifest['name'], $row->getError()), + JText::sprintf('JLIB_INSTALLER_WARNING_UNABLE_TO_INSTALL_CONTENT_LANGUAGE', $siteLanguageManifest['name'], $tableLanguage->getError()), JLog::WARNING, 'jerror' ); From c924445b28cc76afbcddc33ddd611f32757040e4 Mon Sep 17 00:00:00 2001 From: andrepereiradasilva Date: Fri, 9 Sep 2016 12:05:57 +0100 Subject: [PATCH 20/20] don't fallback to en-GB native title --- libraries/cms/installer/adapter/language.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libraries/cms/installer/adapter/language.php b/libraries/cms/installer/adapter/language.php index 6cb033e6a3c5a..bc4d5711ce5d8 100644 --- a/libraries/cms/installer/adapter/language.php +++ b/libraries/cms/installer/adapter/language.php @@ -319,7 +319,17 @@ protected function _install($cname, $basePath, $clientId, &$element) if ($installationLanguage->hasKey('INSTL_DEFAULTLANGUAGE_NATIVE_LANGUAGE_NAME')) { - $contentLanguageNativeTitle = $installationLanguage->_('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'); + } } }