Diff: STRATO-apps/wordpress_03/app/wp-content/themes/blocksy/admin/helpers/jed-locale-data.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
3
+
if (! function_exists('blocksy_get_json_translation_files')) {
4
+
function blocksy_get_json_translation_files($domain) {
5
+
$cached_mofiles = [];
6
+
7
+
$locations = [
8
+
WP_LANG_DIR . '/themes',
9
+
WP_LANG_DIR . '/plugins'
10
+
];
11
+
12
+
foreach ($locations as $location) {
13
+
$mofiles = glob($location . '/*.json');
14
+
15
+
if (! $mofiles) {
16
+
continue;
17
+
}
18
+
19
+
$cached_mofiles = array_merge($cached_mofiles, $mofiles);
20
+
}
21
+
22
+
$locale = determine_locale();
23
+
24
+
$result = [];
25
+
26
+
foreach ($cached_mofiles as $single_file) {
27
+
if (strpos($single_file, $locale) === false) {
28
+
continue;
29
+
}
30
+
31
+
$result[] = $single_file;
32
+
}
33
+
34
+
return $result;
35
+
}
36
+
}
37
+
38
+
if (! function_exists('blocksy_get_jed_locale_data')) {
39
+
function blocksy_get_jed_locale_data($domain) {
40
+
static $locale = [];
41
+
42
+
if (isset($locale[$domain])) {
43
+
return $locale[$domain];
44
+
}
45
+
46
+
$translations = get_translations_for_domain($domain);
47
+
48
+
$locale[$domain] = [
49
+
'' => [
50
+
'domain' => $domain,
51
+
'lang' => get_user_locale(),
52
+
]
53
+
];
54
+
55
+
if (! empty($translations->headers['Plural-Forms'])) {
56
+
$locale[$domain]['']['plural_forms'] = $translations->headers['Plural-Forms'];
57
+
}
58
+
59
+
foreach (blocksy_get_json_translation_files($domain) as $file_path) {
60
+
$parsed_json = json_decode(
61
+
call_user_func(
62
+
'file' . '_get_contents',
63
+
$file_path
64
+
),
65
+
true
66
+
);
67
+
68
+
if (
69
+
! $parsed_json
70
+
||
71
+
! isset($parsed_json['locale_data']['messages'])
72
+
) {
73
+
continue;
74
+
}
75
+
76
+
foreach ($parsed_json['locale_data']['messages'] as $msgid => $entry) {
77
+
if (empty($msgid)) {
78
+
continue;
79
+
}
80
+
81
+
$locale[$domain][$msgid] = $entry;
82
+
}
83
+
}
84
+
85
+
foreach ($translations->entries as $msgid => $entry) {
86
+
$locale[$domain][$entry->key()] = $entry->translations;
87
+
}
88
+
89
+
return $locale[$domain];
90
+
}
91
+
}
92
+