[wp-trac] [WordPress Trac] #52696: __() avoiding default language fallback

WordPress Trac noreply at wordpress.org
Tue Mar 2 20:34:53 UTC 2021


#52696: __() avoiding default language fallback
-------------------------+-----------------------------
 Reporter:  drzraf       |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  I18N         |    Version:  5.6.2
 Severity:  minor        |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 Currently `__()` wraps `pomo/translations.php::translate_entry()̀` in such
 a way:

 {{{#!php
 <?php
                 function translate( $singular, $context = null ) {
                         $entry      = new Translation_Entry(
                                 array(
                                         'singular' => $singular,
                                         'context'  => $context,
                                 )
                         );
                         $translated = $this->translate_entry( $entry );
                         return ( $translated && ! empty(
 $translated->translations ) ) ? $translated->translations[0] : $singular;
                 }
 }}}

 If no translation exist, the original is returned which is the more
 frequently desirable behavior.

 But in some cases, the user may want to know whether the string obtained
 from `__()` is actually the translation or the original.

 **Use-case**: I'm inserting programmatically taxonomy terms translated
 using a 3rd-party service. I'm iterating over `[__("t1"), __("t2"), ...]`
 and I would like to only insert those actually translated, ignoring the
 others.

 Currently, I've no way to discriminate between the original and the
 translation (which may or may not be identical btw).

 I'd like a function providing me this ability like. One such example
 `__i18n_exists($term, $context = null);`

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


More information about the wp-trac mailing list