ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Translator.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24
28class Translator
29{
33 private const LANG_PHP = 'lang.php';
34
35 public function __construct(private readonly Container $dic)
36 {
37 $dic->language()->loadLanguageModule('gsfo');
38 }
39
40 public function translate(string $identifier, ?string $prefix = null): string
41 {
42 $key = $prefix !== null ? $prefix . '_' . $identifier : $identifier;
43
44 return $this->dic->language()->txt($key);
45 }
46
47 private function internal(string $translation): string
48 {
49 if ($translation === '-' . $key . '-') {
50 $file = __DIR__ . '/' . self::LANG_PHP;
51 // touch($file);
52 $current = (array) ((@include $file) ?? []);
53 if (!isset($current[$key])) {
54 $current[$key] = $key;
55 file_put_contents($file, '<?php return ' . var_export($current, true) . ';');
56 } else {
57 $translation = $current[$key];
58 }
59 }
60 return $translation;
61 }
62}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
__construct()
Constructor setup ILIAS global object @access public.
Definition: class.ilias.php:76
$dic
Definition: ltiresult.php:33