19declare(strict_types=1);
31 private bool $internal =
false;
32 private const LANG_PHP =
'lang.php';
34 private MultiLanguage $multi_language;
35 private string $prefix;
39 ?TranslationsRepository $translations_repository =
null,
43 foreach ($module as $m) {
44 $this->
lng->loadLanguageModule($m);
46 $this->multi_language =
new MultiLanguage($translations_repository);
49 public function t(
string $identifier, ?
string $prefix =
null, array $subsitutions = []): string
51 return $this->translate($identifier, $prefix, $subsitutions);
57 public function txt(
string $identifier, array $subsitutions = []): string
59 return $this->translate($identifier,
null, $subsitutions);
62 public function translate(
string $identifier, ?
string $prefix =
null, array $subsitutions = []): string
64 $key = $prefix !==
null ? $prefix .
'_' . $identifier : $identifier;
66 if (!empty($this->prefix)) {
67 $key = $this->prefix .
'_' . $key;
70 if ($subsitutions !== []) {
71 return sprintf($this->
internal($key, $this->
lng->txt($key)), ...array_values($subsitutions));
74 return $this->
internal($key, $this->
lng->txt($key));
77 public function setGeneralPrefix(
string $prefix): void
79 $this->prefix = $prefix;
82 public function ml(): MultiLanguage
84 return $this->multi_language;
87 private function internal(
string $key,
string $translation):
string
89 if (!$this->
internal) {
93 $file = __DIR__ .
'/' . self::LANG_PHP;
95 $current = (array) ((@include $file) ?? []);
96 $untranslated = ($translation ===
'-' . $key .
'-') || ($translation === $key);
99 if (!($current[$key] ??
false)) {
100 $current[$key] = $translation = $key;
102 file_put_contents($file,
'<?php return ' . var_export($current,
true) .
';');
106 if ($untranslated || ($current[$key] ?? $translation) !== $translation) {
107 return $current[$key] ?? $translation;
__construct()
Constructor setup ILIAS global object @access public.