Multilanguage.php
2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/**
* Joomla! Content Management System
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Language;
defined('JPATH_PLATFORM') or die;
/**
* Utitlity class for multilang
*
* @since 2.5.4
*/
class Multilanguage
{
/**
* Method to determine if the language filter plugin is enabled.
* This works for both site and administrator.
*
* @return boolean True if site is supporting multiple languages; false otherwise.
*
* @since 2.5.4
*/
public static function isEnabled()
{
// Flag to avoid doing multiple database queries.
static $tested = false;
// Status of language filter plugin.
static $enabled = false;
// Get application object.
$app = \JFactory::getApplication();
// If being called from the frontend, we can avoid the database query.
if ($app->isClient('site'))
{
$enabled = $app->getLanguageFilter();
return $enabled;
}
// If already tested, don't test again.
if (!$tested)
{
// Determine status of language filter plugin.
$db = \JFactory::getDbo();
$query = $db->getQuery(true)
->select('enabled')
->from($db->quoteName('#__extensions'))
->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
->where($db->quoteName('folder') . ' = ' . $db->quote('system'))
->where($db->quoteName('element') . ' = ' . $db->quote('languagefilter'));
$db->setQuery($query);
$enabled = $db->loadResult();
$tested = true;
}
return (bool) $enabled;
}
/**
* Method to return a list of published site languages.
*
* @return array of language extension objects.
*
* @since 3.5
* @deprecated 3.7.0 Use \JLanguageHelper::getInstalledLanguages(0) instead.
*/
public static function getSiteLangs()
{
\JLog::add(__METHOD__ . ' is deprecated. Use \JLanguageHelper::getInstalledLanguages(0) instead.', \JLog::WARNING, 'deprecated');
return \JLanguageHelper::getInstalledLanguages(0);
}
/**
* Method to return a list of language home page menu items.
*
* @return array of menu objects.
*
* @since 3.5
*/
public static function getSiteHomePages()
{
// To avoid doing duplicate database queries.
static $multilangSiteHomePages = null;
if (!isset($multilangSiteHomePages))
{
// Check for Home pages languages.
$db = \JFactory::getDbo();
$query = $db->getQuery(true)
->select('language')
->select('id')
->from($db->quoteName('#__menu'))
->where('home = 1')
->where('published = 1')
->where('client_id = 0');
$db->setQuery($query);
$multilangSiteHomePages = $db->loadObjectList('language');
}
return $multilangSiteHomePages;
}
}