PDA

View Full Version : Splitting Translation Files



Jimmy2775
1st February 2006, 22:31
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

KjellKod
2nd February 2006, 12:06
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 (http://babelfish.altavista.com)SOAP solution? --- I hope you are using QLinguist for editing the translation files. That's far easier than editing the xml files directly.

Jimmy2775
2nd February 2006, 19:16
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:

Run lupdate on my project
Cut the login text from each generated .ts file
Paste the login text into a new Login .ts file for each translation
Use Linguist to translate the text
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

yop
2nd February 2006, 21:14
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:

lupdate [login_source_file.cpp] -ts [ts_file_1]
lupdate [all other but login_source_file.cpp] -ts [ts_file_2]

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.

Jimmy2775
2nd February 2006, 22:39
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.

Chicken Blood Machine
3rd February 2006, 05:47
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!

yop
3rd February 2006, 08:29
OK - that is the information I was looking for. Thank you. Where did you find it? lupdate -help

KjellKod
3rd February 2006, 08:41
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)

yop
3rd February 2006, 08:58
...although the overhead might increaseThis 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

Jimmy2775
3rd February 2006, 20:23
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