免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1129 | 回复: 0
打印 上一主题 下一主题

QT 翻译补充 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-07-09 16:53 |只看该作者 |倒序浏览
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
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP