QTranslator Class ReferenceThe QTranslator class provides internationalization support for text output. More... #include <qtranslator.h> Inherits QObject. Public Members
Detailed DescriptionThe QTranslator class provides internationalization support for text output.
An object of this class contains a set of QTranslatorMessage objects, each of which specifies a translation from a source language to a target language. QTranslator provides functions to look up translations, add new ones, remove them, load and save them, etc. The most common use of QTranslator is to: load a translator file created with Qt Linguist, install it using QApplication::installTranslator(), and use it via QObject::tr(). For example:
int main( int argc, char ** argv ) { QApplication app( argc, argv ); QTranslator translator( 0 ); translator.load( "french.qm", "." ); app.installTranslator( &translator ); MyWidget m; app.setMainWidget( &m ); m.show(); return app.exec(); } Most applications will never need to do anything else with this class. The other functions provided by this class are useful for applications that work on translator files. We call a translation a "messsage". For this reason, translation files are sometimes referred to as "message files". It is possible to lookup a translation using findMessage() (as tr() and QApplication::translate() do) and contains(), to insert a new translation messsage using insert(), and to remove one using remove(). Translation tools often need more information than the bare source text and translation, for example, context information to help the translator. But end-user programs that are using translations usually only need lookup. To cater for these different needs, QTranslator can use stripped translator files that use the minimum of memory and which support little more functionality than findMessage(). Thus, load() may not load enough information to make anything more than findMessage() work. save() has an argument indicating whether to save just this minimum of information or to save everything. "Everything" means that for each translation item the following information is kept:
The minimum for each item is just the information necessary for findMessage() to return the right text. This may include the source, context and comment, but usually it is just a hash value and the translated text. For example, the "Cancel" in a dialog might have "Anuluj" when the program runs in Polish (in this case the source text would be "Cancel"). The context would (normally) be the dialog's class name; there would normally be no comment, and the translated text would be "Anuluj". But it's not always so simple. The Spanish version of a printer dialog with settings for two-sided printing and binding would probably require both "Activado" and "Activada" as translations for "Enabled". In this case the source text would be "Enabled" in both cases, and the context would be the dialog's class name, but the two items would have disambiguating comments such as "two-sided printing" for one and "binding" for the other. The comment enables the translator to choose the appropriate gender for the Spanish version, and enables Qt to distinguish between translations. Note that when QTranslator loads a stripped file, most functions do not work. The functions that do work with stripped files are explicitly documented as such.
See also QTranslatorMessage, QApplication::installTranslator(), QApplication::removeTranslator(), QObject::tr(), QApplication::translate(), Environment Classes and Internationalization with Qt. Member Type Documentation
|
Publicité
Best OfActualités les plus luesSemaine
Mois
Année
Le blog Digia au hasardCréer des applications avec un style Metro avec Qt, exemples en QML et C++, un article de Digia Qt traduit par Thibaut CuvelierLe blog Digia est l'endroit privilégié pour la communication sur l'édition commerciale de Qt, où des réponses publiques sont apportées aux questions les plus posées au support. Lire l'article.
CommunautéRessources
Liens utilesContact
Qt dans le magazine |
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 3.0 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com