[wp-trac] [WordPress Trac] #49518: Consider adding domain-specific i18N filter hooks

WordPress Trac noreply at wordpress.org
Wed Feb 26 16:22:29 UTC 2020


#49518: Consider adding domain-specific i18N filter hooks
-------------------------+-----------------------------
 Reporter:  geminilabs   |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  I18N         |    Version:  5.3.2
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 This would be useful in cases where plugins provide a search/replace
 option to translate plugin text. An example plugin is Site Reviews
 [https://wordpress.org/plugins/site-reviews/] (which I develop and
 maintain). I optimise this process by calling a domain specific hook
 within each i18n filter hook, and perform any additional things inside
 these domain-specific hooks.

 The problem with not having domain-specific i18n filter hooks is that the
 amount of times the i18n filter hooks are called are increased with every
 active plugin.

 Even though there is little-to-no performance impact (by calling a domain
 specific hook within each i18n filter hook and only performing any
 additional things inside these domain-specific hooks), it still results in
 thousands, sometimes millions of function calls on every page load.

 For example, on one system there were 14 million function calls on each
 page load due to this feature (even though the **total combined execution
 time** of these function calls was only ~<0.3s).

 Here are the domain-specific i18n filter hooks I am proposing:

 {{{#!php
 <?php
 /**
  * Filters text with its translation for a domain.
  *
  * @since 5.4.0
  *
  * @param string $translation  Translated text.
  * @param string $text         Text to translate.
  */
 $translation = apply_filters( 'gettext-' . $domain, $translation, $text );
 }}}


 {{{#!php
 <?php
 /**
  * Filters text with its translation based on context information for a
 domain.
  *
  * @since 5.4.0
  *
  * @param string $translation  Translated text.
  * @param string $text         Text to translate.
  * @param string $context      Context information for the translators.
  */
 $translation = apply_filters( 'gettext_with_context-' . $domain,
 $translation, $text, $context );
 }}}

 {{{#!php
 <?php
 /**
  * Filters the singular or plural form of a string for a domain.
  *
  * @since 5.4.0
  *
  * @param string $translation Translated text.
  * @param string $single      The text to be used if the number is
 singular.
  * @param string $plural      The text to be used if the number is plural.
  * @param string $number      The number to compare against to use either
 the singular or plural form.
  */
 $translation = apply_filters( 'ngettext-' . $domain, $translation,
 $single, $plural, $number );
 }}}



 {{{#!php
 <?php
 /**
  * Filters the singular or plural form of a string with gettext context
 for a domain.
  *
  * @since 5.4.0
  *
  * @param string $translation Translated text.
  * @param string $single      The text to be used if the number is
 singular.
  * @param string $plural      The text to be used if the number is plural.
  * @param string $number      The number to compare against to use either
 the singular or plural form.
  * @param string $context     Context information for the translators.
  */
 $translation = apply_filters( 'ngettext_with_context-' . $domain,
 $translation, $single, $plural, $number, $context );
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/49518>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list