Make WordPress Core

Ticket #42725: add-new-gender-translation-function.diff

File add-new-gender-translation-function.diff, 2.1 KB (added by yoavf, 6 years ago)

_g() and makepot support

  • tools/i18n/makepot.php

     
    5050                '__ngettext' => array('singular', 'plural'),
    5151                '__ngettext_noop' => array('singular', 'plural'),
    5252                '_x' => array('string', 'context'),
     53                '_g' => array( 'string' ),
    5354                '_ex' => array('string', 'context'),
    5455                '_nx' => array('singular', 'plural', null, 'context'),
    5556                '_nx_noop' => array('singular', 'plural', 'context'),
  • tools/i18n/extract.php

     
    1515                '_n' => array( 'singular', 'plural' ),
    1616        );
    1717        var $comment_prefix = 'translators:';
     18        var $gender_context_prefix = '_wpg_';
    1819
    1920        function __construct( $rules = array() ) {
    2021                $this->rules = $rules;
     
    106107                                break;
    107108                        }
    108109                }
     110
     111                if ( '_g' === $call['name'] ) {
     112                        $entry->context = isset( $entry->context ) ? $this->gender_context_prefix . $entry->context : $this->gender_context_prefix;
     113                }
     114
    109115                if ( isset( $call['line'] ) && $call['line'] ) {
    110116                        $references = array( $file_name . ':' . $call['line'] );
    111117                        $entry->references = $references;
  • src/wp-includes/l10n.php

     
    292292 * @return string Translated context string without pipe.
    293293 */
    294294function _x( $text, $context, $domain = 'default' ) {
     295        //error_log( var_export( func_get_args() , true ));
    295296        return translate_with_gettext_context( $text, $context, $domain );
    296297}
    297298
     299function _g( $text, $gender = null, $domain ='default' ) {
     300        if ( ! $gender ) {
     301                $gender = get_current_user_gender();
     302        }
     303
     304        switch ( $gender ) {
     305                case 'unknown':
     306                        return _x( $text, '_wpg_', $domain );
     307                case 'female':
     308                        return _x( $text, '_wpg_female_', $domain );
     309                case 'male':
     310                        return _x( $text, '_wpg_male_', $domain );
     311        }
     312}
     313
    298314/**
    299315 * Display translated string with gettext context.
    300316 *