multilang.php
3.34 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
// namespace administrator\components\com_jmap\framework\language;
/**
* @package JMAP::FRAMEWORK::administrator::components::com_jmap
* @subpackage framework
* @subpackage language
* @author Joomla! Extensions Store
* @copyright (C) 2015 - Joomla! Extensions Store
* @license GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html
*/
defined('_JEXEC') or die('Restricted access');
/**
* Multilanguage fallback utility class
*
* @package JMAP::FRAMEWORK::administrator::components::com_jmap
* @subpackage framework
* @subpackage language
* @since 2.0
*/
class JMapLanguageMultilang extends JLanguage {
/**
* 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 front-end, we can avoid the database query.
if ($app->isSite()) {
$enabled = $app->getLanguageFilter();
return $enabled;
}
// If already tested, don't test again.
if (!$tested) {
// Determine status of language filter plug-in.
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('enabled');
$query->from($db->quoteName('#__extensions'));
$query->where($db->quoteName('type') . ' = ' . $db->quote('plugin'));
$query->where($db->quoteName('folder') . ' = ' . $db->quote('system'));
$query->where($db->quoteName('element') . ' = ' . $db->quote('languagefilter'));
$db->setQuery($query);
$enabled = $db->loadResult();
$tested = true;
}
return $enabled;
}
/**
* Get the sef string for the current language
*
* @access public
* @return string
*/
public static function getCurrentSefLanguage() {
static $defaultLanguageSef;
if($defaultLanguageSef) {
return $defaultLanguageSef;
}
$knownLangs = JLanguageHelper::getLanguages();
// Setup predefined site language
$defaultLanguageCode = JFactory::getLanguage()->getTag();
foreach ($knownLangs as $knownLang) {
if($knownLang->lang_code == $defaultLanguageCode) {
$defaultLanguageSef = $knownLang->sef;
break;
}
}
return $defaultLanguageSef;
}
/**
* Load language ID
*
* @access public
* @param string $languagTag
* @return int
*
*/
public static function loadLanguageID($languageTag) {
// Determine status of language filter plug-in.
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('lang_id');
$query->from($db->quoteName('#__languages'));
$query->where($db->quoteName('lang_code') . ' = ' . $db->quote($languageTag));
$db->setQuery($query);
$langID = $db->loadResult();
return $langID;
}
/**
* Override Language instantiator
*
* @access public
* @return JLanguage The Language object.
*/
public static function getInstance($lang = null, $debug = false) {
$conf = JFactory::getConfig();
if(is_null($lang)) {
$locale = $conf->get('language');
} else {
$locale = $lang;
}
$langInstance = new JMapLanguageMultilang($locale);
$langInstance->setDebug($conf->get('debug_lang'));
return $langInstance;
}
}