|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the PhpBotFramework. |
|
5
|
|
|
* |
|
6
|
|
|
* PhpBotFramework is free software: you can redistribute it and/or modify |
|
7
|
|
|
* it under the terms of the GNU Lesser General Public License as |
|
8
|
|
|
* published by the Free Software Foundation, version 3. |
|
9
|
|
|
* |
|
10
|
|
|
* PhpBotFramework is distributed in the hope that it will be useful, but |
|
11
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13
|
|
|
* Lesser General Public License for more details. |
|
14
|
|
|
* |
|
15
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
|
16
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace PhpBotFramework\Localization; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* \addtogroup Modules |
|
23
|
|
|
* @{ |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
/** \class LocalizedString |
|
27
|
|
|
*/ |
|
28
|
|
|
trait LocalizedString |
|
29
|
|
|
{ |
|
30
|
|
|
/** @} */ |
|
31
|
|
|
|
|
32
|
|
|
abstract public function getLanguageRedis(string $default_language = 'en', int $expiring_time = 86400) : string; |
|
33
|
|
|
abstract public function loadCurrentLocalization(string $dir = '') : bool; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* \addtogroup Localization Localization |
|
37
|
|
|
* @{ |
|
38
|
|
|
*/ |
|
39
|
|
|
|
|
40
|
|
|
/** \brief Current user/group language. */ |
|
41
|
|
|
public $language; |
|
42
|
|
|
|
|
43
|
|
|
/** \brief (<i>Internal</i>) True if the bot is using webhook? */ |
|
44
|
|
|
protected $_is_webhook; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* \brief Get a localized string giving an index. |
|
48
|
|
|
* \details Using LocalizedString::language this method get the string of the index given localized string in language of the current user/group. |
|
49
|
|
|
* This method will load the language first, using PhpBotFramework\Localization\Language::getLanguage(), if the language has not been set. |
|
50
|
|
|
* If the localization file for the user/group language has not been load yet, it will load it (load only the single localization file if the bot is using webhook, load all otherwise). |
|
51
|
|
|
* @param string $index Index of the localized string to get. |
|
52
|
|
|
* @return string Localized string in the current user/group language. |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getStr($index) |
|
55
|
|
|
{ |
|
56
|
|
|
if (!isset($this->language)) { |
|
57
|
|
|
$this->getLanguage(); |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
$this->loadLocalization(); |
|
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
// Check if the requested string exists |
|
63
|
|
|
if (isset($this->local[$this->language][$index])) { |
|
64
|
|
|
return $this->local[$this->language][$index]; |
|
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
throw BotException("Index '$index' is not set for {$this->language}"); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** @} */ |
|
71
|
|
|
} |
|
72
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.