WordPress.org

Make WordPress Core

Changeset 48136


Ignore:
Timestamp:
06/23/2020 10:00:36 AM (15 months ago)
Author:
SergeyBiryukov
Message:

I18N: Use underscores instead of dashes and interpolation instead of concatenation in domain-specific gettext hooks, per the coding standards:

  • gettext_{$domain}
  • gettext_with_context_{$domain}
  • ngettext_{$domain}
  • ngettext_with_context_{$domain}

Additionally:

  • Pass $domain parameter to the new hooks, for consistency with their pre-existing counterparts.
  • Update documentation to explain the dynamic portion of the filter, for consistency with other dynamic hooks in core.

Follow-up to [48131].

Props swissspidy, knutsp, TimothyBlynJacobs, SergeyBiryukov.
Fixes #49518.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/l10n.php

    r48131 r48136  
    130130     */
    131131    $determined_locale = apply_filters( 'pre_determine_locale', null );
     132
    132133    if ( ! empty( $determined_locale ) && is_string( $determined_locale ) ) {
    133134        return $determined_locale;
     
    182183     * @since 2.0.11
    183184     *
    184      * @param string $translation  Translated text.
    185      * @param string $text         Text to translate.
    186      * @param string $domain       Text domain. Unique identifier for retrieving translated strings.
     185     * @param string $translation Translated text.
     186     * @param string $text        Text to translate.
     187     * @param string $domain      Text domain. Unique identifier for retrieving translated strings.
    187188     */
    188189    $translation = apply_filters( 'gettext', $translation, $text, $domain );
     
    191192     * Filters text with its translation for a domain.
    192193     *
     194     * The dynamic portion of the hook, `$domain`, refers to the text domain.
     195     *
    193196     * @since 5.5.0
    194197     *
    195      * @param string $translation  Translated text.
    196      * @param string $text         Text to translate.
    197      */
    198     return apply_filters( 'gettext-' . $domain, $translation, $text );
     198     * @param string $translation Translated text.
     199     * @param string $text        Text to translate.
     200     * @param string $domain      Text domain. Unique identifier for retrieving translated strings.
     201     */
     202    $translation = apply_filters( "gettext_{$domain}", $translation, $text, $domain );
     203
     204    return $translation;
    199205}
    200206
     
    244250     * @since 2.8.0
    245251     *
    246      * @param string $translation  Translated text.
    247      * @param string $text         Text to translate.
    248      * @param string $context      Context information for the translators.
    249      * @param string $domain       Text domain. Unique identifier for retrieving translated strings.
     252     * @param string $translation Translated text.
     253     * @param string $text        Text to translate.
     254     * @param string $context     Context information for the translators.
     255     * @param string $domain      Text domain. Unique identifier for retrieving translated strings.
    250256     */
    251257    $translation = apply_filters( 'gettext_with_context', $translation, $text, $context, $domain );
     
    254260     * Filters text with its translation based on context information for a domain.
    255261     *
     262     * The dynamic portion of the hook, `$domain`, refers to the text domain.
     263     *
    256264     * @since 5.5.0
    257265     *
    258      * @param string $translation  Translated text.
    259      * @param string $text         Text to translate.
    260      * @param string $context      Context information for the translators.
    261      */
    262     return apply_filters( 'gettext_with_context-' . $domain, $translation, $text, $context );
     266     * @param string $translation Translated text.
     267     * @param string $text        Text to translate.
     268     * @param string $context     Context information for the translators.
     269     * @param string $domain      Text domain. Unique identifier for retrieving translated strings.
     270     */
     271    $translation = apply_filters( "gettext_with_context_{$domain}", $translation, $text, $context, $domain );
     272
     273    return $translation;
    263274}
    264275
     
    473484     * Filters the singular or plural form of a string for a domain.
    474485     *
     486     * The dynamic portion of the hook, `$domain`, refers to the text domain.
     487     *
    475488     * @since 5.5.0
    476489     *
     
    479492     * @param string $plural      The text to be used if the number is plural.
    480493     * @param string $number      The number to compare against to use either the singular or plural form.
    481      */
    482     return apply_filters( 'ngettext-' . $domain, $translation, $single, $plural, $number );
     494     * @param string $domain      Text domain. Unique identifier for retrieving translated strings.
     495     */
     496    $translation = apply_filters( "ngettext_{$domain}", $translation, $single, $plural, $number, $domain );
     497
     498    return $translation;
    483499}
    484500
     
    528544     * Filters the singular or plural form of a string with gettext context for a domain.
    529545     *
     546     * The dynamic portion of the hook, `$domain`, refers to the text domain.
     547     *
    530548     * @since 5.5.0
    531549     *
     
    535553     * @param string $number      The number to compare against to use either the singular or plural form.
    536554     * @param string $context     Context information for the translators.
    537      */
    538     return apply_filters( 'ngettext_with_context-' . $domain, $translation, $single, $plural, $number, $context );
     555     * @param string $domain      Text domain. Unique identifier for retrieving translated strings.
     556     */
     557    $translation = apply_filters( "ngettext_with_context_{$domain}", $translation, $single, $plural, $number, $context, $domain );
     558
     559    return $translation;
    539560}
    540561
     
    692713    $plugin_override = apply_filters( 'override_load_textdomain', false, $domain, $mofile );
    693714
    694     if ( true == $plugin_override ) {
     715    if ( true === (bool) $plugin_override ) {
    695716        unset( $l10n_unloaded[ $domain ] );
    696717
Note: See TracChangeset for help on using the changeset viewer.