Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JLanguage(Helper) improvements #87

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ public static function getContentlangs()
*
* @return array of language extension objects.
*
* @deprecated 4.0 Use JLanguageMultilang::getSiteLangs() instead.
* @deprecated 4.0 Use JLanguageHelper::getInstalledLanguages(0) instead.
*/
public static function getSitelangs()
{
JLog::add(__METHOD__ . ' is deprecated, use JLanguageMultilang::getSiteLangs() instead.', JLog::WARNING, 'deprecated');
JLog::add(__METHOD__ . ' is deprecated, use JLanguageHelper::getInstalledLanguages(0) instead.', JLog::WARNING, 'deprecated');

return JLanguageMultilang::getSiteLangs();
return JLanguageHelper::getInstalledLanguages(0);
}

/**
Expand Down
83 changes: 25 additions & 58 deletions administrator/components/com_languages/models/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,68 +198,36 @@ public function getData()
{
$this->data = array();

// Get information.
$db = $this->getDbo();
$query = $db->getQuery(true);

// Select languages installed from the extensions table.
$query->select($db->quoteName(array('a.element', 'a.client_id', 'a.extension_id')))
->from($db->quoteName('#__extensions', 'a'))
->where($db->quoteName('a.type') . ' = ' . $db->quote('language'))
->where($db->quoteName('state') . ' = 0')
->where($db->quoteName('enabled') . ' = 1');

// For client_id = 1 do we need to check language table also?
$db->setQuery($query);
$langlist = $db->loadObjectList();
$langlist = JLanguageHelper::getInstalledLanguages(null, false, true);

// Compute all the languages.
foreach ($langlist as $lang)
foreach ($langlist as $clientId => $language)
{
$client = JApplicationHelper::getClientInfo($lang->client_id);
$clientPath = (int) $lang->client_id === 0 ? JPATH_SITE : JPATH_ADMINISTRATOR;
$metafilePath = $clientPath . '/language/' . $lang->element . '/' . $lang->element . '.xml';

$info = JApplicationHelper::parseXMLLangMetaFile($metafilePath);
if (!is_array($info))
foreach ($language as $languageCode => $lang)
{
$app = JFactory::getApplication();
$app->enqueueMessage(JText::sprintf('COM_LANGUAGES_ERROR_LANGUAGE_METAFILE_MISSING', $lang->element, $metafilePath), 'warning');

continue;
$row = new StdClass;
$row->language = $lang->element;
$row->client_id = (int) $lang->client_id;
$row->extension_id = (int) $lang->extension_id;

foreach ($lang->manifest as $key => $value)
{
$row->$key = $value;
}

// Fix wrongly set parentheses in RTL languages
if (JFactory::getLanguage()->isRtl())
{
$row->name = html_entity_decode($row->name . '‎', ENT_QUOTES, 'UTF-8');
}

// If current than set published.
$clientInfo = JApplicationHelper::getClientInfo($lang->client_id);
$row->published = (int) (JComponentHelper::getParams('com_languages')->get($clientInfo->name, 'en-GB') == $row->language);
$row->checked_out = 0;
$this->data[] = $row;
}

$row = new StdClass;

$row->language = $lang->element;
$row->client_id = (int) $lang->client_id;
$row->extension_id = (int) $lang->extension_id;

foreach ($info as $key => $value)
{
$row->$key = $value;
}

// Fix wrongly set parentheses in RTL languages
if (JFactory::getLanguage()->isRtl())
{
$row->name = html_entity_decode($row->name . '‎', ENT_QUOTES, 'UTF-8');
}

// If current than set published.
$params = JComponentHelper::getParams('com_languages');

if ($params->get($client->name, 'en-GB') == $row->language)
{
$row->published = 1;
}
else
{
$row->published = 0;
}

$row->checked_out = 0;
$this->data[] = $row;
}
}

Expand Down Expand Up @@ -456,8 +424,7 @@ protected function getPath()
{
if (is_null($this->path))
{
$client = $this->getClient();
$this->path = JLanguage::getLanguagePath($client->path);
$this->path = JLanguageHelper::getLanguagePath($this->getClient()->path);
}

return $this->path;
Expand Down
4 changes: 2 additions & 2 deletions administrator/components/com_languages/models/overrides.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ public function getLanguages()

// Get all languages of frontend and backend.
$languages = array();
$site_languages = JLanguage::getKnownLanguages(JPATH_SITE);
$admin_languages = JLanguage::getKnownLanguages(JPATH_ADMINISTRATOR);
$site_languages = JLanguageHelper::getKnownLanguages(JPATH_SITE);
$admin_languages = JLanguageHelper::getKnownLanguages(JPATH_ADMINISTRATOR);

// Create a single array of them.
foreach ($site_languages as $tag => $language)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function display($tpl = null)
$this->switchers = MultilangstatusHelper::getLangswitchers();
$this->listUsersError = MultilangstatusHelper::getContacts();
$this->contentlangs = MultilangstatusHelper::getContentlangs();
$this->site_langs = JLanguageMultilang::getSiteLangs();
$this->site_langs = JLanguageHelper::getInstalledLanguages(0);
$this->statuses = MultilangstatusHelper::getStatus();
$this->homepages = JLanguageMultilang::getSiteHomePages();

Expand Down
8 changes: 4 additions & 4 deletions components/com_users/helpers/html/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,14 @@ public static function admin_language($value)
}
else
{
$path = JLanguage::getLanguagePath(JPATH_ADMINISTRATOR, $value);
$path = JLanguageHelper::getLanguagePath(JPATH_ADMINISTRATOR, $value);
$file = "$value.xml";

$result = null;

if (is_file("$path/$file"))
{
$result = JLanguage::parseXMLLanguageFile("$path/$file");
$result = JLanguageHelper::parseXMLLanguageFile("$path/$file");
}

if ($result)
Expand Down Expand Up @@ -194,14 +194,14 @@ public static function language($value)
}
else
{
$path = JLanguage::getLanguagePath(JPATH_SITE, $value);
$path = JLanguageHelper::getLanguagePath(JPATH_SITE, $value);
$file = "$value.xml";

$result = null;

if (is_file("$path/$file"))
{
$result = JLanguage::parseXMLLanguageFile("$path/$file");
$result = JLanguageHelper::parseXMLLanguageFile("$path/$file");
}

if ($result)
Expand Down
51 changes: 13 additions & 38 deletions installation/application/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,52 +311,27 @@ public function getLocalise()
*/
public function getLocaliseAdmin($db = false)
{
// Read the files in the admin area.
$path = JLanguage::getLanguagePath(JPATH_ADMINISTRATOR);
$langfiles['admin'] = JFolder::folders($path);

// Read the files in the site area.
$path = JLanguage::getLanguagePath(JPATH_SITE);
$langfiles['site'] = JFolder::folders($path);
$langfiles = array();

// if db connection, fetch them from the database.
if ($db)
{
$langfiles_disk = $langfiles;
$langfiles = array();
$langfiles['admin'] = array();
$langfiles['site'] = array();

$query = $db->getQuery(true)
->select($db->quoteName(array('element','client_id')))
->from($db->quoteName('#__extensions'))
->where($db->quoteName('type') . ' = ' . $db->quote('language'));
$db->setQuery($query);
$langs = $db->loadObjectList();

foreach ($langs as $lang)
foreach (JLanguageHelper::getInstalledLanguages() as $clientId => $language)
{
switch ($lang->client_id)
$clientName = $clientId === 0 ? 'site' : 'admin';

foreach ($language as $languageCode => $lang)
{
// Site.
case 0:
if (in_array($lang->element, $langfiles_disk['site']))
{
$langfiles['site'][] = $lang->element;
}

break;

// Administrator.
case 1:
if (in_array($lang->element, $langfiles_disk['admin']))
{
$langfiles['admin'][] = $lang->element;
}

break;
$langfiles[$clientName][] = $lang->element;
}
}
}
// Read the folder names in the site and admin area.
else
{
$langfiles['site'] = JFolder::folders(JLanguageHelper::getLanguagePath(JPATH_SITE));
$langfiles['admin'] = JFolder::folders(JLanguageHelper::getLanguagePath(JPATH_ADMINISTRATOR));
}

return $langfiles;
}
Expand Down
2 changes: 1 addition & 1 deletion installation/model/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function initialise($options)
$currentLang = $lang->getTag();

// Load the selected language
if (JLanguage::exists($currentLang, JPATH_ADMINISTRATOR))
if (JLanguageHelper::exists($currentLang, JPATH_ADMINISTRATOR))
{
$lang->load('joomla', JPATH_ADMINISTRATOR, $currentLang, true);
}
Expand Down
3 changes: 1 addition & 2 deletions installation/model/languages.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,7 @@ protected function getPath()
{
if (is_null($this->path))
{
$client = $this->getClient();
$this->path = JLanguage::getLanguagePath($client->path);
$this->path = JLanguageHelper::getLanguagePath($this->getClient()->path);
}

return $this->path;
Expand Down
6 changes: 3 additions & 3 deletions libraries/cms/application/administrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ protected function initialiseApp($options = array())
$lang = $user->getParam('admin_language');

// Make sure that the user's language exists
if ($lang && JLanguage::exists($lang))
if ($lang && JLanguageHelper::exists($lang))
{
$options['language'] = $lang;
}
Expand All @@ -275,11 +275,11 @@ protected function initialiseApp($options = array())
}

// One last check to make sure we have something
if (!JLanguage::exists($options['language']))
if (!JLanguageHelper::exists($options['language']))
{
$lang = $this->get('language', 'en-GB');

if (JLanguage::exists($lang))
if (JLanguageHelper::exists($lang))
{
$options['language'] = $lang;
}
Expand Down
12 changes: 6 additions & 6 deletions libraries/cms/application/site.php
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ protected function initialiseApp($options = array())
$lang = $this->input->getString('language', null);

// Make sure that the user's language exists
if ($lang && JLanguage::exists($lang))
if ($lang && JLanguageHelper::exists($lang))
{
$options['language'] = $lang;
}
Expand All @@ -624,7 +624,7 @@ protected function initialiseApp($options = array())
$lang = $this->input->cookie->get(md5($this->get('secret') . 'language'), null, 'string');

// Make sure that the user's language exists
if ($lang && JLanguage::exists($lang))
if ($lang && JLanguageHelper::exists($lang))
{
$options['language'] = $lang;
}
Expand All @@ -636,7 +636,7 @@ protected function initialiseApp($options = array())
$lang = $user->getParam('language');

// Make sure that the user's language exists
if ($lang && JLanguage::exists($lang))
if ($lang && JLanguageHelper::exists($lang))
{
$options['language'] = $lang;
}
Expand All @@ -648,7 +648,7 @@ protected function initialiseApp($options = array())
$lang = JLanguageHelper::detectLanguage();

// Make sure that the user's language exists
if ($lang && JLanguage::exists($lang))
if ($lang && JLanguageHelper::exists($lang))
{
$options['language'] = $lang;
}
Expand All @@ -662,11 +662,11 @@ protected function initialiseApp($options = array())
}

// One last check to make sure we have something
if (!JLanguage::exists($options['language']))
if (!JLanguageHelper::exists($options['language']))
{
$lang = $this->config->get('language', 'en-GB');

if (JLanguage::exists($lang))
if (JLanguageHelper::exists($lang))
{
$options['language'] = $lang;
}
Expand Down
25 changes: 11 additions & 14 deletions libraries/cms/html/contentlanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,29 @@ abstract class JHtmlContentLanguage
*/
public static function existing($all = false, $translate = false)
{
if (empty(static::$items))
if (is_null($items))
{
// Get the database object and a new query object.
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$contentLanguages = JLanguageHelper::getContentLanguages(true, null, 'title', 'ASC');

// Build the query.
$query->select('a.lang_code AS value, a.title AS text, a.title_native')
->from('#__languages AS a')
->where('a.published >= 0')
->order('a.title');
$items = array();

// Set the query and load the options.
$db->setQuery($query);
static::$items = $db->loadObjectList();
foreach($contentLanguages as $key => $language)
{
$items[$key]->value = $language->lang_code;
$items[$key]->text = $language->title;
$items[$key]->title_native = $language->title_native;
}
}

if ($all)
{
$all_option = array(new JObject(array('value' => '*', 'text' => $translate ? JText::alt('JALL', 'language') : 'JALL_LANGUAGE')));

return array_merge($all_option, static::$items);
return array_merge($all_option, $items);
}
else
{
return static::$items;
return $items;
}
}
}
Loading