Changeset 959319
- Timestamp:
- 08/02/2014 06:11:35 PM (12 years ago)
- Location:
- quick-localization/trunk
- Files:
-
- 5 edited
-
index.php (modified) (3 diffs)
-
ql_class.php (modified) (4 diffs)
-
ql_edit.php (modified) (1 diff)
-
ql_settings.php (modified) (2 diffs)
-
readme.txt (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
quick-localization/trunk/index.php
r755016 r959319 2 2 /* 3 3 * Plugin Name: Quick Localization (Quick Localisation) 4 * Version: 0. 0.94 * Version: 0.1.0 5 5 * Plugin URI: http://name.ly/plugins/ 6 6 * Description: Quick Localisation allows site admins to patch Wordpress translations of any theme and any plugin without leaving the control panel … … 22 22 23 23 global $ql_options; 24 // $ql_options are checked [and saved when needed] when creating $QLC but are not propag ed; we load them globally here24 // $ql_options are checked [and saved when needed] when creating $QLC but are not propagated; we load them globally here 25 25 $ql_options = get_option ( 'ql_options' ); 26 26 … … 54 54 55 55 add_filter ( "gettext", "ql_gettext_filter", 1000, 3 ); 56 57 function ql_gettext_filter ( $new, $old, $domain ) { 56 function ql_gettext_filter ( $translations, $text, $domain ) { 58 57 global $ql_options; 59 58 global $QLC; 60 59 global $ql_footer_textarea; 61 60 61 // if ( "yes" != $ql_options [ "collect_draft_translations_gettext" ] ) { 62 // return $translations; 63 // } 64 65 if ( is_array ( $translations ) ) { 66 return $translations; 67 } 68 62 69 if ( "yes" == $ql_options [ "footer_textarea" ] ) { 63 $ql_footer_textarea .= $ old . "||" . $new. "||" . $domain . "\n";70 $ql_footer_textarea .= $text . "||" . $translations . "||" . $domain . "\n"; 64 71 } 65 72 66 73 if ( "yes" == $ql_options [ "only_unknown" ] ) { 67 if ( $ new != $old) {68 return $ new;74 if ( $translations != $text ) { 75 return $translations; 69 76 } 70 77 } 71 78 72 $ql_new = $QLC -> translate ( $ old, $domain );79 $ql_new = $QLC -> translate ( $text, $domain ); 73 80 if ( false !== $ql_new ) { 74 81 return $ql_new; 75 82 } else { 76 return $new; 83 return $translations; 84 } 85 } 86 87 add_filter ( "ngettext", "ql_ngettext_filter", 1000, 5 ); 88 function ql_ngettext_filter ( $translation, $single, $plural, $number, $domain ) { 89 global $ql_options; 90 if ( "yes" == $ql_options [ "collect_draft_translations_ngettext" ] ) { 91 return ql_gettext_filter ( $translation, 1 == $number ? $single : $plural, $domain ); 92 } else { 93 return $translation; 94 } 95 } 96 97 add_filter ( "gettext_with_context", "ql_gettext_with_context_filter", 1000, 4 ); 98 function ql_gettext_with_context_filter ( $translations, $text, $context, $domain ) { 99 global $ql_options; 100 if ( "yes" == $ql_options [ "collect_draft_translations_gettext_with_context" ] ) { 101 return ql_gettext_filter ( $translations, $text, $domain ); 102 } else { 103 return $translations; 104 } 105 } 106 107 add_filter ( "ngettext_with_context", "ql_ngettext_with_context_filter", 1000, 6 ); 108 function ql_ngettext_with_context_filter ( $translation, $single, $plural, $number, $context, $domain ) { 109 global $ql_options; 110 if ( "yes" == $ql_options [ "collect_draft_translations_ngettext_with_context" ] ) { 111 return ql_gettext_filter ( $translation, 1 == $number ? $single : $plural, $domain ); 112 } else { 113 return $translation; 77 114 } 78 115 } -
quick-localization/trunk/ql_class.php
r755016 r959319 30 30 // 0.0.8 0.0.1 31 31 // 0.0.9 0.0.1 32 // 0.1.0 0.0.1 32 33 33 34 … … 41 42 private $collect_draft_translations_white; 42 43 private $collect_draft_translations_black; 44 private $collect_draft_translations_gettext; 45 private $collect_draft_translations_ngettext; 46 private $collect_draft_translations_gettext_with_context; 47 private $collect_draft_translations_ngettext_with_context; 43 48 private $default_order_by; 44 49 … … 91 96 $saveaftercheck = true; 92 97 } 98 if ( ! isset ( $ql_options [ "collect_draft_translations_gettext" ] ) || "yes" != $ql_options [ "collect_draft_translations_gettext" ] ) { 99 $ql_options [ "collect_draft_translations_gettext" ] = "yes"; 100 $saveaftercheck = true; 101 } 102 if ( ! isset ( $ql_options [ "collect_draft_translations_ngettext" ] ) ) { 103 $ql_options [ "collect_draft_translations_ngettext" ] = "no"; 104 $saveaftercheck = true; 105 } 106 if ( ! isset ( $ql_options [ "collect_draft_translations_gettext_with_context" ] ) ) { 107 $ql_options [ "collect_draft_translations_gettext_with_context" ] = "no"; 108 $saveaftercheck = true; 109 } 110 if ( ! isset ( $ql_options [ "collect_draft_translations_ngettext_with_context" ] ) ) { 111 $ql_options [ "collect_draft_translations_ngettext_with_context" ] = "yes" == $ql_options [ "collect_draft_translations_ngettext" ] && "yes" == $ql_options [ "collect_draft_translations_gettext_with_context" ] ? "yes" : "no"; 112 $saveaftercheck = true; 113 } 93 114 if ( ! isset ( $ql_options [ "only_unknown" ] ) ) { 94 115 $ql_options [ "only_unknown" ] = "no"; … … 118 139 $this -> collect_draft_translations_white = get_option ( "ql_collect_draft_translations_white", array () ); 119 140 $this -> collect_draft_translations_black = get_option ( "ql_collect_draft_translations_black", array ( "default" ) ); 141 $this -> collect_draft_translations_gettext = "yes" == $ql_options [ "collect_draft_translations_gettext" ]; 142 $this -> collect_draft_translations_ngettext = "yes" == $ql_options [ "collect_draft_translations_ngettext" ]; 143 $this -> collect_draft_translations_gettext_with_context = "yes" == $ql_options [ "collect_draft_translations_gettext_with_context" ]; 144 $this -> collect_draft_translations_ngettext_with_context = "yes" == $ql_options [ "collect_draft_translations_ngettext_with_context" ]; 120 145 121 146 $this -> default_order_by = $ql_options [ "default_order_by" ]; -
quick-localization/trunk/ql_edit.php
r755016 r959319 82 82 <td><input type='text' value='$domain' style='width:90%;' name='ql[$x][domain]' id='ql_domain_$x' /></td> 83 83 <td><a onclick='ql_mark2delete($x);'>" . __ ( "Empty", "QL" ) . "</a> " . __ ( "(mark to delete)", "QL" ) . "</td>"; 84 $x++; 84 85 ?> 85 86 </tr> -
quick-localization/trunk/ql_settings.php
r755016 r959319 22 22 $ql_options [ "collect_draft_translations_fe" ] = $_POST [ "ql_settings_collect_draft_translations_fe" ] ? "yes" : "no" ; 23 23 $ql_options [ "collect_draft_translations_be" ] = $_POST [ "ql_settings_collect_draft_translations_be" ] ? "yes" : "no" ; 24 $ql_options [ "collect_draft_translations_gettext" ] = "yes"; // $_POST [ "ql_settings_collect_draft_translations_gettext" ] ? "yes" : "no" ; 25 $ql_options [ "collect_draft_translations_ngettext" ] = $_POST [ "ql_settings_collect_draft_translations_ngettext" ] ? "yes" : "no" ; 26 $ql_options [ "collect_draft_translations_gettext_with_context" ] = $_POST [ "ql_settings_collect_draft_translations_gettext_with_context" ] ? "yes" : "no" ; 27 $ql_options [ "collect_draft_translations_ngettext_with_context" ] = $_POST [ "ql_settings_collect_draft_translations_ngettext_with_context" ] ? "yes" : "no" ; 24 28 update_option ( 'ql_options', $ql_options ); 25 29 // … … 87 91 <textarea name="ql_settings_collect_draft_translations_black" id="ql_settings_collect_draft_translations_black"><?php echo esc_textarea ( implode ( "\n", get_option ( "ql_collect_draft_translations_black", array ( "default" ) ) ) ); ?></textarea><br /> 88 92 <?php _e ( "N.B. <code>default</code> domain usually has 600+ translations. You don't want to load that many of them, do you?", "QL" ); ?></p> 93 <p><input type="checkbox" value="1" name="ql_settings_collect_draft_translations_gettext" id="ql_settings_collect_draft_translations_gettext" <?php echo "yes" == $ql_options [ "collect_draft_translations_gettext" ] ? 'checked="yes"' : ''; ?> disabled/><label for="ql_settings_collect_draft_translations_gettext"> <?php _e ( "Save drafts of translations called by functions <code>__</code>, <code>_e</code>, and <code>translate</code> (filter <code>gettext</code>).", "QL" ); ?></label></p> 94 <p><input type="checkbox" value="1" name="ql_settings_collect_draft_translations_ngettext" id="ql_settings_collect_draft_translations_ngettext" <?php echo "yes" == $ql_options [ "collect_draft_translations_ngettext" ] ? 'checked="yes"' : ''; ?>/><label for="ql_settings_collect_draft_translations_ngettext"> <?php _e ( "Save drafts of translations called by function <code>_n</code> (filter <code>ngettext</code>).", "QL" ); ?></label></p> 95 <p><input type="checkbox" value="1" name="ql_settings_collect_draft_translations_gettext_with_context" id="ql_settings_collect_draft_translations_gettext_with_context" <?php echo "yes" == $ql_options [ "collect_draft_translations_gettext_with_context" ] ? 'checked="yes"' : ''; ?>/><label for="ql_settings_collect_draft_translations_gettext_with_context"> <?php _e ( "Save drafts of translations called by functions <code>_x</code>, <code>_ex</code>, and <code>translate_with_gettext_context</code> (filter <code>gettext_with_context</code>).", "QL" ); ?></label></p> 96 <p><input type="checkbox" value="1" name="ql_settings_collect_draft_translations_ngettext_with_context" id="ql_settings_collect_draft_translations_ngettext_with_context" <?php echo "yes" == $ql_options [ "collect_draft_translations_ngettext_with_context" ] ? 'checked="yes"' : ''; ?>/><label for="ql_settings_collect_draft_translations_ngettext_with_context"> <?php _e ( "Save drafts of translations called by functions <code>_nx</code> (filter <code>ngettext_with_context</code>).", "QL" ); ?></label></p> 97 <?php // _e ( 'N.B. Drafts of translations called by function <code>_nx</code> (filter <code>ngettext_with_context</code>) will be saved if both options for filters <label for="ql_settings_collect_draft_translations_ngettext"><code>ngettext</code></label> and <label for="ql_settings_collect_draft_translations_gettext_with_context"><code>gettext_with_context</code></label> above are enabled.', "QL" ); ?></p> 89 98 <p><input type="hidden" name="ql_settings_update"/></p> 90 99 <p><input type="submit" class="button-primary" value="<?php _e ( "Save", "QL" ); ?>" name="ql_save"></p> 91 100 92 101 <p><h4><?php _e ( "Debugging (sort of)", "QL" ); ?></h4></p> 93 <p><input type="checkbox" value="1" name="ql_settings_footer_textarea" id="ql_settings_footer_textarea" <?php echo "yes" == $ql_options [ "footer_textarea" ] ? 'checked="yes"' : ''; ?>/><label for="ql_settings_footer_textarea"> <?php _e ( "Gather all translations called via <code> gettext</code>and show them only to the site admins on every page in a black box in the footer area.", "QL" ); ?></label></p>102 <p><input type="checkbox" value="1" name="ql_settings_footer_textarea" id="ql_settings_footer_textarea" <?php echo "yes" == $ql_options [ "footer_textarea" ] ? 'checked="yes"' : ''; ?>/><label for="ql_settings_footer_textarea"> <?php _e ( "Gather all translations called via <code>*gettext*</code> filters and show them only to the site admins on every page in a black box in the footer area.", "QL" ); ?></label></p> 94 103 <p><input type="submit" class="button-primary" value="<?php _e ( "Save", "QL" ); ?>" name="ql_save"></p> 95 104 -
quick-localization/trunk/readme.txt
r755016 r959319 13 13 == Description == 14 14 15 Quick Localisation allows to hook on `gettext` so that one can easily tweak Wordpress translations generated by functions `__` and `_e`.15 Quick Localisation allows to hook on `gettext`, `gettext_with_context`, `ngettext`, and `ngettext_with_context` so that one can easily tweak Wordpress translations generated by functions `__`, `_e`, `_ex`, `_n`, `_nx`, `_x`, `translate`, and `translate_with_gettext_context`. 16 16 17 17 For installation please see the [corresponding section](http://wordpress.org/extend/plugins/quick-localization/installation/). It is as trivial as copying the plugin folder in your WordPress. … … 45 45 = Hooks = 46 46 47 At the moment Quick Localisation hooks on `gettext` filterwith very low priority (namely, 1000), allowing it to be the last one to have a say on translations.47 At the moment Quick Localisation hooks on `gettext`, `ngettext`, and `gettext_with_context` filters with very low priority (namely, 1000), allowing it to be the last one to have a say on translations. 48 48 49 49 Should one use other similar `gettext` hooks, the priority can be changed in `index.php`. … … 70 70 The bigger the database, the more parsing the plugin has to perform, the higher the load. The relationship is exponential. Though we tested it with thousand words and the extra load was minimal. 71 71 72 = Some plugins appear not to be translated, what can be done about it? = 73 74 Wordpress activates plugins alphabetically or in the order provided by the file system. Having said this, if one of these earlier plugins localises its strings directly on the initialisation, Quick Localisation won't be able to catch those. 75 76 A known way around it is as follows: 77 78 1. Create `quick-localization.php` in the `/wp-content/mu-plugins/` directory 79 1. Add the following line into `quick-localization.php`:<br />`<?php include_once ABSPATH . "wp-content/plugins/quick-localization/index.php"; ?>` 80 1. Voila! 81 72 82 == Screenshots == 73 83 … … 76 86 == Changelog == 77 87 88 = 0.1.0 = 89 90 * Added a note on how to intialise the plugin via MU plugins 91 * Now handling `_n` and `_x` translatons as well 92 * Fixed the issue when addition of multiple new entries failed on the first one 93 78 94 = 0.0.9 = 79 95 80 * Fixed warnings generated when WP_DEBUG is set to true96 * Fixed warnings generated when `WP_DEBUG` is set to `true` 81 97 82 98 = 0.0.8 =
Note: See TracChangeset
for help on using the changeset viewer.