Plugin Directory

Changeset 959319


Ignore:
Timestamp:
08/02/2014 06:11:35 PM (12 years ago)
Author:
Name.ly
Message:

version 0.1.0

Location:
quick-localization/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • quick-localization/trunk/index.php

    r755016 r959319  
    22/*
    33 * Plugin Name:   Quick Localization (Quick Localisation)
    4  * Version:       0.0.9
     4 * Version:       0.1.0
    55 * Plugin URI:    http://name.ly/plugins/
    66 * Description:   Quick Localisation allows site admins to patch Wordpress translations of any theme and any plugin without leaving the control panel
     
    2222
    2323global $ql_options;
    24 // $ql_options are checked [and saved when needed] when creating $QLC but are not propaged; we load them globally here
     24// $ql_options are checked [and saved when needed] when creating $QLC but are not propagated; we load them globally here
    2525$ql_options = get_option ( 'ql_options' );
    2626
     
    5454
    5555add_filter ( "gettext", "ql_gettext_filter", 1000, 3 );
    56 
    57 function ql_gettext_filter ( $new, $old, $domain ) {
     56function ql_gettext_filter ( $translations, $text, $domain ) {
    5857    global $ql_options;
    5958    global $QLC;
    6059    global $ql_footer_textarea;
    6160
     61//  if ( "yes" != $ql_options [ "collect_draft_translations_gettext" ] ) {
     62//      return $translations;
     63//  }
     64
     65    if ( is_array ( $translations ) ) {
     66        return $translations;
     67    }
     68
    6269    if ( "yes" == $ql_options [ "footer_textarea" ] ) {
    63         $ql_footer_textarea .= $old . "||" . $new  . "||" . $domain . "\n";
     70        $ql_footer_textarea .= $text . "||" . $translations  . "||" . $domain . "\n";
    6471    }
    6572
    6673    if ( "yes" == $ql_options [ "only_unknown" ] ) {
    67         if ( $new != $old ) {
    68             return $new;
     74        if ( $translations != $text ) {
     75            return $translations;
    6976        }
    7077    }
    7178
    72     $ql_new = $QLC -> translate ( $old, $domain );
     79    $ql_new = $QLC -> translate ( $text, $domain );
    7380    if ( false !== $ql_new ) {
    7481        return $ql_new;
    7582    } else {
    76         return $new;
     83        return $translations;
     84    }
     85}
     86
     87add_filter ( "ngettext", "ql_ngettext_filter", 1000, 5 );
     88function 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
     97add_filter ( "gettext_with_context", "ql_gettext_with_context_filter", 1000, 4 );
     98function 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
     107add_filter ( "ngettext_with_context", "ql_ngettext_with_context_filter", 1000, 6 );
     108function 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;
    77114    }
    78115}
  • quick-localization/trunk/ql_class.php

    r755016 r959319  
    3030//  0.0.8           0.0.1
    3131//  0.0.9           0.0.1
     32//  0.1.0           0.0.1
    3233
    3334
     
    4142    private $collect_draft_translations_white;
    4243    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;
    4348    private $default_order_by;
    4449
     
    9196            $saveaftercheck = true;
    9297        }
     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        }
    93114        if ( ! isset ( $ql_options [ "only_unknown" ] ) ) {
    94115            $ql_options [ "only_unknown" ] = "no";
     
    118139        $this -> collect_draft_translations_white = get_option ( "ql_collect_draft_translations_white", array () );
    119140        $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" ];
    120145
    121146        $this -> default_order_by = $ql_options [ "default_order_by" ];
  • quick-localization/trunk/ql_edit.php

    r755016 r959319  
    8282        <td><input type='text' value='$domain' style='width:90%;' name='ql[$x][domain]' id='ql_domain_$x' /></td>
    8383        <td><a onclick='ql_mark2delete($x);'>" . __ ( "Empty", "QL" ) . "</a> " . __ ( "(mark to delete)", "QL" ) . "</td>";
     84        $x++;
    8485?>
    8586    </tr>
  • quick-localization/trunk/ql_settings.php

    r755016 r959319  
    2222            $ql_options [ "collect_draft_translations_fe" ] = $_POST [ "ql_settings_collect_draft_translations_fe" ] ? "yes" : "no" ;
    2323            $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" ;
    2428            update_option ( 'ql_options', $ql_options );
    2529            //
     
    8791    <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 />
    8892    <?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>
    8998    <p><input type="hidden" name="ql_settings_update"/></p>
    9099    <p><input type="submit" class="button-primary" value="<?php _e ( "Save", "QL" ); ?>" name="ql_save"></p>
    91100
    92101    <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>
    94103    <p><input type="submit" class="button-primary" value="<?php _e ( "Save", "QL" ); ?>" name="ql_save"></p>
    95104
  • quick-localization/trunk/readme.txt

    r755016 r959319  
    1313== Description ==
    1414
    15 Quick Localisation allows to hook on `gettext` so that one can easily tweak Wordpress translations generated by functions `__` and `_e`.
     15Quick 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`.
    1616
    1717For 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.
     
    4545= Hooks =
    4646
    47 At the moment Quick Localisation hooks on `gettext` filter with very low priority (namely, 1000), allowing it to be the last one to have a say on translations.
     47At 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.
    4848
    4949Should one use other similar `gettext` hooks, the priority can be changed in `index.php`.
     
    7070The 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.
    7171
     72= Some plugins appear not to be translated, what can be done about it? =
     73
     74Wordpress 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
     76A known way around it is as follows:
     77
     781. Create `quick-localization.php` in the `/wp-content/mu-plugins/` directory
     791. Add the following line into `quick-localization.php`:<br />`<?php include_once ABSPATH . "wp-content/plugins/quick-localization/index.php"; ?>`
     801. Voila!
     81
    7282== Screenshots ==
    7383
     
    7686== Changelog ==
    7787
     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
    7894= 0.0.9 =
    7995
    80 * Fixed warnings generated when WP_DEBUG is set to true
     96* Fixed warnings generated when `WP_DEBUG` is set to `true`
    8197
    8298= 0.0.8 =
Note: See TracChangeset for help on using the changeset viewer.