[wp-trac] [WordPress Trac] #48244: script-loader.php Need to use _n() when more than one results are found
WordPress Trac
noreply at wordpress.org
Sat Oct 26 15:54:42 UTC 2019
#48244: script-loader.php Need to use _n() when more than one results are found
----------------------------------------+------------------------------
Reporter: tobifjellner | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Script Loader | Version: 4.5
Severity: normal | Resolution:
Keywords: good-first-bug needs-patch | Focuses:
----------------------------------------+------------------------------
Comment (by shaampk1):
Hi Sergey/Pascal,
This 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.
== For load-scripts.php
== Example # 1:
{{{
// Strings for 'jquery-ui-autocomplete' live region messages
did_action( 'init' ) && $scripts->localize( 'jquery-ui-autocomplete',
'uiAutocompleteL10n', array(
'noResults' => __( 'No search results.' ),
/* translators: Number of results found when using jQuery UI
Autocomplete */
'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' ) ),
'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' ) ),
) );
}}}
== Example # 2:
{{{
// Strings for 'jquery-ui-autocomplete' live region messages
did_action( 'init' ) && $scripts->localize( 'jquery-ui-autocomplete',
'uiAutocompleteL10n', array(
'noResults' => __( 'No search results.' ),
/* translators: Number of results found when using jQuery UI
Autocomplete */
'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'
) ) ),
'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' ) ) ),
) );
}}}
== For plugin.js
== Example # 1:
{{{
messages: {
noResults: ( typeof window.uiAutocompleteL10n !== 'undefined' ) ?
window.uiAutocompleteL10n.noResults : '',
results: function( number ) {
if ( typeof window.uiAutocompleteL10n !== 'undefined' ) {
if ( number == 1 ) {
return
window.uiAutocompleteL10n.oneResult;
} elseif {
return
window.uiAutocompleteL10n.manyResults.replace( '%d', number );
}
}
}
}
}}}
== Example # 2:
{{{
messages: {
noResults: ( typeof window.uiAutocompleteL10n !== 'undefined' ) ?
window.uiAutocompleteL10n.noResults : '',
results: function( number ) {
if ( typeof window.uiAutocompleteL10n !== 'undefined' ) {
if ( number == 1 ) {
return
window.uiAutocompleteL10n.oneResult;
} elseif {
return
window.uiAutocompleteL10n.manyResults.replace( '%s', number );
}
}
}
}
}}}
Thank you!
--
Ticket URL: <https://core.trac.wordpress.org/ticket/48244#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list