1
0

LazyL10N.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\L10N;
  8. use OCP\IL10N;
  9. class LazyL10N implements IL10N {
  10. /** @var IL10N */
  11. private $l;
  12. /** @var \Closure */
  13. private $factory;
  14. public function __construct(\Closure $factory) {
  15. $this->factory = $factory;
  16. }
  17. private function getL(): IL10N {
  18. if ($this->l === null) {
  19. $this->l = ($this->factory)();
  20. }
  21. return $this->l;
  22. }
  23. public function t(string $text, $parameters = []): string {
  24. return $this->getL()->t($text, $parameters);
  25. }
  26. public function n(string $text_singular, string $text_plural, int $count, array $parameters = []): string {
  27. return $this->getL()->n($text_singular, $text_plural, $count, $parameters);
  28. }
  29. public function l(string $type, $data, array $options = []) {
  30. return $this->getL()->l($type, $data, $options);
  31. }
  32. public function getLanguageCode(): string {
  33. return $this->getL()->getLanguageCode();
  34. }
  35. public function getLocaleCode(): string {
  36. return $this->getL()->getLocaleCode();
  37. }
  38. }