language.php
3.03 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
136
137
138
139
140
141
142
143
144
<?php
/**
* @package Joomla.Administrator
* @subpackage com_finder
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
/**
* Finder language helper class.
*
* @since 2.5
*/
class FinderHelperLanguage
{
/**
* Method to return a plural language code for a taxonomy branch.
*
* @param string $branchName Branch title.
*
* @return string Language key code.
*
* @since 2.5
*/
public static function branchPlural($branchName)
{
$return = preg_replace('/[^a-zA-Z0-9]+/', '_', strtoupper($branchName));
if ($return !== '_')
{
return 'PLG_FINDER_QUERY_FILTER_BRANCH_P_' . $return;
}
return $branchName;
}
/**
* Method to return a singular language code for a taxonomy branch.
*
* @param string $branchName Branch name.
*
* @return string Language key code.
*
* @since 2.5
*/
public static function branchSingular($branchName)
{
$return = preg_replace('/[^a-zA-Z0-9]+/', '_', strtoupper($branchName));
return 'PLG_FINDER_QUERY_FILTER_BRANCH_S_' . $return;
}
/**
* Method to return the language name for a language taxonomy branch.
*
* @param string $branchName Language branch name.
*
* @return string The language title.
*
* @since 3.6.0
*/
public static function branchLanguageTitle($branchName)
{
$title = $branchName;
if ($branchName === '*')
{
$title = JText::_('JALL_LANGUAGE');
}
else
{
$languages = JLanguageHelper::getLanguages('lang_code');
if (isset($languages[$branchName]))
{
$title = $languages[$branchName]->title;
}
}
return $title;
}
/**
* Method to load Smart Search component language file.
*
* @return void
*
* @since 2.5
*/
public static function loadComponentLanguage()
{
JFactory::getLanguage()->load('com_finder', JPATH_SITE);
}
/**
* Method to load Smart Search plugin language files.
*
* @return void
*
* @since 2.5
*/
public static function loadPluginLanguage()
{
static $loaded = false;
// If already loaded, don't load again.
if ($loaded)
{
return;
}
$loaded = true;
// Get array of all the enabled Smart Search plugin names.
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select(array($db->qn('name'), $db->qn('element')))
->from($db->quoteName('#__extensions'))
->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
->where($db->quoteName('folder') . ' = ' . $db->quote('finder'))
->where($db->quoteName('enabled') . ' = 1');
$db->setQuery($query);
$plugins = $db->loadObjectList();
if (empty($plugins))
{
return;
}
// Load generic language strings.
$lang = JFactory::getLanguage();
$lang->load('plg_content_finder', JPATH_ADMINISTRATOR);
// Load language file for each plugin.
foreach ($plugins as $plugin)
{
$lang->load($plugin->name, JPATH_ADMINISTRATOR)
|| $lang->load($plugin->name, JPATH_PLUGINS . '/finder/' . $plugin->element);
}
}
}