Load translation from other language
How can I load a translation from an other language, other than the current language?
For example, my site has 4 languages but some items are only available in 2 languages. If the current language is not available I want to load an other language which is available. I want to use this for the title, content and some meta fields.
I use this snippet:
//WP Multilang: Fallback to any language if a translation does not exist
add_filter( 'wpm_untranslated_text', function( $translation, $strings, $language ) {
if ( $translation === '' ) {
foreach( $strings as $string ) {
if ( ( '' === $string ) ) continue;
$translation = $string;
break;
}
}
return $translation;
}, 10, 3 );
Hi Soft79, thanks for your reply but this is not what i'm looking for. I want to get a other translation (as fallback) from the database only if a translation not exists. So if a page is loaded in Dutch and the page title is not in Dutch available the site needs to load the original English translation as fallback, right from the database.
And what's wrong with the snippet then? That's what the snippet should do and I have been using it in production for more than a year now.
(originally I placed a PR for this, see https://github.com/VaLeXaR/wp-multilang/pull/12 but VaLeXaR didn't want this in core so he made a filter for this)
Niels, did you try the snippet?