File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed
Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ public function getFilters(): array
3232
3333 private function getPermissionTranslation (string $ string ): string
3434 {
35- return empty ($ string ) ? '' : (Translation::get (sprintf ('permission::%s ' , $ string )) ?? '' );
35+ $ key = sprintf ('permission::%s ' , $ string );
36+ return Translation::has ($ key ) ? Translation::get ($ key ) : '' ;
3637 }
3738}
Original file line number Diff line number Diff line change @@ -66,7 +66,6 @@ public static function get(string $languageKey): string|array|null
6666
6767 return self ::$ translation ->loadedLanguages [self ::$ translation ->defaultLanguage ][$ languageKey ];
6868 } catch (Exception ) {
69- // handle exception
7069 Configuration::getConfigurationInstance ()->getLogger ()->error (
7170 'Error while fetching translation key: ' . $ languageKey
7271 );
@@ -75,6 +74,27 @@ public static function get(string $languageKey): string|array|null
7574 return null ;
7675 }
7776
77+ /**
78+ * Checks if a specific translation key exists in the current or default language.
79+ */
80+ public static function has (string $ languageKey ): bool
81+ {
82+ try {
83+ self ::$ translation ->checkInit ();
84+ self ::$ translation ->checkLanguageLoaded ();
85+
86+ if (isset (self ::$ translation ->loadedLanguages [self ::$ translation ->currentLanguage ][$ languageKey ])) {
87+ return true ;
88+ }
89+ if (isset (self ::$ translation ->loadedLanguages [self ::$ translation ->defaultLanguage ][$ languageKey ])) {
90+ return true ;
91+ }
92+ } catch (Exception ) {
93+ }
94+
95+ return false ;
96+ }
97+
7898 /**
7999 * @throws Exception
80100 */
You can’t perform that action at this time.
0 commit comments