ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
Translator.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\GlobalScreen_\UI;
22 
24 
29 {
30  private const LANG_PHP = 'lang.php';
31 
32  public function __construct(private readonly Container $dic)
33  {
34  $dic->language()->loadLanguageModule('gsfo');
35  }
36 
37  public function translate(string $identifier, ?string $prefix = null): string
38  {
39  $key = $prefix !== null ? $prefix . '_' . $identifier : $identifier;
40 
41  return $this->dic->language()->txt($key);
42  }
43 
44  private function internal(string $translation): string
45  {
46  if ($translation === '-' . $key . '-') {
47  $file = __DIR__ . '/' . self::LANG_PHP;
48  // touch($file);
49  $current = (array) ((@include $file) ?? []);
50  if (!isset($current[$key])) {
51  $current[$key] = $key;
52  file_put_contents($file, '<?php return ' . var_export($current, true) . ';');
53  } else {
54  $translation = $current[$key];
55  }
56  }
57  return $translation;
58  }
59 }
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:35
translate(string $identifier, ?string $prefix=null)
Definition: Translator.php:37
__construct(private readonly Container $dic)
Definition: Translator.php:32
$dic
Definition: ltiresult.php:33