-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathJson.php
More file actions
88 lines (81 loc) · 2.5 KB
/
Json.php
File metadata and controls
88 lines (81 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
namespace Gettext\Languages\Exporter;
class Json extends Exporter
{
/**
* {@inheritdoc}
*
* @see \Gettext\Languages\Exporter\Exporter::getDescription()
*/
public static function getDescription()
{
return 'Build a compressed JSON-encoded file';
}
/**
* {@inheritdoc}
*
* @see \Gettext\Languages\Exporter\Exporter::supportsFormulasWithAndWithoutParenthesis()
*/
public static function supportsFormulasWithAndWithoutParenthesis()
{
return true;
}
/**
* Return the options for json_encode.
*
* @return int
*/
protected static function getEncodeOptions()
{
$result = 0;
if (defined('\JSON_UNESCAPED_SLASHES')) {
$result |= \JSON_UNESCAPED_SLASHES;
}
if (defined('\JSON_UNESCAPED_UNICODE')) {
$result |= \JSON_UNESCAPED_UNICODE;
}
return $result;
}
/**
* {@inheritdoc}
*
* @see \Gettext\Languages\Exporter\Exporter::toStringDoWithOptions()
*/
protected static function toStringDoWithOptions($languages, array $options)
{
$list = array();
foreach ($languages as $language) {
$item = array();
$item['name'] = $language->name;
if (isset($language->supersededBy)) {
$item['supersededBy'] = $language->supersededBy;
}
if (isset($language->script)) {
$item['script'] = $language->script;
}
if (isset($language->territory)) {
$item['territory'] = $language->territory;
}
if (isset($language->baseLanguage)) {
$item['baseLanguage'] = $language->baseLanguage;
}
if (!empty($options['both-formulas'])) {
$item['formulas'] = array(
'standard' => $language->buildFormula(true),
'php' => $language->formula,
);
} else {
$item['formula'] = $language->formula;
}
$item['plurals'] = count($language->categories);
$item['cases'] = array();
$item['examples'] = array();
foreach ($language->categories as $category) {
$item['cases'][] = $category->id;
$item['examples'][$category->id] = $category->examples;
}
$list[$language->id] = $item;
}
return json_encode($list, static::getEncodeOptions());
}
}