- 论坛徽章:
- 0
|
1。Distinguishing Identical Strings That Require Different Translations例如:
rbc = new QRadioButton( tr("Enabled", "Color frame"), this );
and
rbh = new QRadioButton( tr("Enabled", "Hue frame"), this );
2.Helping The Translator With Navigation Information
In
large complex applications it may be difficult for the translator to
see where a particular source text comes from. This problem can be
solved by adding a comment using the keyword TRANSLATOR which describes the navigation steps to reach the text in question; e.g.
/* TRANSLATOR FindDialog
Choose Edit|Find from the menu bar or press Ctrl+F to pop up the
Find dialog.
*/
Coping With C++ Namespaces
C++ namespaces and the using namespace statement can confuse
lupdate
. It will interpret MyClass::tr() as meaning just that, not as MyNamespace::MyClass::tr(), even if MyClass is defined in the MyNamespace namespace. Runtime translation of these strings will fail because of that.
You can work around this limitation by putting a TRANSLATOR comment at the beginning of the source files that use MyClass::tr():
/* TRANSLATOR MyNamespace::MyClass */
After the comment, all references to MyClass::tr() will be understood as meaning MyNamespace::MyClass::tr().
Translating Text that is Outside of a QObject subclass
Using QApplication::translate()
If the quoted text is not in a member function of a QObject
subclass, use either the tr() function of an appropriate class, or the
QApplication::translate() function directly:
void some_global_function( LoginWidget *logwid )
{
QLabel *label = new QLabel(
LoginWidget::tr("Password:"), logwid );
}
void same_global_function( LoginWidget *logwid )
{
QLabel *label = new QLabel(
qApp->translate("LoginWidget", "Password:"),
logwid );
}
Using QT_TR_NOOP() and QT_TRANSLATE_NOOP()
If you need to have translatable text completely outside a function,
there are two macros to help: QT_TR_NOOP() and QT_TRANSLATE_NOOP().
These macros merely mark the text for extraction by
lupdate
. The macros expand to just the text (without the context).
Example of QT_TR_NOOP():
QString FriendlyConversation::greeting( int greet_type )
{
static const char* greeting_strings[] = {
QT_TR_NOOP( "Hello" ),
QT_TR_NOOP( "Goodbye" )
};
return tr( greeting_strings[greet_type] );
}
Example of QT_TRANSLATE_NOOP():
static const char* greeting_strings[] = {
QT_TRANSLATE_NOOP( "FriendlyConversation", "Hello" ),
QT_TRANSLATE_NOOP( "FriendlyConversation", "Goodbye" )
};
QString FriendlyConversation::greeting( int greet_type )
{
return tr( greeting_strings[greet_type] );
}
QString global_greeting( int greet_type )
{
return qApp->translate( "FriendlyConversation",
greeting_strings[greet_type] );
}
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/70379/showart_1077012.html |
|