1 | <?php |
||
27 | trait File |
||
28 | { |
||
29 | /** |
||
30 | * \addtogroup Localization Localization |
||
31 | * \brief Methods to create a localized bot. |
||
32 | * \details Localization files must have this syntax: |
||
33 | * file <code>./localization/en.json</code>: |
||
34 | * |
||
35 | * {"Hello_Msg": "Hello"} |
||
36 | * |
||
37 | * File <code>./localization/it.json</code>: |
||
38 | * |
||
39 | * {"Hello_Msg": "Ciao"} |
||
40 | * |
||
41 | * Usage in <code>processMessage()</code>: |
||
42 | * |
||
43 | * $sendMessage($this->local[$this->language]["Hello_Msg"]); |
||
44 | * |
||
45 | * @{ |
||
46 | */ |
||
47 | |||
48 | /** @internal |
||
49 | * \brief Store the localized strings. */ |
||
50 | protected $local; |
||
51 | |||
52 | /** \brief Source for localization files. */ |
||
53 | protected $localization_dir = './localization'; |
||
54 | |||
55 | /** |
||
56 | * @internal |
||
57 | * \brief Load a localization file into the localized strings array. |
||
58 | * @param string $lang Language to load. |
||
59 | * @param string $dir Directory in which there are the JSON files. |
||
60 | * @return bool True if loaded. |
||
61 | */ |
||
62 | protected function loadSingleLanguage(string $lang = 'en', string $dir = './localization') : bool |
||
84 | |||
85 | /** |
||
86 | * \brief Load all localization files (like JSON) from a folder and set them in <code>$local</code> variable. |
||
87 | * \details Save all localization files, using JSON format, from a directory and put |
||
88 | * the contents in <code>$local</code> variable. |
||
89 | * |
||
90 | * Each file will be saved into <code>$local</code> with the first two letters of the filename as the index. |
||
91 | * @param string $dir Source directory for localization files. |
||
92 | * @return bool True if the directory could be opened without errors. |
||
93 | */ |
||
94 | public function loadAllLanguages(string $dir = './localization') : bool |
||
114 | |||
115 | /** |
||
116 | * @internal |
||
117 | * \brief Load localization for current language and mode. |
||
118 | * \details This method will load only the current user/group localization file if the bot is using webhook, all files otherwise. |
||
119 | * @param string $dir Directory where the localization file is stored. If no directory is given (by default) it will load it from $localization_dir (which is ./localization if it is not set). |
||
120 | * @return bool True if the localization has been loaded or it is already loaded. |
||
121 | */ |
||
122 | public function loadCurrentLocalization(string $dir = '') : bool |
||
142 | |||
143 | /** |
||
144 | * \brief Change source directory for localization files. |
||
145 | * @param string $dir Source directory. |
||
146 | */ |
||
147 | public function setLocalizationDir(string $dir) |
||
151 | |||
152 | /** @} */ |
||
153 | } |
||
154 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.