Is there a way to translate a QT app into different languages without defining the texts directly in the source? I want to separate the text from source. This would result in some kind of resource files for ALL languages, including the default language (e.g. English).
You won't be able to leave the English (or your source language, not necessarily English) source out of the XML (.ts) files as lupdate will put it there each time you run it. However as long as a translation exists for the chosen language, the source text will be ignored. If there is no translation text, it will default to the source text. This is useful since you'll be guaranteed to get some sort of text in your translation, but it'll be up to your test team to insure that the translations exist. I wrote a python script to automate the checking of the translation files since we have 9 languages and nearly 1k strings per translation. To test for this, we used a very simple sed script to create pseudo-loc source strings so if there were translations missing, the pseudo-loc text would be very evident.
Regarding the process for editing the .ts files, we farmed out the translations to individual translators, providing them with the .ts file for their language, and usually about an hour's worth of hand's on instruction in using QT Linguist. If the translator was onsite and wanted to see their translations on our device immediately, I wrote an autorun script that would place the resultant .qm file in the right place in our embedded file system and restart the application to display the new translations. If they weren't onsite, we'd run them through the python script mentioned above to check for a number of different problems, then simply check in the .ts file so it'd get built the next time around.
HTH
You might be able to use the QT_TRANSLATE_NOOP family of macros to do what you want. Those simply mark some text as "need to be translated" so that lupdate picks it up, but you can refer to those translated values by variable constants in your code. So ...
const char *kHelloWorld = QT_TRANSLATE_NOOP("SomeScope", "Hello world");
Later...
return qApp->translate("SomeScope", kHelloWorld);
This is still in your source code somewhere, but it is at least one step removed. You could theoretically have the QT_TRANSLATE_NOOP stuff in an entirely different Qt project, but then you'd need some way in your real project to know what you are supposed to translate. (You still need the char* constants somewhere.)
What are you trying to accomplish exactly by not having the English text in the source? That might help people provide more appropriate answers.
EDIT
Based on your comment below about intended usage
OK, then this is precisely what the normal Qt translation process does. Running lupdate creates those XML files (they have a .ts extension). They can be opened by translators in the very-easy-to-use Qt Linguist. They are translated, then sent back to you (the programmer), where you run lrelease on them to create the binary translation files you will ship with the app. The translations are resolved at runtime, so there is no need to recompile.
If you wanted to enable a user to do this, you would:
Ship your application with an empty (untranslated) .ts file and the lrelease program.
Provide instructions on how to use Qt Linguist to translate. (They could use a text editor and modify the Xml directly, but it's a lot easier with Linguist.)
Explain how to run lrelease and where to drop the binary translation files so that your application pulls them in.
On this last step, you could theoretically provide a nice wizard-like app that hides the implementation details.
What we will do is:
* Include a translation for the former default language. Using this *.ts file to auto-generate the other *.ts files. This is required as we keep the translations outside the QT environment as they match with other projects not related to QT.
Then have only have to make sure this translation contains the correct value.
In the future we can define IDs in the code witch represent Text in the default translation. Like translating TXT_ID_ABOUT to "About".
Related
When I synthesize a design using Xilinx ISE, the output file is named untitled.mcs. I would like to configure the project to use an output filename more appropriate to the project I am synthesizing.
I have examined all the properties easily reachable by right clicking the the implementation panel in the tool, but I can't find a configuration option to change output file names. I have also searched the help, but couldn't find anything useful. Can anyone suggest where I need to configure the output filename or tell me where or what to search?
I am aware of at least two things I could be doing wrong and would appreciate comments. First, I am not using TCL to synthesize my project. I just right click in the implementation panel and choose run. Perhaps if I create a TCL script to I would have finer control or output file naming. Second, I can see several files named untitled.x where x is [cfi|mcs|prm|sig]. I guess these are a sequence of files processed from one format to another, and if I understood the process, I could configure the name of the first and see all the derived files change their names to follow.
The answer to my question is that you don't use ISE to configure output PROM file names, you do it in the iMPACT tool. When it is properly configured, ISE will run iMPACT to create the programming file.
If anyone needs the precise details on configuring iMPACT, the built in help has the details. See the section entitled "Creating Xilinx Flash/PROM Files". During the setup of the programming file, you get to choose the output file name.
One extra pointer from me: The help says you double click to open a wizard. For me that didn't work, but there is an icon (or tool bar button) to launch the PROM file formatter wizard when Create PROM File is highlighted in the iMPACT Flows panel.
When you have created an saved an iMPACT project file, you select it in ISE and ISE will create a PROM programming file at the last step of the synthesize process.
I am learning Qt for the first time and I prefer to learn how to things the hand-coded way. I prefer learning this route because I am using Eclipse (with no Qt Designer) and I learn better knowing what is going on under the hood. Thus, I would like to know how to hand-code the XML-based user interface definition (.ui) files.
Unfortunately, I cannot seem to find any information on how this XML tree should be structured, and which properties and attributes are allowed. Instead, I find "drag-and-drop" tutorials. Aside from generating the .ui files in Qt Designer and then studying the output XML tree, is there another way to learn how to handcode these .ui files, or any documentation which speaks to the semantics of this XML document?
Thank you!
The UI file's sole purpose is to save you from hand-coding things. They're files that are generated by designer:
You create user interface components with Qt Designer and use Qt's integrated build tools, qmake and uic, to generate code for them when the application is built. The generated code contains the form's user interface object. It is a C++ struct that contains:
If you want to improve your knowledge of Qt, learning to write UIs via C++ would be a better option. Still, if you're convinced, there is this XML schema:
http://qt-project.org/doc/qt-4.8/designer-ui-file-format.html
Note that it says:
Be aware that the format may change in future Qt releases.
You might also be interested in the documentation for uic, which operates on the .ui file to create a header file containing the various widgets that make up the UI.
i have this tree structure:
repository/modules/module1
repository/modules/module2
repository/modules/module..
repository/apps/application1
repository/apps/application2
repository/apps/application..
where the applications are using some modules.
now, I'd like to put some resources inside a module (like a very colorfull icons inside a widget used by several applications) but.. something gets wrong.
inside the module CMakeLists.txt if I use only:
set(${MODULE_NAME}_RCS
colors.qrc
)
...
qt4_add_resources (${MODULE_NAME}_RHEADERS ${${MODULE_NAME}_RCS})
no qrc_colors.cxx are created anywhere. so I've tried to add:
ADD_EXECUTABLE (${MODULE_NAME}
${${MODULE_NAME}_RHEADERS}
)
but.. I get this weird error:
CMake Error at repo/modules/ColorModule/CMakeLists.txt:51 (ADD_EXECUTABLE):
add_executable cannot create target "ColorModule" because another
target with the same name already exists. The existing target is a static
library created in source directory
"repo/modules/ColorModule". See documentation for
policy CMP0002 for more details.
(I've changed the path of the error of course)
so.. don't know what to think because i'm new both to cmake and qt..
what can i try?
EDIT:
if I add the ${MODULE_NAME}_RHEADERS and ${MODULE_NAME}_RCS in the add_library command the qrc_colors.cxx is created BUT it is in repository/modules/module1/built and not copied in the application built directory...
There is at least two errors in your code.
1) It is usually not necessary to use ${MODULE_NAME} everywhere like that, just "MODULE_NAME". You can see that the difference is the raw string vs. variable. It is usually recommended to avoid double variable value dereference if possible.
2) More importantly, you seem to be setting ${MODULE_NAME} in more than one executable place, which is "ColorModule" according to the error output. You should have individual executable names for different binaries.
Also, the resource file focus is a bit of red herring in here. There are several other issues with your project.
You can cmake files as CmakeLists.txt instead of CMakeLists.txt which inherently causes issues on case sensitive systes as my Linux box.
You use Findfoo.cmake, and find_package(foo) for that matter, rather than the usual FindFoo.cmake convention alongside find_package(Foo).
Your FindFoo.cmake is quite odd, and you should probably be rewritten.
Most importantly, you should use config files rather than find modules.
Documentation and examples can be found at these places:
http://www.cmake.org/Wiki/CMake/Tutorials#CMake_Packages
https://projects.kde.org/projects/kde/kdeexamples/repository/revisions/master/show/buildsystem
When you would like use a find module, you need to have that at hand already. That will tell you what to look for, where things are, or if they are not anywhere where necessary. It is not something that you should write. You should just reuse existing ones for those projects that are not using cmake, and hence the find modules are added separately.
It is a bit like putting the treasure map just next to the treasure. Do you understand the irony? :) Once you find the map, you would automatically have the treasure as well. i.e. you would not look for it anymore.
Here's my problem: We've got .ts files for nine different languages for our product. We've added about 100 new strings that need to be translated, but some are for our next release, and some are for the release after that. We've run into problems with translators missing strings or translating strings ahead of time. We want to be able to send them smaller .ts file containing only the strings we want translated now, and then merge that .ts file into the larger .ts file containing the rest of the translation.
Our translators are required to use QT Linguist (previously we let them edit the raw XML with less than stellar results).
One solution would be to use contexts, but our dev team is not very keen on that idea. Another would be to merge the .ts files by hand, but that seems like a recipe for cut & paste errors.
Is there a method with lupdate & the project file to add or merge secondary .ts files? I've read through the forums in QT-land w/o finding the answer, but the switches in lupdate allude to being able to point to other translation files. Specifically the -pro switch which says:
-pro <filename>
Name of a .pro file. Useful for files with .pro file syntax but
different file suffix. Projects are recursed into and merged.
Example1: we have a German .ts file, we want to add 20 strings from a separate German translation file such that the primary translation file contains all the strings including the 20 new ones.
Example2: we have a German .ts file, we want to add 20 strings from a separate German translation file such that the secondary translation file will be merged with the primary during lupdate so that the resultant .qm file contains all the strings including the 20 new ones.
Has anyone done either of these (and either would work) and can you give me some insight?
The answer doesn't use lupdate, it lies in another utility called lconvert. It's quite easy to create a secondary file that only contains the strings you're interested in (and delete those same strings from the primary file), then run:
lconvert -i primary.ts secondary.ts -o complete.ts
This will take all the strings from the two input files and put them together into the output file. Using this method I was able to create a zero difference file (other than time stamp) of the original file that I'd split the two primary & secondary files from.
This question didn't get a lot of attention, but maybe someone will have this same problem and this will help.
thanks for this tip. It seems to work properly for my case :
I tried to extract updated and new strings from my project, which is currently under translation in an older version/release that I do not already have translated strings.
The problem was to send the new/updated strings only to translators.
I passed older strings in status resolved, adding new string using Lupdate, make a research using OxygenXML Editor with an XPath "/TS/context/message[not(translation/#type)]" to delete older strings, and clean it from useless blanks and carriage returns.
I tried a merge using lconvert with your solution, in order to merge translated strings : older and newer. It pass correctly lrelease and are displayed properly.
Im learning how to use QT's translate stuff for the first time for work.
They already have things working to some degree and its my job to clean
things up and get it working properly as well as using lupdate to keep
things in sync when they change etc. We are also using QML in which we
wrote a wrapper function for all our strings, so lupdate does not find
our function to add to the .ts XML file. The reason we use a wrapper is
for centralizing other functions at once place for all strings. We also
dont always use a string literal in our 'source' argument but a defined
property, such as:
property string buttonTxt: "ButtonText"
then: commonTRFunction(context, buttonTxt)
which of course lupdate does not find for both reasons.
Ive looked into updating the lupdate source very briefly
and Im not sure if its worth trying to hack it to find our function or
write our own parser to find the standard QT tags AND also our new ones?
Secondly, and related to the first part, Id like a way to make one
context section that contains all the common words we use in our app
such as 'Back', 'Save', 'Ok' etc etc without repeating it over and over
throughout the .ts file. lupdate seems to repeat things over and over
in multiple contexts which seems both inefficient and a waste of lines
in the ts file.
I haven't found any QT docs that really explain the differences between tr(), qsTr(), qsTranslate(), QT_TR_NOOP() and QT_TRANSLATE_NOOP(). I know you sometimes need a context and the source,
and other times just use the source without a context. We dont use
the disambigous arg. Most of our code is in QML and not C++.
Also we are running lupdate from the command line.
Does anyone have thoughts, suggestions or even a tool someone wrote
that can be used for what we have? I appreciate your help.