最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - Display site language setting in source code

programmeradmin1浏览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?

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?

Share Improve this question asked Mar 23, 2020 at 6:08 SteveSteve 2991 gold badge4 silver badges15 bronze badges 3
  • 1 There's get_locale() and get_bloginfo( 'language' ), if that helps. – Sally CJ Commented Mar 23, 2020 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 Commented Mar 23, 2020 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 Commented Mar 26, 2020 at 5:07
Add a comment  | 

1 Answer 1

Reset to default 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 ) . ') -->';
发布评论

评论列表(0)

  1. 暂无评论