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

WordPress Trac noreply at wordpress.org
Thu Jun 8 09:16:10 UTC 2023


#52696: __() avoiding default language fallback
----------------------------------------+-----------------------------
 Reporter:  drzraf                      |       Owner:  (none)
     Type:  enhancement                 |      Status:  new
 Priority:  normal                      |   Milestone:  Future Release
Component:  I18N                        |     Version:
 Severity:  minor                       |  Resolution:
 Keywords:  needs-patch good-first-bug  |     Focuses:
----------------------------------------+-----------------------------

Comment (by ckanitz):

 Hi!

 I've startet working on this on the WCEU contributor day. My first
 approach of the requested feature looks like this:

 {{{#!php
 <?php
 function __i18n_exists( $text, $domain = 'default' ) {
         $translations = get_translations_for_domain( $domain );
         $translation  = $translations->translate( $text );

         if ( empty( $translations->entries ) ) {
                 return null;
         }

         return $translation;
 }
 }}}


 If I test it against `de_DE` translations "Post" translates to "Beitrag"
 but `en_EN` will just return `null`.

 Let me know if that's the kind of behaviour you're looking for.

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


More information about the wp-trac mailing list