ILIAS  trunk Revision v11.0_alpha-2645-g16283d3b3f8
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 {
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:35
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
translate(string $identifier, ?string $prefix=null)
Definition: Translator.php:40
__construct(private readonly Container $dic)
Definition: Translator.php:35
$dic
Definition: result.php:31