Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved nativeLanguageName is too verbose

    General and Desktop
    2
    5
    199
    Loading More Posts
    • 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.
    • Megamouse
      Megamouse last edited by

      Hi,
      I am currently trying to implement a list of languages that the user can choose when they want to change the localization of our program.

      The QLocales are created using the available .qm filenames, which works perfectly fine.

      The problem I'm having is that the nativeLanguageString of some QLocales can end up really ugly, when used in combination with the native country name.

      QLocale locale = QLocale("en");
      myString = locale.nativeLanguageName() + " (" + locale.nativeCountryName() + ")";
      

      I would expect to see something like "English (United States)"
      But instead the result is "American English (United States)"

      I already found out that QLocale::languageToString(locale)will return "English", which apparently is hardcoded as english string in the Qt souce code.

      So my main question is:
      Is there a way to make this look better in its native language?
      Or what is the commonly recommended way to show language selections to the user?

      Best regards,
      Megamouse

      Pablo J. Rogina 2 Replies Last reply Reply Quote 1
      • Pablo J. Rogina
        Pablo J. Rogina @Megamouse last edited by

        @Megamouse said in nativeLanguageName is too verbose:

        nativeLanguageName()

        From the method source code, it looks the "ugly" name comes from the system locale (based on underlying OS) if Qt was configured to use system locale, or from a built-in table if not.

        See that the method comment already make you aware of the possible return values:

        Returns a native name of the language for the locale. For example

        "Schwiizertüütsch" for Swiss-German locale.
        

        Upvote the answer(s) that helped you solve the issue
        Use "Topic Tools" button to mark your post as Solved
        Add screenshots via postimage.org
        Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

        1 Reply Last reply Reply Quote 2
        • Pablo J. Rogina
          Pablo J. Rogina @Megamouse last edited by

          @Megamouse said in nativeLanguageName is too verbose:

          Or what is the commonly recommended way to show language selections to the user?

          If the list of possible languages to select from is "short", which should be the case since you're are already creating locales using the available .qm filenames you could use a QMap<QLocale, QString> structure for instance and provide the whatever fancy name you want for a particular locale.

          Upvote the answer(s) that helped you solve the issue
          Use "Topic Tools" button to mark your post as Solved
          Add screenshots via postimage.org
          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

          1 Reply Last reply Reply Quote 1
          • Megamouse
            Megamouse last edited by

            @Pablo-J-Rogina I'm not adding the files.
            It's an open source software, so anyone can add their own language to their local build. But we don't ship translations ourselves.

            That's why a map is not feasible, unless someone has a map of language code to all the language names in their native tongue (ideally plus optional country).

            I'm tempted to simply go with the "ugly" verbose solution and hope that someone who gets triggered enough fixes it elegantly in the future.

            Pablo J. Rogina 1 Reply Last reply Reply Quote 0
            • Pablo J. Rogina
              Pablo J. Rogina @Megamouse last edited by

              @Megamouse said in nativeLanguageName is too verbose:

              That's why a map is not feasible, unless someone has a map of language code to all the language names

              Taking a second look at the "requirements", you could add one string in your open source code that's the "nativeLanguageName" and so, everyone adding a new language will have that string to translate in the set of strings to translate. So whenever a language file is loaded, the "nice" native language name is already there...

              Upvote the answer(s) that helped you solve the issue
              Use "Topic Tools" button to mark your post as Solved
              Add screenshots via postimage.org
              Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

              1 Reply Last reply Reply Quote 0
              • First post
                Last post