• I have a multilingual WordPress theme with a hard-coded string which I don’t want to show if a translation is not available.

    By default, _e('this string is irrelevant in German', 'my-theme') falls back to the original English string when the translation is not found or is empty.

    Ideally I’d like to query the current translation database and see if the translation exists. If not, then I can skip the code block that outputs the translation.

    I’ve looked in wp-includes/l10n.php to see if there is a translation_exists() function but don’t see anything relevant. Is this possible in WordPress?

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    If you use a translation function, the translation is not considered complete until all strings are translated. Translators could translate to an empty string if it’s really not applicable for certain languages. You code can check if the translation comes back as an empty string or not, but there’s no function that tells us if a translation exists at all, strings are simply not translated.

    I suppose you could check if the applicable .mo translation file exists on the server to determine if a translation exists. Or you could check the current locale value to determine what the desired language is, but this does not mean a translation exists.

Viewing 1 replies (of 1 total)
  • The topic ‘Conditional localization’ is closed to new replies.