Correct code to display available languages
-
I've got translation files called DSS_lang.qm
Included in the list are:
DSS_zh_CN.qm
DSS_zh_TW.qmI have a dialog that allow the user to change the language using a combo-box. I populate the combo using this code:
QDir dir(":/i18n/", "DSS_*.qm"); for(auto it: dir.entryList()) { QString lang = it.section('_', 1, 1); lang = lang.section('.', 0, 0); QString langName = QLocale(lang).nativeLanguageName(); if ("en" == lang) langName = "English"; ui->comboBox->addItem(langName, lang); }
Problem is that both versions of Chinese display with the same text:
So how is the user to distinguish.If my code is not correct, what is the correct code to populate the combo-box to distinguish between Simplified and Traditional Chinese?
Thanks
David -
I've got translation files called DSS_lang.qm
Included in the list are:
DSS_zh_CN.qm
DSS_zh_TW.qmI have a dialog that allow the user to change the language using a combo-box. I populate the combo using this code:
QDir dir(":/i18n/", "DSS_*.qm"); for(auto it: dir.entryList()) { QString lang = it.section('_', 1, 1); lang = lang.section('.', 0, 0); QString langName = QLocale(lang).nativeLanguageName(); if ("en" == lang) langName = "English"; ui->comboBox->addItem(langName, lang); }
Problem is that both versions of Chinese display with the same text:
So how is the user to distinguish.If my code is not correct, what is the correct code to populate the combo-box to distinguish between Simplified and Traditional Chinese?
Thanks
DavidSince you pass the same string two times to QLocale() I would be surprised if you would get two different strings back.
-
Since you pass the same string two times to QLocale() I would be surprised if you would get two different strings back.
@Christian-Ehrlicher Blush!!!!
The following works a LOT better!
QDir dir(":/i18n/", "DSS_*.qm"); for(auto it: dir.entryList()) { QString lang = it.section('_', 1); lang = lang.section('.', 0, 0); QString langName = QLocale(lang).nativeLanguageName(); if ("en" == lang) langName = "English"; ui->comboBox->addItem(langName, lang); }