Elgg  Version 2.3
MessageTranslator.php
Go to the documentation of this file.
1 <?php
2 namespace Elgg\I18n;
3 
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 
32  public function translate($key, array $args = [], Locale $locale = null) {
33  $locales = [
34  $locale,
35  $this->defaultLocale,
36  Locale::parse('en'),
37  ];
38 
39  foreach ($locales as $locale) {
40  if (!$locale) {
41  continue;
42  }
43 
44  $message = $this->messages->get($key, $locale);
45 
46  if ($message) {
47  return $message->format($args);
48  }
49  }
50 
51  return $key;
52  }
53 }
static parse($locale)
Create a language, asserting that the language code is valid.
Definition: Locale.php:41
__construct(Locale $defaultLocale, MessageBundle $messages)
Constructor.
$args
Some servers don&#39;t allow PHP to check the rewrite, so try via AJAX.
elgg page messages
Definition: admin.css.php:233
WARNING: API IN FLUX.
Definition: Locale.php:13
$key
Definition: summary.php:34
translate($key, array $args=[], Locale $locale=null)
WARNING: API IN FLUX.
WARNING: API IN FLUX.