| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
class midcom_admin_babel_plugin extends midcom_baseclasses_components_request |
|---|
| 6 |
{ |
|---|
| 7 |
|
|---|
| 8 |
function midcom_admin_babel_plugin() |
|---|
| 9 |
{ |
|---|
| 10 |
parent::__construct(); |
|---|
| 11 |
} |
|---|
| 12 |
|
|---|
| 13 |
function get_plugin_handlers() |
|---|
| 14 |
{ |
|---|
| 15 |
|
|---|
| 16 |
$_MIDCOM->load_library('midgard.admin.asgard'); |
|---|
| 17 |
$_MIDCOM->load_library('midcom.admin.babel'); |
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
return array |
|---|
| 21 |
( |
|---|
| 22 |
'select' => array |
|---|
| 23 |
( |
|---|
| 24 |
'handler' => Array('midcom_admin_babel_handler_process', 'select'), |
|---|
| 25 |
), |
|---|
| 26 |
'status' => array |
|---|
| 27 |
( |
|---|
| 28 |
'handler' => Array('midcom_admin_babel_handler_process', 'status'), |
|---|
| 29 |
'fixed_args' => 'status', |
|---|
| 30 |
'variable_args' => 1, |
|---|
| 31 |
), |
|---|
| 32 |
'edit' => array |
|---|
| 33 |
( |
|---|
| 34 |
'handler' => Array('midcom_admin_babel_handler_process', 'edit'), |
|---|
| 35 |
'fixed_args' => 'edit', |
|---|
| 36 |
'variable_args' => 2, |
|---|
| 37 |
), |
|---|
| 38 |
'save' => array |
|---|
| 39 |
( |
|---|
| 40 |
'handler' => Array('midcom_admin_babel_handler_process', 'save'), |
|---|
| 41 |
'fixed_args' => 'save', |
|---|
| 42 |
'variable_args' => 2, |
|---|
| 43 |
), |
|---|
| 44 |
); |
|---|
| 45 |
} |
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
function calculate_language_status($lang) |
|---|
| 49 |
{ |
|---|
| 50 |
$status = array |
|---|
| 51 |
( |
|---|
| 52 |
'components_core' => array(), |
|---|
| 53 |
'components_other' => array(), |
|---|
| 54 |
'strings_all' => array |
|---|
| 55 |
( |
|---|
| 56 |
'total' => 0, |
|---|
| 57 |
'translated' => 0, |
|---|
| 58 |
), |
|---|
| 59 |
'strings_core' => array |
|---|
| 60 |
( |
|---|
| 61 |
'total' => 0, |
|---|
| 62 |
'translated' => 0, |
|---|
| 63 |
), |
|---|
| 64 |
'strings_other' => array |
|---|
| 65 |
( |
|---|
| 66 |
'total' => 0, |
|---|
| 67 |
'translated' => 0, |
|---|
| 68 |
) |
|---|
| 69 |
); |
|---|
| 70 |
|
|---|
| 71 |
$components = array('midcom'); |
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
foreach ($_MIDCOM->componentloader->manifests as $manifest) |
|---|
| 75 |
{ |
|---|
| 76 |
$components[] = $manifest->name; |
|---|
| 77 |
} |
|---|
| 78 |
|
|---|
| 79 |
foreach ($components as $component) |
|---|
| 80 |
{ |
|---|
| 81 |
$component_l10n = $_MIDCOM->i18n->get_l10n($component); |
|---|
| 82 |
|
|---|
| 83 |
if ($_MIDCOM->componentloader->is_core_component($component)) |
|---|
| 84 |
{ |
|---|
| 85 |
$string_array = 'components_core'; |
|---|
| 86 |
} |
|---|
| 87 |
else |
|---|
| 88 |
{ |
|---|
| 89 |
$string_array = 'components_other'; |
|---|
| 90 |
} |
|---|
| 91 |
|
|---|
| 92 |
$status[$string_array][$component] = array(); |
|---|
| 93 |
|
|---|
| 94 |
$string_ids = array_unique($component_l10n->get_all_string_ids()); |
|---|
| 95 |
|
|---|
| 96 |
$status[$string_array][$component]['total'] = count($string_ids); |
|---|
| 97 |
$status['strings_all']['total'] += $status[$string_array][$component]['total']; |
|---|
| 98 |
|
|---|
| 99 |
if ($string_array == 'components_core') |
|---|
| 100 |
{ |
|---|
| 101 |
$status['strings_core']['total'] += $status[$string_array][$component]['total']; |
|---|
| 102 |
} |
|---|
| 103 |
else |
|---|
| 104 |
{ |
|---|
| 105 |
$status['strings_other']['total'] += $status[$string_array][$component]['total']; |
|---|
| 106 |
} |
|---|
| 107 |
|
|---|
| 108 |
$status[$string_array][$component]['translated'] = 0; |
|---|
| 109 |
|
|---|
| 110 |
foreach ($string_ids as $id) |
|---|
| 111 |
{ |
|---|
| 112 |
if ($component_l10n->string_exists($id, $lang)) |
|---|
| 113 |
{ |
|---|
| 114 |
$status[$string_array][$component]['translated']++; |
|---|
| 115 |
$status['strings_all']['translated']++; |
|---|
| 116 |
|
|---|
| 117 |
if ($_MIDCOM->componentloader->is_core_component($component)) |
|---|
| 118 |
{ |
|---|
| 119 |
$status['strings_core']['translated']++; |
|---|
| 120 |
} |
|---|
| 121 |
else |
|---|
| 122 |
{ |
|---|
| 123 |
$status['strings_other']['translated']++; |
|---|
| 124 |
} |
|---|
| 125 |
} |
|---|
| 126 |
} |
|---|
| 127 |
} |
|---|
| 128 |
|
|---|
| 129 |
return $status; |
|---|
| 130 |
} |
|---|
| 131 |
|
|---|
| 132 |
function navigation() |
|---|
| 133 |
{ |
|---|
| 134 |
$prefix = $_MIDCOM->get_context_data(MIDCOM_CONTEXT_ANCHORPREFIX); |
|---|
| 135 |
$languages = $_MIDCOM->i18n->get_language_db(); |
|---|
| 136 |
$curlang = $_MIDCOM->i18n->get_current_language(); |
|---|
| 137 |
|
|---|
| 138 |
echo "<ul class=\"midgard_admin_asgard_navigation\">\n"; |
|---|
| 139 |
|
|---|
| 140 |
foreach ($languages as $language => $language_info) |
|---|
| 141 |
{ |
|---|
| 142 |
$language_name = $language_info['enname']; |
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
$state = midcom_admin_babel_plugin::calculate_language_status($language); |
|---|
| 146 |
$percentage = round(100 / $state['strings_core']['total'] * $state['strings_core']['translated']); |
|---|
| 147 |
$percentage_other = round(100 / $state['strings_other']['total'] * $state['strings_other']['translated']); |
|---|
| 148 |
|
|---|
| 149 |
if ($percentage >= 96) |
|---|
| 150 |
{ |
|---|
| 151 |
$status = 'ok'; |
|---|
| 152 |
} |
|---|
| 153 |
elseif ($percentage >= 75) |
|---|
| 154 |
{ |
|---|
| 155 |
$status = 'acceptable'; |
|---|
| 156 |
} |
|---|
| 157 |
else |
|---|
| 158 |
{ |
|---|
| 159 |
$status = 'bad'; |
|---|
| 160 |
} |
|---|
| 161 |
|
|---|
| 162 |
echo " <li class=\"status\"><a href=\"{$prefix}__mfa/asgard_midcom.admin.babel/status/{$language}/\">{$language_name} <span class=\"metadata\">({$percentage}%/{$percentage_other}%)</span></a></li>\n"; |
|---|
| 163 |
} |
|---|
| 164 |
|
|---|
| 165 |
echo "</ul>\n"; |
|---|
| 166 |
|
|---|
| 167 |
} |
|---|
| 168 |
|
|---|
| 169 |
} |
|---|
| 170 |
|
|---|
| 171 |
?> |
|---|