Elgg  Version 3.0
MessageTranslator.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\I18n;
4 
12 
13  // TODO Maybe this should be an array of locales to provide multiple fallbacks?
15  private $defaultLocale;
16 
18  private $messages;
19 
26  public function __construct(Locale $defaultLocale, MessageBundle $messages) {
27  $this->defaultLocale = $defaultLocale;
28  $this->messages = $messages;
29  }
30 
34  public function translate($key, array $args = [], Locale $locale = null) {
35  $locales = [
36  $locale,
37  $this->defaultLocale,
38  Locale::parse('en'),
39  ];
40 
41  foreach ($locales as $locale) {
42  if (!$locale) {
43  continue;
44  }
45 
46  $message = $this->messages->get($key, $locale);
47 
48  if ($message) {
49  return $message->format($args);
50  }
51  }
52 
53  return $key;
54  }
55 }
static parse($locale)
Create a language, asserting that the language code is valid.
Definition: Locale.php:43
__construct(Locale $defaultLocale, MessageBundle $messages)
Constructor.
$args
Some servers don&#39;t allow PHP to check the rewrite, so try via AJAX.
WARNING: API IN FLUX.
Definition: Locale.php:13
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:55
translate($key, array $args=[], Locale $locale=null)
Given a message key, returns a best-effort translated string.If the translator doesn&#39;t know how to tr...
WARNING: API IN FLUX.
WARNING: API IN FLUX.