Results 1 to 10 of 10

Thread: Splitting Translation Files

  1. #1
    Join Date
    Jan 2006
    Location
    Edmonton, Canada
    Posts
    101
    Thanks
    13
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Splitting Translation Files

    Good day,

    I'd like to be able to split the translation files in my application.

    In my scenario, when the user launches the appplication, an initial translation file will load to provide translated text for the login dialog. Once the user has logged in, I want to load a different translation dependant upon that user's preferences. I would prefer not to load the translation for the entire application when loading the login dialog because I don't think that is efficient. I would prefer to have a seperate .ts/.qm for the login dialog.

    Has anyone tried this? I imagine that I could create two .ts files by manually cutting out the login dialog text from the .ts file initially generated by lupdate and pasting it into a new .ts file, but I have not tried this. Furthermore, it is not practical for me to edit the xml every time I run lupdate. Is there a better way to do this?

    Thank you in advance,

    Jimmy

  2. #2
    Join Date
    Jan 2006
    Location
    Scandinavia
    Posts
    62
    Thanks
    5
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Splitting Translation Files

    I see no problem in loading a small translation .qm file for your initial dialogue.

    Online translation changes can also be done run-time. I've done it and the only thing to remember is to be sure to use functions like 'languageUpdate' for 'text' that has been initialized already.

    Furthermore, it is not practical for me to edit the xml every time I run lupdate. Is there a better way to do this?
    The only reason for editing the xml file would be in case you've added more text, right? How else would you get the text translated? Using an babelfish SOAP solution? --- I hope you are using QLinguist for editing the translation files. That's far easier than editing the xml files directly.

  3. #3
    Join Date
    Jan 2006
    Location
    Edmonton, Canada
    Posts
    101
    Thanks
    13
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Splitting Translation Files

    Thanks for your reply.

    Yes, I am using QT's Linguist for translating.

    The reason I am talking about editing the .ts XML is because I want to have two .ts/.qm files for each language - one for the Login and one for the rest of the application. At this point the only way I can think of to accomplish this is:
    1. Run lupdate on my project
    2. Cut the login text from each generated .ts file
    3. Paste the login text into a new Login .ts file for each translation
    4. Use Linguist to translate the text
    5. Run lrelease to generate two .qm files for each translation

    I believe this will work (although I have not tried it), but this is not efficient as there are too many manual steps every time I want to create/update the translations. I want to know if there is a better way to accomplish what I am trying to do here.

    Thanks

  4. #4
    Join Date
    Jan 2006
    Location
    Athens - Greece
    Posts
    219
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Splitting Translation Files

    Quote Originally Posted by Jimmy2775
    I want to know if there is a better way to accomplish what I am trying to do here.
    If you have your login widget in different source files than the rest of your project you can call lupdate specifying only the files you want it to parce:
    Qt Code:
    1. lupdate [login_source_file.cpp] -ts [ts_file_1]
    2. lupdate [all other but login_source_file.cpp] -ts [ts_file_2]
    To copy to clipboard, switch view to plain text mode 
    I still don't see why you want to split it though. I think the best solution is to have a single qm for your whole app.

  5. #5
    Join Date
    Jan 2006
    Location
    Edmonton, Canada
    Posts
    101
    Thanks
    13
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Splitting Translation Files

    OK - that is the information I was looking for. Thank you. Where did you find it? As of yet I haven't been able to find much documentation about lupdate and lrelease.

    I still don't see why you want to split it though.
    In my application the system does not know the user's preferred language until after the user has logged in - login is accomplished using the application's default translation. If I only use one translation file for the application, then the entire translation file is loaded when the application launches, and then after the user logs in, the entire translation file may be loaded again if the user's preferred language differs from the system default. If I split the translation file, then only the login translation is loaded when the application launches, and then after the user logs in the translation file for the rest of the application is loaded.

    In my opinion, it is less efficient to load a translation for the entire application twice than it is to load one small login translation, and then load the rest of the application's translation. That is why I want to split the translation file. That said, QT is still new to me so I welcome any ideas and opinions on the subject.

  6. #6
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Splitting Translation Files

    Quote Originally Posted by Jimmy2775
    In my opinion, it is less efficient to load a translation for the entire application twice than it is to load one small login translation, and then load the rest of the application's translation. That is why I want to split the translation file. That said, QT is still new to me so I welcome any ideas and opinions on the subject.
    My opinion (for what it's worth) - don't worry about the efficiency, it's really not a big issue. It's tempting to try and solve problems before they occur, but often the problem you are trying to solve doesn't really exist. In my experience, loading Japanese translation files for large EDA tools that I have written takes a negligible amount of time at startup. In fact, there's no noticable difference in time between starting the app in English and starting it in Japanese.

    Get the app working the 'easy' way, then worry about refining it when it is all tested and working perfectly!

  7. #7
    Join Date
    Jan 2006
    Location
    Athens - Greece
    Posts
    219
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Splitting Translation Files

    Quote Originally Posted by Jimmy2775
    OK - that is the information I was looking for. Thank you. Where did you find it?
    lupdate -help

  8. #8
    Join Date
    Jan 2006
    Location
    Scandinavia
    Posts
    62
    Thanks
    5
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Splitting Translation Files

    I think you got very good help above

    I agree that you probably don't have to worry about efficiency.

    If you have a lot of source files and directories this approach may help: I used a script for generating .pro files which I then called lupdate on (to get updated or new .ts files). Basically the script scanned certain directories, skipped others, and added the found files to the .pro files.

    This way I could separate the .ts/qm files between different applications, shared directories etc. The translators also appreciated having smaller files to work with instead of huge .ts files (although the overhead might increase)

  9. #9
    Join Date
    Jan 2006
    Location
    Athens - Greece
    Posts
    219
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Splitting Translation Files

    Quote Originally Posted by KjellKod
    ...although the overhead might increase
    This is one of my main concerns and I said that I'd prefer one qm file, the other is that when you use more than one it's easier to forget to switch between them and the code is more hard to maintain. Anyway I'm sure that you've all thought that this is the best approach for your case, I'm just giving some extra food for thought

  10. #10
    Join Date
    Jan 2006
    Location
    Edmonton, Canada
    Posts
    101
    Thanks
    13
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Talking Re: Splitting Translation Files

    That's excellent - thank you for your posts yop, KjellKod, and Chicken Blood Machine, it is very much appreciated.

    For now I think it is wise to go with the simplest solution (only one .qm per translation) and not to worry about the efficiency unless it becomes a problem.

    Thanks again.

    Jimmy

Similar Threads

  1. visual studio project files - adding extra files
    By luf in forum Qt Programming
    Replies: 3
    Last Post: 13th June 2008, 22:05
  2. Replies: 5
    Last Post: 22nd September 2006, 09:04
  3. [Win32/VC++ 8.0] Strange problems with qrc_*.cpp files
    By mloskot in forum Installation and Deployment
    Replies: 6
    Last Post: 6th March 2006, 11:28

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.