Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Correct code to display available languages
Qt 6.11 is out! See what's new in the release blog

Correct code to display available languages

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 435 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • PerdrixP Offline
    PerdrixP Offline
    Perdrix
    wrote on last edited by Perdrix
    #1

    I've got translation files called DSS_lang.qm

    Included in the list are:

    DSS_zh_CN.qm
    DSS_zh_TW.qm

    I 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:
    2df8d518-93f4-4c52-9679-beab09645238-image.png
    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

    Christian EhrlicherC 1 Reply Last reply
    0
    • PerdrixP Perdrix

      I've got translation files called DSS_lang.qm

      Included in the list are:

      DSS_zh_CN.qm
      DSS_zh_TW.qm

      I 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:
      2df8d518-93f4-4c52-9679-beab09645238-image.png
      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

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by Christian Ehrlicher
      #2

      Since you pass the same string two times to QLocale() I would be surprised if you would get two different strings back.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      PerdrixP 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        Since you pass the same string two times to QLocale() I would be surprised if you would get two different strings back.

        PerdrixP Offline
        PerdrixP Offline
        Perdrix
        wrote on last edited by Perdrix
        #3

        @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);
            }
        

        131109de-f9c3-485b-af37-b2f71e31e6cc-image.png

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved