-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathl10n-helper.php
127 lines (103 loc) · 3.71 KB
/
l10n-helper.php
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
/**
* Plugin Name: Localization Helper
* Plugin URI: https://deconf.com
* Description: Shows the originals, domain, context and L10N source file while hovering translated strings (while ALT keypressed)
* Author: Alin Marcu
* Version: 0.2
* Author URI: https://deconf.com
*/
add_filter('gettext', 'L10N_Helper_Collector', 10, 3);
add_filter('gettext_with_context', 'L10N_Helper_Collector_Context', 10, 4);
add_filter('ngettext', 'L10N_Helper_nCollector', 10, 5);
add_filter('ngettext_with_context', 'L10N_Helper_nCollector_Context', 10, 6);
add_filter('load_textdomain_mofile', 'L10N_Helper_MOFiles', 10, 2);
function L10N_Helper_MOFiles($mofile, $domain)
{
global $L10N_Helper_MOFiles;
global $l10n;
$L10N_Helper_MOFiles[$domain][] = array(
$mofile,
isset($l10n[$domain]->entries) ? count($l10n[$domain]->entries) : 0
);
return $mofile;
}
function L10N_Helper_getsource($domain, $text)
{
global $L10N_Helper_MOFiles;
global $l10n;
$filepath = '';
if (isset($L10N_Helper_MOFiles[$domain])) {
if (isset($l10n[$domain]->entries)) {
$index = array_search($text, array_keys($l10n[$domain]->entries));
foreach ($L10N_Helper_MOFiles[$domain] as $data) {
if ($index >= $data[1]) {
$filepath = $data[0];
}
}
}
$filepath = str_replace(ABSPATH, '', $filepath);
}
return $filepath;
}
function L10N_Helper_Collector_Context($translated_text, $text, $context, $domain)
{
global $L10N_Helper_Collection;
$L10N_Helper_Collection[str_replace('\u00a0', ' ', html_entity_decode($translated_text))] = array(
$text,
$domain,
$context,
L10N_Helper_getsource($domain, $text)
);
return $translated_text;
}
function L10N_Helper_Collector($translated_text, $text, $domain)
{
global $L10N_Helper_Collection;
$L10N_Helper_Collection[str_replace('\u00a0', ' ', html_entity_decode($translated_text))] = array(
$text,
$domain,
L10N_Helper_getsource($domain, $text)
);
return $translated_text;
}
function L10N_Helper_nCollector_Context($translated_text, $text, $plural, $number, $context, $domain)
{
global $L10N_Helper_Collection;
$L10N_Helper_Collection[str_replace('\u00a0', ' ', html_entity_decode($translated_text))] = array(
$text,
$domain,
$context,
L10N_Helper_getsource($domain, $text)
);
return $translated_text;
}
function L10N_Helper_nCollector($translated_text, $text, $plural, $number,$domain)
{
global $L10N_Helper_Collection;
$L10N_Helper_Collection[str_replace('\u00a0', ' ', html_entity_decode($translated_text))] = array(
$text,
$domain,
L10N_Helper_getsource($domain, $text)
);
return $translated_text;
}
add_action('wp_footer', 'L10N_Helper_Collection_output');
add_action('admin_footer', 'L10N_Helper_Collection_output');
function L10N_Helper_Collection_output()
{
if (!is_user_logged_in()){
return;
}
global $L10N_Helper_Collection;
global $L10N_Helper_MOFiles;
wp_register_script('L10N-data', plugins_url('js/l10n-helper.js', __FILE__), array(
'jquery',
'jquery-ui-dialog'
), '0.1');
wp_enqueue_style("wp-jquery-ui-dialog");
wp_localize_script('L10N-data', 'L10N_data', $L10N_Helper_Collection);
wp_localize_script('L10N-data', 'L10N_momap', $L10N_Helper_MOFiles);
wp_enqueue_script('L10N-data');
?><div id="l10n-data" style="display: none;"></div><?php
}