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. [SOLVED]Localizing resources
QtWS25 Last Chance

[SOLVED]Localizing resources

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 3.0k 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.
  • D Offline
    D Offline
    Davita
    wrote on last edited by
    #1

    Hello guys

    First of all, sorry for this stupid question :)

    I'm storing some text files in embedded resource file which I want to localize. Is there any way to load the text file which targets currently selected language in the application? What's the best practice for localizing resources. I'm aware of the tr() function, but I want to avoid hardcoding those texts in the application.

    I tried searching the net but couldn't find anything helpful :(

    Thanks

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      You can get locale by invoking:
      @QLocale::system().name(); // Returns QString with locale name@

      Then just use it to load particular file from QRC.

      (Z(:^

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Davita
        wrote on last edited by
        #3

        Is this the best approach? I mean, in .NET, you could just append locale name to the resource (e.g. MyResource.resx, MyResource.ru-RU.resx etc) and the framework automatically recognizes which resource to load by current locale. I thought maybe there is such way in Qt too?

        1 Reply Last reply
        0
        • EddyE Offline
          EddyE Offline
          Eddy
          wrote on last edited by
          #4

          have a look at the "arrow pads example":http://doc.qt.nokia.com/4.7/linguist-arrowpad.html.

          Qt Certified Specialist
          www.edalsolutions.be

          1 Reply Last reply
          0
          • sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #5

            There is one, yes, but when you use tr() macro (it's fun, by the way, try it! And locales are stored as separate files). I am not sure it can be used for QRC (which can hold any files, including pictures). I don't know whether it's the best way, just first one that popped into my mind.

            (Z(:^

            1 Reply Last reply
            0
            • D Offline
              D Offline
              Davita
              wrote on last edited by
              #6

              I see guys, I think Eddy's answer suits better to my need :)
              Thank you very much again :)

              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