How to differentiate between traditional and simplified Chinese using QLocale

297 Views Asked by At

I have to show the list of languages available for user to select. The list will have (Auto) as the first option which is the operating system language and will have further languages as add-on.

as shown here

Here English is the Auto Language.

The problem here is, If the OS language is Chinese, how do I differentiate between simplified and traditional. My code is:

QLocale loc = QLocale::system();
QString defaultLocale = loc.name();       // e.g. "de_DE"
defaultLocale.truncate(defaultLocale.lastIndexOf('_')); // e.g. "de"
QStringList languageList;
languageList.append("auto (System language)");
if(defaultLocale != "de")
    languageList.append("German");
if(defaultLocale != "en")
    languageList.append("English");
if(defaultLocale != "fr")
    languageList.append("French");
if(defaultLocale != "it")
    languageList.append("Italian");
if(defaultLocale != "es")
    languageList.append("Spanish");
if(defaultLocale != "zh")
{
    languageList.append("Chinese Simple");
    languageList.append("Chinese Traditional");
}
if(defaultLocale == "zh") 
{
    if(loc.script() == QLocale::SimplifiedChineseScript)
        languageList.append("Chinese Traditional");
    else
        languageList.append("Chinese Simple");
}
if(defaultLocale != "ja")
    languageList.append("Japanese");

Here the loc.script() is always returning 0 stating "Any Script" option. If the operating system language is Chinese, then how do I differentiate between simplified and traditional? and why is the script() not returning the proper value?

0

There are 0 best solutions below