Source for file languages.php
Documentation is available at languages.php
* @package Joomla.Installation
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
jimport('legacy.component.helper');
* Language Installer model for the Joomla Core Installer.
* @package Joomla.Installation
* @var object Client object
* @var array Languages description
* @var string Language path
* @var integer Total number of languages installed
* @var Admin Id, author of all generated content
* Constructor: Deletes the default installation config file and recreates it with the good config file.
// Overrides application config and set the configuration.php file so tokens and database works
* Generate a list of language choices to install in the Joomla CMS
* @return boolean True if successful
* The following function uses extension_id 600, that is the English language extension id.
* In #__update_sites_extensions you should have 600 linked to the Accredited Translations Repo
$updater->findUpdates(array(600), 0);
$query =
$db->getQuery(true);
// Select the required fields from the updates table
$query->select('update_id, name, version')
$list =
$db->loadObjectList();
if (!$list ||
$list instanceof
Exception)
* Method that installs in Joomla! the selected languages in the Languages View of the installer.
* @param array $lids List of the update_id value of the languages to install
* @return boolean True if successful
/* @var InstallationApplicationWeb $app */
// Loop through every selected language
// Loads the update database object that represents the language
// Get the url to the XML manifest file of the selected language
// Could not find the url, the information in the update server may be corrupt
$message =
JText::sprintf('INSTL_DEFAULTLANGUAGE_COULD_NOT_INSTALL_LANGUAGE', $language->name);
$message .=
' ' .
JText::_('INSTL_DEFAULTLANGUAGE_TRY_LATER');
$app->enqueueMessage($message);
// Based on the language XML manifest get the url of the package to download
// Could not find the url , maybe the url is wrong in the update server, or there is not internet access
$message =
JText::sprintf('INSTL_DEFAULTLANGUAGE_COULD_NOT_INSTALL_LANGUAGE', $language->name);
$message .=
' ' .
JText::_('INSTL_DEFAULTLANGUAGE_TRY_LATER');
$app->enqueueMessage($message);
// Download the package to the tmp folder
if (!$installer->install($package['dir']))
// There was an error installing the package
$message =
JText::sprintf('INSTL_DEFAULTLANGUAGE_COULD_NOT_INSTALL_LANGUAGE', $language->name);
$message .=
' ' .
JText::_('INSTL_DEFAULTLANGUAGE_TRY_LATER');
$app->enqueueMessage($message);
// Cleanup the install files in tmp folder
if (!is_file($package['packagefile']))
$package['packagefile'] =
$config->get('tmp_path') .
'/' .
$package['packagefile'];
// Delete the installed language from the list
* Gets the manifest file of a selected language from a the language list in a update server.
* @param integer $uid The id of the language in the #__updates table
$detailurl =
trim($instance->detailsurl);
* Finds the url of the package to download.
* @param string $remote_manifest Url to the manifest XML file of the remote package
$update->loadFromXML($remote_manifest);
$package_url =
trim($update->get('downloadurl', false)->_data);
* Download a language package from a URL and unpack it in the tmp folder.
* @param string $url Url of the package
* @return array|boolPackage details or false on failure
// Download the package from the given URL
// Was the package downloaded?
$tmp_dest =
$config->get('tmp_path');
// Unpack the downloaded package file
* Get Languages item data for the Administrator
* Get Languages item data for the Frontend
* @return array List of installed languages in the frontend application
* Get Languages item data
* @param string $cms_client Name of the cms client
// Compute all the languages
foreach ($langlist as $lang)
$file =
$path .
'/' .
$lang .
'/' .
$lang .
'.xml';
foreach ($info as $key =>
$value)
// If current then set published
if ($params->get($client->name, 'en-GB') ==
$row->language)
usort($data, array($this, 'compareLanguages'));
* Get installed languages data.
* @param integer $client_id The client ID to retrieve data for
* @return object The language data
// Create a new db object.
$query =
$db->getQuery(true);
// Select field element from the extensions table.
$query->select('a.element, a.name')
->from('#__extensions AS a')
->where('a.type = ' .
$db->quote('language'))
->where('client_id=' . (int)
$client_id);
* Compare two languages in order to sort them.
* @param object $lang1 The first language
* @param object $lang2 The second language
return strcmp($lang1->name, $lang2->name);
* Get the languages folder path.
* @return string The path to the languages folders
* Get the client object of Administrator or Frontend.
* @param string $client Name of the client object
protected function getClient($client =
'administrator')
* Set the default language.
* @param string $language The language to be set as default
* @param string $cms_client The name of the CMS client
public function setDefault($language, $cms_client =
'administrator')
/* @var InstallationApplicationWeb $app */
$params->set($client->name, $language);
$id =
$table->find(array('element' =>
'com_languages'));
$app->enqueueMessage($table->getError(), 'warning');
$table->params = (string)
$params;
$app->enqueueMessage($table->getError(), 'warning');
$app->enqueueMessage($table->getError(), 'warning');
* Get the current setup options from the session.
$options =
$session->get('setup.options', array());
* @param string $view The view being processed
* @return mixed JForm object on success, false on failure.
public function getForm($view =
null)
/* @var InstallationApplicationWeb $app */
$view =
$app->input->getWord('view', 'defaultlanguage');
$app->enqueueMessage($e->getMessage(), 'error');
// Check the session for previously entered form data.
// Bind the form data if present.
* @param string $pluginName The name of plugin
// Create a new db object.
$query =
$db->getQuery(true);
->update('#__extensions')
->where('name = ' .
$db->quote($pluginName))
->where('type = ' .
$db->quote('plugin'));
// Store language filter plugin parameters
if ($pluginName ==
'plg_system_languagefilter')
$params =
'{"detect_browser":"0","automatic_change":"1","item_associations":"1","remove_default_prefix":"0","lang_cookie":"0","alternate_meta":"1"}';
->update('#__extensions')
->set('params = ' .
$db->quote($params))
->where('name = ' .
$db->quote('plg_system_languagefilter'))
->where('type = ' .
$db->quote('plugin'));
* Enable the Language Switcher Module.
'title' =>
'Language Switcher',
'position' =>
'position-0',
'module' =>
'mod_languages',
'{"header_text":"","footer_text":"","dropdown":"0","image":"1","inline":"1","show_active":"1",'
.
'"full_name":"1","layout":"_:default","moduleclass_sfx":"","cache":"0","cache_time":"900","cachemode":"itemid",'
.
'"module_tag":"div","bootstrap_size":"0","header_tag":"h3","header_class":"","style":"0"}',
if (!$tableModule->bind($moduleData))
if (!$tableModule->check())
if (!$tableModule->store())
* Add a Module in Module menus
* @param integer $moduleId The Id of module
// Create a new db object.
$query =
$db->getQuery(true);
// Add Module in Module menus
->insert('#__modules_menu')
->columns(array($db->quoteName('moduleid'), $db->quoteName('menuid')))
->values($moduleId .
', 0');
catch
(RuntimeException $e)
* 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 stdClass $itemLanguage Language Object
* @param stdClass[] $siteLanguages All Language Objects
$langs =
explode('-', $itemLanguage->language);
$prefixToFind =
$langs[0];
$numberPrefixesFound =
0;
foreach ($siteLanguages as $siteLang)
$langs =
explode('-', $siteLang->language);
if ($lang ==
$prefixToFind)
if ($numberPrefixesFound ==
1)
* @param stdClass $itemLanguage Language Object
* @param string $sefLangString String to use for SEF so it doesn't conflict
public function addLanguage($itemLanguage, $sefLangString)
// Load the native language name
$installationLocalisedIni =
new JLanguage($itemLanguage->language, 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 =
$itemLanguage->name;
'lang_code' =>
$itemLanguage->language,
'title' =>
$itemLanguage->name,
'title_native' =>
$nativeLanguageName,
if (!$tableLanguage->bind($langData))
if (!$tableLanguage->check())
if (!$tableLanguage->store())
* @param stdClass $itemLanguage Language Object
'menutype' =>
'mainmenu-' .
strtolower($itemLanguage->language),
'title' =>
'Main Menu (' .
$itemLanguage->language .
')',
'description' =>
'The main menu for the site in language ' .
$itemLanguage->name
if (!$tableMenu->bind($menuData))
if (!$tableMenu->check())
if (!$tableMenu->store())
* @param stdClass $itemLanguage Language Object
$newlanguage =
new JLanguage($itemLanguage->language, false);
$title =
$newlanguage->_('COM_LANGUAGES_HOMEPAGE');
$alias =
'home_' .
$itemLanguage->language;
'menutype' =>
'mainmenu-' .
strtolower($itemLanguage->language),
'link' =>
'index.php?option=com_content&view=featured',
'params' =>
'{"featured_categories":[""],"layout_type":"blog","num_leading_articles":"1",'
.
'"num_intro_articles":"3","num_columns":"3","num_links":"0","orderby_pri":"","orderby_sec":"front",'
.
'"order_date":"","multi_column_order":"1","show_pagination":"2","show_pagination_results":"1","show_noauth":"",'
.
'"article-allow_ratings":"","article-allow_comments":"","show_feed_link":"1","feed_summary":"",'
.
'"show_title":"","link_titles":"","show_intro":"","show_category":"","link_category":"",'
.
'"show_parent_category":"","link_parent_category":"","show_author":"","show_create_date":"",'
.
'"show_modify_date":"","show_publish_date":"","show_item_navigation":"","show_readmore":"",'
.
'"show_icons":"","show_print_icon":"","show_email_icon":"","show_hits":"","menu-anchor_title":"",'
.
'"menu-anchor_css":"","menu_image":"","show_page_heading":1,"page_title":"","page_heading":"",'
.
'"pageclass_sfx":"","menu-meta_description":"","menu-meta_keywords":"","robots":"","secure":0}',
'language' =>
$itemLanguage->language
if (!$tableItem->bind($menuItem))
$tableItem->setLocation($menuItem['parent_id'], 'last-child');
if (!$tableItem->check())
if (!$tableItem->store())
// Rebuild the tree path.
if (!$tableItem->rebuildPath($tableItem->id))
* @param stdClass $itemLanguage Language Object
$title =
'Main menu ' .
$itemLanguage->language;
'position' =>
'position-7',
'params' =>
'{"menutype":"mainmenu-' .
strtolower($itemLanguage->language)
.
'","startLevel":"0","endLevel":"0","showAllChildren":"0","tag_id":"","class_sfx":"","window_open":"",'
.
'"layout":"","moduleclass_sfx":"_menu","cache":"1","cache_time":"900","cachemode":"itemid"}',
'language' =>
$itemLanguage->language,
if (!$tableModule->bind($moduleData))
if (!$tableModule->check())
if (!$tableModule->store())
* Disable Default Main Menu Module
// Create a new db object.
$query =
$db->getQuery(true);
// Add Module in Module menus
->update($db->quoteName('#__modules'))
->set($db->quoteName('published') .
' = 0')
->where($db->quoteName('module') .
' = ' .
$db->quote('mod_menu'))
->where($db->quoteName('language') .
' = ' .
$db->quote('*'))
->where($db->quoteName('client_id') .
' = ' .
$db->quote('0'))
->where($db->quoteName('position') .
' = ' .
$db->quote('position-7'));
* @param string $moduleName The Name of the module to activate
// Create a new db object.
$query =
$db->getQuery(true);
->update($db->quoteName('#__modules'))
->set($db->quoteName('published') .
' = 1')
->where($db->quoteName('module') .
' = ' .
$db->quote($moduleName));
* Method create a category for a specific language
* @param stdClass $itemLanguage Language Object
* @return JTable Category Object
$newlanguage =
new JLanguage($itemLanguage->language, false);
$title =
$newlanguage->_('JCATEGORY');
// Initialize a new category
$category->extension =
'com_content';
$category->title =
$title .
' (' .
strtolower($itemLanguage->language) .
')';
$category->description =
'';
$category->published =
1;
$category->params =
'{"target":"","image":""}';
$category->metadata =
'{"page_title":"","author":"","robots":""}';
$category->language =
$itemLanguage->language;
// Set the location in the tree
$category->setLocation(1, 'last-child');
// Check to make sure our data is valid
if (!$category->store(true))
// Build the path for our category
$category->rebuildPath($category->id);
* Create an article in a specific language
* @param stdClass $itemLanguage Language Object
* @param int $categoryId The id of the category where we want to add the article
* @return JTable Category Object
public function addArticle($itemLanguage, $categoryId)
$newlanguage =
new JLanguage($itemLanguage->language, false);
$newlanguage->load('plg_editors-xtd_article', JPATH_ADMINISTRATOR, $itemLanguage->language, true);
$title =
$newlanguage->_('PLG_ARTICLE_BUTTON_ARTICLE');
$article->title =
$title .
' (' .
strtolower($itemLanguage->language) .
')';
$article->introtext =
'<p>Lorem ipsum ad his scripta blandit partiendo, eum fastidii accumsan euripidis'
.
' in, eum liber hendrerit an. Qui ut wisi vocibus suscipiantur, quo dicit'
.
' ridens inciderint id. Quo mundi lobortis reformidans eu, legimus senserit'
.
'definiebas an eos. Eu sit tincidunt incorrupte definitionem, vis mutat'
.
' affert percipit cu, eirmod consectetuer signiferumque eu per. In usu latine'
.
'equidem dolores. Quo no falli viris intellegam, ut fugit veritus placerat'
.
'per. Ius id vidit volumus mandamus, vide veritus democritum te nec, ei eos'
.
'debet libris consulatu.</p>';
$article->created_by =
$this->getAdminId();
$article->created_by_alias =
'Joomla';
$article->publish_down =
$db->getNullDate();
$article->catid =
$categoryId;
$article->metadata =
'{"robots":"","author":"","rights":"","xreference":"","tags":null}';
$article->language =
$itemLanguage->language;
// Check to make sure our data is valid
// Now store the category
if (!$article->store(true))
$newId =
$article->get('id');
$query =
$db->getQuery(true)
->insert($db->quoteName('#__content_frontpage'))
->values($newId .
', 0');
* Retrieve the admin user id.
* @return int|boolOne Administrator ID
private function getAdminId()
// Return local cached admin ID
$query =
$db->getQuery(true);
// Select the required fields from the updates table
->join('LEFT', '#__user_usergroup_map AS map ON map.user_id = u.id')
->join('LEFT', '#__usergroups AS g ON map.group_id = g.id')
->where('g.title = ' .
$db->q('Super Users'));
if (!$id ||
$id instanceof
Exception)
Documentation generated on Tue, 19 Nov 2013 15:06:42 +0100 by phpDocumentor 1.4.3