ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
JsonDictionary.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Gettext\Generators;
4 
6 
7 class JsonDictionary extends Generator implements GeneratorInterface
8 {
9  public static $options = 0;
10 
14  public static function toString(Translations $translations)
15  {
16  $array = PhpArray::toArray($translations);
17 
18  //for a simple json translation dictionary, one domain is supported
19  $values = current($array);
20 
21  // remove meta / header data
22  if (array_key_exists('', $values)) {
23  unset($values['']);
24  }
25 
26  //map to a simple json dictionary (no plurals)
27  return json_encode(
28  array_filter(
29  array_map(function ($val) {
30  return isset($val[1]) ? $val[1] : null;
31  }, $values)
32  ),
34  );
35  }
36 }
static toArray(Translations $translations)
Generates an array with the translations.
Definition: PhpArray.php:26
static toString(Translations $translations)
{}.
Class to manage a collection of translations.
$values