WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In answering this question: Change language by clicking a button. It was necessary to obtain a list of languages for which translations were available (i.e. their po/mo files were present in wp-content/languages).

So how can you obtain that list?

Clearly by 'available' we can only mean that their po/mo files are present - and it's not a concern if every plug-in also provides a translation for that language (interesting to see how you might do this though).

The list was originally intended for us in a drop-down, whereby a user could select from a list of (available) languages. So the human readable form of the language as well would be a bonus. But I think this is probably not possible.

View the question linked to above for demonstration of the current method used.

share|improve this question
up vote 5 down vote accepted

You can get a list of available languages with get_available_languages( $dir ). It returns an array with all .mo files where the names does not start with 'continents-cities', 'ms-' or admin-.

To get a readable name for the file use format_code_lang( $code ).

If you scan a directory for language files and get an array like array( 'de_DE', 'tr_TR' ) this function will build translated names for the languages: German and Turkish.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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