Traslate string saved in db
I'd like to store the errors in a sqlite db but i need to support multiple Language.
What I need is a way to store code/description and then collect and display the translated string. A very userfull stuff would be the ability to define the description using the tr macros in order to use the lupdate tool.
Well, you will need to store each string in each language in your database tagged with a language code and tied to a the default language string You will then need to write your own equivalent of the QCoreApplication::translate() functionality to access strings via the database and use that in your code.
You could use the linguist tools by writing a program to read your database's base language strings out and creating an XML file (the TS file) for input to the translation tools. When the transaltion is done you would need a tool to read the linguist XML and update your database.
I was waiting this replay and as I suspected I think this the only way to go haed.
I realy dislike the Internationalization in qt.
For example in order to get the string traslated to another language I have to traslate all the application and access the value using tr all of this just to know an hashmap key/value!
Actually there is another approach. If the error string (or any strings) are static and are known in advance you can then store only an ID of that string in your database. Then in your application you would make a translation of the ID to a QObject::tr() enabled string, i.e.
int stringID; //this could probably be even an un-translated English text
... //get the id from db
if(stringID = 10) return tr("String to translate");
When accessing the database and loading it to a model you can subclass the model to provide this resolution in its data() function. Or in a proxy model sub-class. For compound errors etc. you can make translatable only the static part. Qt native strings are already translated to many languages so just load relevant Qt .qm file(s) for your language as well.
I find this approach much easier for static strings (like errors). For dynamic data like user data that should support internationalization you should search for "database internationalization" and see some common approaches. Linguist Tool would not be very useful in that situation anyway (as great as it is).