Converting java language output to Joomla language output

Posted by jax on Stack Overflow See other posts from Stack Overflow or by jax
Published on 2010-06-08T14:13:44Z Indexed on 2010/06/08 16:02 UTC
Read the original article Hit count: 176

Filed under:
|
|

in java if I run :

Locale.getDefault().toString()

I get zh_tw

I am sending this to a joomla site and setting the language like this:

$lang = &JFactory::getLanguage();
$lang->setLanguage( $_GET['lang'] );
$lang->load();

however the site requires the following format zh-TW

It appears that if it is not in that exact format the language will not change. Is there a function somewhere in java or php that will convert the format for me?

I realise that I could write the method myself like this:

    public static String convertLanguageToJoomlaFormat(String lang) {
    String[] parts = lang.split("_");
    if(parts.length ==2)
        return parts[0]+"-"+parts[1].toUpperCase();
    return lang;
}

but am unsure if there are any cases where the format changes for particular languages.

© Stack Overflow or respective owner

Related posts about java

Related posts about php