Changeset 23472
- Timestamp:
- Jun 23, 2013, 7:50:07 PM (11 years ago)
- Location:
- extensions/plugin_lang_analysis
- Files:
-
- 3 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/plugin_lang_analysis/admin.php
r23467 r23472 7 7 8 8 include_once(PLA_PATH . 'include/functions.inc.php'); 9 include_once(PHPWG_ROOT_PATH . ' /admin/include/plugins.class.php');9 include_once(PHPWG_ROOT_PATH . 'admin/include/plugins.class.php'); 10 10 $plugins = new plugins(); 11 11 12 /* PLUGINS LIST */12 /* SELECT */ 13 13 if (!isset($_GET['plugin_id'])) 14 14 { … … 20 20 } 21 21 22 /* FILES LIST*/22 /* CONFIG */ 23 23 else if (!isset($_GET['analyze'])) 24 24 { … … 45 45 foreach ($files as &$file) 46 46 { 47 if (isset($saved_files[ $file]))48 { 49 $file = $saved_files[ $file];47 if (isset($saved_files[ $file ])) 48 { 49 $file = $saved_files[ $file ]; 50 50 $file['lang_files'] = array_intersect($file['lang_files'], array_keys($language_files)); 51 51 } … … 65 65 'PLA_PLUGIN' => $plugins->fs_plugins[ $_GET['plugin_id'] ], 66 66 'PLA_FILES' => $files, 67 'PLA_LANG_FILES' => $language_files,67 'PLA_LANG_FILES' => array_keys($language_files), 68 68 'F_ACTION' => PLA_ADMIN.'&plugin_id='.$_GET['plugin_id'].'&analyze', 69 69 'U_BACK' => PLA_ADMIN, 70 70 )); 71 71 } 72 73 /* ANALYSIS */ 72 74 else 73 75 { … … 78 80 foreach ($_POST['files'] as $file => $data) 79 81 { 80 $files[ $file] = array(82 $files[ $file ] = array( 81 83 'path' => $file, 82 84 'is_admin' => $data['is_admin']=='true', … … 85 87 if (!empty($data['lang_files'])) 86 88 { 87 $files[ $file]['lang_files'] = array_keys(array_filter($data['lang_files'], create_function('$f', 'return $f=="true";')));89 $files[ $file ]['lang_files'] = array_keys(array_filter($data['lang_files'], create_function('$f', 'return $f=="true";'))); 88 90 } 89 91 } … … 125 127 } 126 128 127 // analy ze129 // analyse 128 130 foreach ($strings as $string => &$string_data) 129 131 { 130 // find where t ehstring is defined132 // find where the string is defined 131 133 $string_data['in_common'] = array_key_exists($string, $lang_common); 132 134 $string_data['in_admin'] = array_key_exists($string, $lang_admin); … … 137 139 } 138 140 141 // very rare case 142 if (count($string_data['in_plugin'])>1) 143 { 144 $string_data['warnings'][] = l10n('This string is translated in multiple files'); 145 } 146 139 147 $missing = $useless = $ok = false; 140 148 $string_data['is_admin'] = true; 141 149 142 // analy ze for each file where the string exists150 // analyse for each file where the string exists 143 151 foreach ($string_data['files'] as $file => &$file_data) 144 152 { … … 147 155 148 156 // find if the string is translated in one of the language files included in this file 149 $exists = false; 150 foreach ($file_data['lang_files'] as $lang_file) 151 { 152 if (in_array($lang_file, $string_data['in_plugin'])) 153 { 154 $exists = true; 155 break; 156 } 157 } 157 $exists = count(array_intersect($file_data['lang_files'], $string_data['in_plugin'])) > 0; 158 158 159 159 // useless if translated in the plugin AND in common or admin … … 193 193 else 194 194 { 195 // another very rare case 196 if ($useless) 197 { 198 $string_data['warnings'][] = l10n('This string is useless in some files'); 199 } 200 195 201 $string_data['stat'] = 'ok'; 196 202 $counts['ok']++; … … 199 205 unset($string_data); 200 206 201 uksort($strings, 'strnatcasecmp'); 207 uksort($strings, 'strnatcasecmp'); // natural sort 202 208 $counts['total'] = array_sum($counts); 203 209 … … 206 212 'PLA_PLUGIN' => $plugins->fs_plugins[ $_GET['plugin_id'] ], 207 213 'PLA_STRINGS' => $strings, 208 'PLA_LANG_FILES' => $language_files,214 'PLA_LANG_FILES' => array_keys($language_files), 209 215 'PLA_COUNTS' => $counts, 210 216 'U_BACK' => PLA_ADMIN.'&plugin_id='.$_GET['plugin_id'], … … 215 221 $template->assign(array( 216 222 'PLA_PATH'=> PLA_PATH, 217 'PLA_ABS_PATH'=> realpath(PLA_PATH) ,223 'PLA_ABS_PATH'=> realpath(PLA_PATH).'/', 218 224 'PLA_ADMIN' => PLA_ADMIN, 219 225 )); -
extensions/plugin_lang_analysis/template/main.tpl
r23467 r23472 1 {combine_css path=$PLA_PATH|@cat:"template/style.css"} 2 {combine_css path=$PLA_PATH|@cat:"template/fontello/css/fontello_pla.css"} 3 1 {combine_css path=$PLA_PATH|cat:'template/style.css'} 2 {combine_css path=$PLA_PATH|cat:'template/fontello/css/fontello_pla.css'} 4 3 5 4 <div class="titrePage"> 6 <h2>Plugin Language Analysis</h2> 5 <h2> 6 Plugin Language Analysis 7 {if isset($PLA_PLUGIN)}[{$PLA_PLUGIN.name}]{/if} 8 </h2> 7 9 </div> 10 11 {include file=$PLA_ABS_PATH|cat:'template/'|cat:$PLA_STEP|cat:'.tpl'} 8 12 9 13 {if isset($U_BACK)} 10 14 <p style="text-align:left;margin-left:20px;"><a href="{$U_BACK}" class="buttonLike">{'Back'|@translate}</a></p> 11 15 {/if} 12 13 14 {* <!-- select --> *}15 {if $PLA_STEP=='select'}16 {footer_script}{literal}17 $('form#pla').submit(function() {18 window.location.href = location.href + '&plugin_id=' + $(this).find('select').val();19 return false;20 });21 {/literal}{/footer_script}22 23 <form method="GET" action="{$F_ACTION}" class="properties" id="pla">24 <fieldset>25 <legend>{'How to use?'|@translate}</legend>26 27 <p>28 This tool analyzes each file of the selected plugin, searching for <b>l10n</b>, <b>l10n_dec</b> and <b>translate</b> functions.<br>29 Then it compares the matched strings to the content of the plugin language file and the common and admin core language files.<br>30 Each file of the plugin can be configured as <b>Common</b> (public) or <b>Admin</b>.<br>31 <br>32 When the analysis is complete, each string can have one of these three status :33 </p>34 35 <dl style="margin-left:30px;">36 <dt class="iconpla-attention">missing</dt>37 <dd>38 not in the plugin language file<br>39 <b>AND</b> not in the common language file<br>40 <b>AND</b> (<br>41 belonging to at least one common file<br>42 <b>OR</b> not in the admin language file<br>43 )44 </dd>45 46 <dt class="iconpla-attention-circled">useless</dt>47 <dd>48 in the plugin language file<br>49 <b>AND</b> (<br>50 in the common language file<br>51 <b>OR</b> (<br>52 not belonging to any common file<br>53 <b>AND</b> in the admin language file<br>54 )<br>55 )56 </dd>57 58 <dt class="iconpla-ok-squared">ok</dt>59 <dd>60 any other case61 </dd>62 </dl>63 64 <p>65 You can click the <span class="iconpla-plus-circled"></span> icon on the left of each string to see where it is located.66 </p>67 </fieldset>68 69 <fieldset>70 <legend>{'Select a plugin'|@translate}</legend>71 72 <select name="plugin_id">73 {foreach from=$PLA_PLUGINS item=plugin key=plugin_id}74 <option value="{$plugin_id}">{$plugin.name} ({$plugin.version})</option>75 {/foreach}76 </select>77 78 <p class="formButtons"><input type="submit" value="{'Continue'|@translate}"></p>79 </fieldset>80 </form>81 82 {* <!-- configure --> *}83 {elseif $PLA_STEP=='config'}84 {footer_script}{literal}85 $('.switch-button.type span').click(function() {86 $(this).siblings('span').removeClass('active');87 $(this).addClass('active');88 89 if ($(this).hasClass('common')) {90 $(this).nextAll('input').val('false');91 }92 else {93 $(this).nextAll('input').val('true');94 }95 });96 $('.switch-button.other span').click(function() {97 if ($(this).hasClass('active')) {98 $(this).removeClass('active');99 $(this).next('input').val('false');100 }101 else {102 $(this).addClass('active');103 $(this).next('input').val('true');104 }105 });106 {/literal}{/footer_script}107 108 <form method="POST" action="{$F_ACTION}" class="properties">109 <fieldset>110 <legend>{'Select dependencies'|@translate}</legend>111 112 <table class="files">113 <thead>114 <tr>115 <th></th>116 <th>{'Core dependency'|@translate}</th>117 <th>{'Local dependencies'|@translate}</th>118 </tr>119 </thead>120 121 <tbody>122 {foreach from=$PLA_FILES item=file}123 <tr>124 <td>{$file.path}</td>125 <td>126 <div class="switch-button type">127 <span class="item common {if not $file.is_admin}active{/if}">{'Common'|@translate}</span>128 <span class="item admin {if $file.is_admin}active{/if}">{'Admin'|@translate}</span>129 <input type="hidden" name="files[{$file.path}][is_admin]" value="{if $file.is_admin}true{else}false{/if}">130 </div>131 </td>132 <td>133 <div class="switch-button other">134 {foreach from=$PLA_LANG_FILES item=path key=lang_file}135 <span class="item other {if $lang_file|in_array:$file.lang_files}active{/if}">{$lang_file}</span>136 <input type="hidden" name="files[{$file.path}][lang_files][{$lang_file}]" value="{if $lang_file|in_array:$file.lang_files}true{else}false{/if}">137 {/foreach}138 </div>139 </td>140 </tr>141 {/foreach}142 </tbody>143 </table>144 145 <p class="formButtons"><input type="submit" value="{'Continue'|@translate}"></p>146 </fieldset>147 </form>148 149 {* <!-- analysis --> *}150 {elseif $PLA_STEP=='analysis'}151 {footer_script}{literal}152 $('.strings tr.string td.toggler').click(function() {153 if ($(this).hasClass('iconpla-plus-circled')) {154 $(this).removeClass('iconpla-plus-circled').addClass('iconpla-minus-circled');155 $(this).parent().nextUntil('tr.string').show();156 }157 else {158 $(this).removeClass('iconpla-minus-circled').addClass('iconpla-plus-circled');159 $(this).parent().nextUntil('tr.string').hide();160 }161 });162 163 $('.strings tr.string').hover(164 function() {165 $(this).addClass('hover').nextUntil('tr.string').addClass('hover');166 },167 function() {168 $(this).removeClass('hover').nextUntil('tr.string').removeClass('hover');169 }170 );171 $('.strings tr.file').hover(172 function() {173 $(this).prevAll('tr.string:first').addClass('hover').nextUntil('tr.string').addClass('hover');174 },175 function() {176 $(this).prevAll('tr.string:first').removeClass('hover').nextUntil('tr.string').removeClass('hover');177 }178 );179 180 $('.open-all').click(function() {181 $('.strings tr.file').show();182 });183 $('.open-missing').click(function() {184 $('.strings tr.file.string-missing').show();185 });186 $('.close-all').click(function() {187 $('.strings tr.file').hide();188 });189 {/literal}{/footer_script}190 191 {html_style}192 .strings tr td:nth-last-child(-n+{math equation="2+x" x=$PLA_LANG_FILES|@count}) {ldelim}193 text-align:center;194 }195 {/html_style}196 197 <fieldset>198 <legend>{$PLA_PLUGIN.name}</legend>199 200 <p style="text-align:left;">201 <a class="open-all">{'Expand all'|@translate}</a>202 / <a class="open-missing">{'Expand missing'|@translate}</a>203 / <a class="close-all">{'Collapse all'|@translate}</a>204 </p>205 206 <table class="strings">207 <thead>208 <tr>209 <th></th>210 <th class="legend">211 <span class="missing">{'Missing'|@translate}</span>212 <span class="useless">{'Useless'|@translate}</span>213 </th>214 <th>{'Dependency'|@translate}</th>215 {foreach from=$PLA_LANG_FILES item=path key=lang_file}216 <th>{$lang_file}</th>217 {/foreach}218 <th>common.lang</th>219 <th>admin.lang</th>220 </tr>221 </thead>222 223 <tbody>224 {foreach from=$PLA_STRINGS item=data key=string}225 <!-- begin string -->226 <tr class="string {$data.stat}">227 <td class="toggler iconpla-plus-circled"></td>228 <td>{$string|htmlspecialchars}</td>229 {if $data.is_admin}<td class="text-admin">{'Admin'|@translate}</td>230 {else}<td class="text-common">{'Common'|@translate}</td>{/if}231 {foreach from=$PLA_LANG_FILES item=path key=lang_file}232 <td>{if $lang_file|in_array:$data.in_plugin}<b>{'Yes'|@translate}</b>{else}{'No'|@translate}{/if}</td>233 {/foreach}234 <td>{if $data.in_common}<b>{'Yes'|@translate}</b>{else}{'No'|@translate}{/if}</td>235 <td>{if $data.in_admin}<b>{'Yes'|@translate}</b>{else}{'No'|@translate}{/if}</td>236 </tr>237 {foreach from=$data.files item=file_data key=file}238 <!-- begin file -->239 <tr class="file string-{$data.stat} {$file_data.stat}">240 <td></td>241 <td>{$file} <i>({', '|@implode:$file_data.lines})</i></td>242 {if $file_data.is_admin}<td class="text-admin">{'Admin'|@translate}</td>243 {else}<td class="text-common">{'Common'|@translate}</td>{/if}244 {foreach from=$PLA_LANG_FILES item=path key=lang_file}245 <td>{if $lang_file|in_array:$file_data.lang_files}<b>{'Yes'|@translate}</b>{else}{'No'|@translate}{/if}</td>246 {/foreach}247 <td></td>248 <td></td>249 </tr>250 {/foreach} {* <!-- end file --> *}251 {/foreach} {* <!-- end string --> *}252 </tbody>253 254 <tfoot>255 <tr>256 <th></th>257 <th>{'%d strings : %d missing and %d useless.'|@translate|sprintf:$PLA_COUNTS.total:$PLA_COUNTS.missing:$PLA_COUNTS.useless}</th>258 <th></th>259 <th></th>260 <th></th>261 <th></th>262 <th></th>263 </tr>264 </tfoot>265 </table>266 </fieldset>267 268 {/if} -
extensions/plugin_lang_analysis/template/style.css
r23467 r23472 13 13 padding:5px 8px; 14 14 background:#e6e6e6; 15 color:# 555;15 color:#888; 16 16 cursor:pointer; 17 17 } 18 .switch-button span:hover { 19 text-decoration:underline; 20 } 18 21 .switch-button span.active { 19 22 color:#212121; … … 126 129 background:#BFE599; 127 130 } 128 131 132 .tiptip { 133 cursor:help; 134 }
Note: See TracChangeset
for help on using the changeset viewer.