Make WordPress Core

Changes between Version 1 and Version 2 of Ticket #48244, comment 3


Ignore:
Timestamp:
11/20/2019 06:40:53 PM (7 years ago)
Author:
shaampk1

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #48244, comment 3

    v1 v2  
    1 Hi Sergey/Pascal,
     1Hey folks,
    22
    33This ticket really got my attention. I found it an interesting issue to work with. I know there has been already said a lot about L10n which I have been reading and trying to catch up with for the past few days now but still, I am not sure how far I have come regarding this issue. I'd appreciate it if you could review the following code snippet and let me know what I am missing.
    … …  
    55
    66== For script-loader.php
    7 == Example # 1:
    87
    98{{{
    109
    11 // Strings for 'jquery-ui-autocomplete' live region messages
    12     did_action( 'init' ) && $scripts->localize( 'jquery-ui-autocomplete', 'uiAutocompleteL10n', array(
    13             'noResults' => __( 'No search results.' ),
    14             /* translators: Number of results found when using jQuery UI Autocomplete */
    15             'oneResult' => ( 1 == did_action( 'init' ) ) ? __( '1 result found. Use up and down arrow keys to navigate.' ) : _n( '%d result found. Use up and down arrow keys to navigate.', '%d result found. Use up and down arrow keys to navigate.', did_action( 'init' ) ),
    16             'manyResults' => _n( '%d result found. Use up and down arrow keys to navigate.', '%d result found. Use up and down arrow keys to navigate.', did_action( 'init' ) ),
    17     ) );
     10        // Strings for 'jquery-ui-autocomplete' live region messages
     11        did_action( 'init' ) && $scripts->localize(
     12                'jquery-ui-autocomplete',
     13                'uiAutocompleteL10n',
     14                array(
     15                        'noResults'    => __( 'No results found.' ),
     16                        /* translators: %d: Number of results found when using jQuery UI Autocomplete. */
     17                        'manyResults' => _n( '%s result found. Use up and down arrow keys to navigate.', '%s results found. Use up and down arrow keys to navigate.', did_action( 'init' ) ),
     18                        'itemSelected' => __( 'Item selected.' ),
     19                )
     20        );
    1821
    1922}}}
    2023
    21 == Example # 2:
    2224
    23 {{{
    24 
    25 // Strings for 'jquery-ui-autocomplete' live region messages
    26     did_action( 'init' ) && $scripts->localize( 'jquery-ui-autocomplete', 'uiAutocompleteL10n', array(
    27             'noResults' => __( 'No search results.' ),
    28             /* translators: Number of results found when using jQuery UI Autocomplete */
    29             'oneResult' => sprintf( _n( '1 result found. Use up and down arrow keys to navigate.', '%s result found. Use up and down arrow keys to navigate.', did_action( 'init' ) ), number_format_i18n( did_action( 'init' ) ) ),
    30             'manyResults' => sprintf( _n( '%s result found. Use up and down arrow keys to navigate.', '%s result found. Use up and down arrow keys to navigate.', did_action( 'init' ) ), number_format_i18n( did_action( 'init' ) ) ),
    31     ) );
    32 
    33 }}}
    34 
    35 == For plugin.js
    36 == Example # 1:
    37 
     25== For plugin.js & tags-suggest.js
    3826
    3927{{{
    … …  
    4230        results: function( number ) {
    4331                if ( typeof window.uiAutocompleteL10n !== 'undefined' ) {
    44                         if ( number == 1 ) {
    45                                 return window.uiAutocompleteL10n.oneResult;
    46                         } elseif {
    47                                 return window.uiAutocompleteL10n.manyResults.replace( '%d', number );
    48                         }
    49                 }
    50         }
    51 }
    52 }}}
    53 
    54 
    55 == Example # 2:
    56 
    57 {{{
    58 messages: {
    59         noResults: ( typeof window.uiAutocompleteL10n !== 'undefined' ) ? window.uiAutocompleteL10n.noResults : '',
    60         results: function( number ) {
    61                 if ( typeof window.uiAutocompleteL10n !== 'undefined' ) {
    62                         if ( number == 1 ) {
    63                                 return window.uiAutocompleteL10n.oneResult;
    64                         } elseif {
     32                        if ( number > 1 ) {
    6533                                return window.uiAutocompleteL10n.manyResults.replace( '%s', number );
    6634                        }
     35
     36                        return window.uiAutocompleteL10n.oneResult;
    6737                }
    6838        }