0

I manage a plugin. I have people often complain about translations and have found that sometimes they don't have their site set to their local language.

Is it possible in site source code to display the site language as chosen in Settings > General ?

e.g. I have a comment <!-- plugin version 123 -->. Is it possible to display <!-- plugin version 123 (Fr) --> if the language is French?

  • 1
    There's get_locale() and get_bloginfo( 'language' ), if that helps. – Sally CJ Mar 23 at 6:26
  • 1
    A proper theme should have an accurate <html lang=""> attribute set with language_attributes(). See in _s. So with that in place you can always have the set language in the opening <html> tag. – Mayeenul Islam Mar 23 at 6:26
  • 1
    @SallyCJ would you like to put that as an answer for me to accept? get_bloginfo( 'language' ) did exactly what I wanted. – Steve Mar 26 at 5:07
1

Is it possible to display <!-- plugin version 123 (Fr) --> if the language is French?

Yes, it is possible and you can use get_bloginfo( 'language' ) which returns a language tag like en-US for English (US).

So if you just want to retrieve the first 2-or-3 character code (e.g. en for en-US and en-UK) of the language tag, you can do:

list ( $lang ) = explode( '-', get_bloginfo( 'language' ) );
echo '<!-- plugin version 123 (' . ucfirst( $lang ) . ') -->';
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.