WordPress.org

Make WordPress Core

Opened 3 months ago

#52696 new enhancement

__() avoiding default language fallback

Reported by: drzraf Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version: 5.6.2
Component: I18N Keywords:
Focuses: Cc:

Description

Currently __() wraps pomo/translations.php::translate_entry()̀ in such a way:

<?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);

Change History (0)

Note: See TracTickets for help on using tickets.