Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. How to set file name according to current system language in windows

How to set file name according to current system language in windows

Scheduled Pinned Locked Moved Unsolved Language Bindings
11 Posts 5 Posters 1.6k Views
  • 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.
  • S Offline
    S Offline
    Santhosh Ayanoor
    wrote on last edited by
    #1

    Hiii guys
    I'm creating the file called Users.txt in Windows using Qt Application. When ever language settings are changed I would like display the name of the file in appropriate languages.
    e.g English file name Users.txt
    German File name Benutzer.txts
    there a way to acheive this in Qt ?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      See the Internationalization with Qt chapter in Qt's documentation.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply
      5
      • SGaistS SGaist

        Hi,

        See the Internationalization with Qt chapter in Qt's documentation.

        S Offline
        S Offline
        Santhosh Ayanoor
        wrote on last edited by
        #3

        Hii @SGaist
        we creating the user.txt file in some directory for example c:/san/users.txt not in UI .
        according to system lang that file name should change like system lang=en that file name shoulb show user.txt if o

        1 Reply Last reply
        0
        • artwawA Offline
          artwawA Offline
          artwaw
          wrote on last edited by artwaw
          #4

          Hi,
          the way I see it you can achieve the functionality by doing one of the below:

          1. create manual mappings (QMap or smth) where the key is lang (QString) (i.e. en_US, en_GB, de_DE etc.) and the value for given key is (QString) file name (user, user, benutzer, etc). This way you can automate this, if I understood your goal properly.
          2. other way is to rename your files to include lang value, either by prepending/adding to the file name (en_EN_user, en_GN_user, de_DE_benutzer - or user_en_EN, etc.) or by . notation (user.en_EN.txt, user.en_GB.txt, etc) so you can easily extract locale form file name using QString::split or QRegularExpression.

          Edit: the second way with regular expressions is actual use case in one of my tools but it's designed to handle hundreds of files so might be a bit of overshot for you.

          For more information please re-read.

          Kind Regards,
          Artur

          1 Reply Last reply
          2
          • J.HilkJ Online
            J.HilkJ Online
            J.Hilk
            Moderators
            wrote on last edited by J.Hilk
            #5

            QFile f(pathToFile + tr("Users")+ QString(".txt"));

            this way Users should change accordingly to the QTanslator installed.


            Edit:
            @Santhosh-Ayanoor

            I would like display the name of the file in appropriate languages

            please clarify, do you want to change the file name according to the language settings or do you want to display it (for example) on a QLabel as text, but the actual file name is always the same?


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            S 1 Reply Last reply
            4
            • J.HilkJ J.Hilk

              QFile f(pathToFile + tr("Users")+ QString(".txt"));

              this way Users should change accordingly to the QTanslator installed.


              Edit:
              @Santhosh-Ayanoor

              I would like display the name of the file in appropriate languages

              please clarify, do you want to change the file name according to the language settings or do you want to display it (for example) on a QLabel as text, but the actual file name is always the same?

              S Offline
              S Offline
              Santhosh Ayanoor
              wrote on last edited by
              #6

              hii @J-Hilk
              like that only ... my system lang is en and my friend system lang is german according system lang my user.txt name should be change

              J.HilkJ 1 Reply Last reply
              0
              • S Santhosh Ayanoor

                hii @J-Hilk
                like that only ... my system lang is en and my friend system lang is german according system lang my user.txt name should be change

                J.HilkJ Online
                J.HilkJ Online
                J.Hilk
                Moderators
                wrote on last edited by
                #7

                @Santhosh-Ayanoor

                than QLocale is what you're looking for:
                https://doc.qt.io/qt-5/qlocale.html#system

                example:

                int main(int argc, char *argv[])
                {
                    QApplication a(argc, argv);
                
                    QLocale currentLocale = QLocale::system();
                
                    qDebug() << "FileName should be:" << (currentLocale.language() == QLocale::German ? "Benutzer.txt" : "Users.txt");
                
                    return a.exec();
                }
                

                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply
                2
                • S Offline
                  S Offline
                  Santhosh Ayanoor
                  wrote on last edited by
                  #8

                  @J-Hilk Thanks for you answer. Your code will help me to create the file based on the current locale at start of my app.

                  Now if the user changes the locale of the system, how to change the file name from German to English or vice-versa ?

                  JonBJ 1 Reply Last reply
                  0
                  • S Santhosh Ayanoor

                    @J-Hilk Thanks for you answer. Your code will help me to create the file based on the current locale at start of my app.

                    Now if the user changes the locale of the system, how to change the file name from German to English or vice-versa ?

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #9

                    @Santhosh-Ayanoor
                    [Assuming you really do mean "change the filename on disk".] So you'll have to trap the system locale language change, and rename all the file(s) from their old language name to the new one. But: user may not change system locale while you app is running, he may change it when it isn't. So you'll want to do something like also check for/do this renaming every time your app starts up as well. But at that point, you won't know what the locale was the last time you ran, so you won't even know what the filename(s) were previously saved as so you can rename them now, so goodness knows how you think you're going to deal with that [you'll have to save somewhere what the locale/filename(s) was previously]....

                    This file-rename-per-language all sounds hokey to me. Are you sure you really want to do this?!

                    1 Reply Last reply
                    3
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by SGaist
                      #10

                      Just in case, Windows might show you some translated folder name but if you take a look at what is actually on disk, it's in English.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      JonBJ 1 Reply Last reply
                      0
                      • SGaistS SGaist

                        Just in case, Windows might show you some translated folder name but if you take a look at what is actually on disk, it's in English.

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by
                        #11

                        @SGaist
                        OIC. So

                        how to change the file name from German to English or vice-versa

                        The OP does not really mean change the filename (on disk)? Then there is no issue.

                        1 Reply Last reply
                        0

                        • Login

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