19declare(strict_types=1);
31 private bool $internal =
false;
35 private const LANG_PHP =
'lang.php';
37 private MultiLanguage $multi_language;
41 ?TranslationsRepository $translations_repository =
null,
44 foreach ($module as $m) {
45 $this->
lng->loadLanguageModule($m);
47 $this->multi_language =
new MultiLanguage($translations_repository);
50 public function t(
string $identifier, ?
string $prefix =
null, array $subsitutions = []): string
52 return $this->translate($identifier, $prefix, $subsitutions);
58 public function txt(
string $identifier, array $subsitutions = []): string
60 return $this->translate($identifier,
null, $subsitutions);
63 public function translate(
string $identifier, ?
string $prefix =
null, array $subsitutions = []): string
65 $key = $prefix !==
null ? $prefix .
'_' . $identifier : $identifier;
67 if ($subsitutions !== []) {
68 return sprintf($this->
internal($key, $this->
lng->txt($key)), ...array_values($subsitutions));
71 return $this->
internal($key, $this->
lng->txt($key));
74 public function ml(): MultiLanguage
76 return $this->multi_language;
79 private function internal(
string $key,
string $translation):
string
81 if (!$this->
internal) {
85 $file = __DIR__ .
'/' . self::LANG_PHP;
87 $current = (array) ((@include $file) ?? []);
88 $untranslated = ($translation ===
'-' . $key .
'-');
90 $differs = $untranslated
92 ($current[$key] ??
null) !==
null
93 && ($current[$key] !== $translation)
97 $current[$key] = $translation = $key;
99 file_put_contents($file,
'<?php return ' . var_export($current,
true) .
';');
__construct()
Constructor setup ILIAS global object @access public.