4

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.

5

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.

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.