Редактирование: Qt:Документация 4.3.2/i18n

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск
Внимание: Вы не представились системе. Ваш IP-адрес будет записан в историю изменений этой страницы.
Правка может быть отменена. Пожалуйста, просмотрите сравнение версий, чтобы убедиться, что это именно те изменения, которые вас интересуют, и нажмите «Записать страницу», чтобы изменения вступили в силу.
Текущая версия Ваш текст
Строка 2: Строка 2:
=Internationalization with Qt<br />=
=Internationalization with Qt<br />=
-
<div id="internationalization"></div><div id="i18n"></div>
 
The internationalization of an application is the process of making the application usable by people in countries other than one's own.
The internationalization of an application is the process of making the application usable by people in countries other than one's own.
-
 
-
*[[#step-by-step | Step by Step]]
 
-
**[[#use-qstring-for-all-user-visible-text | Use QString for All User-Visible Text]]
 
-
**[[#use-tr-for-all-literal-text | Use tr() for All Literal Text]]
 
-
**[[#use-qkeysequence-for-accelerator-values | Use QKeySequence() for Accelerator Values]]
 
-
**[[#use-qstring-arg-for-dynamic-text | Use QString::arg() for Dynamic Text]]
 
-
**[[#produce-translations | Produce Translations]]
 
-
**[[#support-for-encodings | Support for Encodings]]
 
-
**[[#localize | Localize]]
 
-
*[[#dynamic-translation | Dynamic Translation]]
 
-
*[[#translating-non-qt-classes | Translating Non-Qt Classes]]
 
-
*[[#system-support | System Support]]
 
-
**[[#unix-x11 | Unix/X11]]
 
-
**[[#windows | Windows]]
 
-
*[[#note-about-locales-on-x11 | Note about Locales on X11]]
 
-
*[[#relevant-qt-classes | Relevant Qt Classes]]
 
In some cases internationalization is simple, for example, making a US application accessible to Australian or British users may require little more than a few spelling corrections. But to make a US application usable by Japanese users, or a Korean application usable by German users, will require that the software operate not only in different languages, but use different input techniques, character encodings and presentation conventions.
In some cases internationalization is simple, for example, making a US application accessible to Australian or British users may require little more than a few spelling corrections. But to make a US application usable by Japanese users, or a Korean application usable by German users, will require that the software operate not only in different languages, but use different input techniques, character encodings and presentation conventions.
Строка 67: Строка 50:
The following sections give some information on the status of the internationalization (i18n) support in Qt. See also the [[Qt:Документация 4.3.2/linguist-manual | Qt Linguist manual]].
The following sections give some information on the status of the internationalization (i18n) support in Qt. See also the [[Qt:Документация 4.3.2/linguist-manual | Qt Linguist manual]].
-
<div id="step-by-step"></div>
+
 
===Step by Step===
===Step by Step===
Writing cross-platform international software with Qt is a gentle, incremental process. Your software can become internationalized in the following stages:
Writing cross-platform international software with Qt is a gentle, incremental process. Your software can become internationalized in the following stages:
-
<div id="use-qstring-for-all-user-visible-text"></div>
+
 
====Use QString for All User-Visible Text====
====Use QString for All User-Visible Text====
Since [[Qt:Документация 4.3.2/qstring | QString]] uses the Unicode 4.0 encoding internally, every language in the world can be processed transparently using familiar text processing operations. Also, since all Qt functions that present text to the user take a [[Qt:Документация 4.3.2/qstring | QString]] as a parameter, there is no <tt>char *</tt> to [[Qt:Документация 4.3.2/qstring | QString]] conversion overhead.
Since [[Qt:Документация 4.3.2/qstring | QString]] uses the Unicode 4.0 encoding internally, every language in the world can be processed transparently using familiar text processing operations. Also, since all Qt functions that present text to the user take a [[Qt:Документация 4.3.2/qstring | QString]] as a parameter, there is no <tt>char *</tt> to [[Qt:Документация 4.3.2/qstring | QString]] conversion overhead.
Строка 77: Строка 60:
You're unlikely to notice that you are using Unicode; [[Qt:Документация 4.3.2/qstring | QString]], and [[Qt:Документация 4.3.2/qchar | QChar]] are just like easier versions of the crude <tt>const char *</tt> and char from traditional C.
You're unlikely to notice that you are using Unicode; [[Qt:Документация 4.3.2/qstring | QString]], and [[Qt:Документация 4.3.2/qchar | QChar]] are just like easier versions of the crude <tt>const char *</tt> and char from traditional C.
-
<div id="use-tr-for-all-literal-text"></div>
+
 
====Use tr() for All Literal Text====
====Use tr() for All Literal Text====
Wherever your program uses "quoted text" for text that will be presented to the user, ensure that it is processed by the [[Qt:Документация 4.3.2/qcoreapplication#translate | QCoreApplication::translate]]() function. Essentially all that is necessary to achieve this is to use [[Qt:Документация 4.3.2/qobject#tr | QObject::tr]](). For example, assuming the <tt>LoginWidget</tt> is a subclass of [[Qt:Документация 4.3.2/qwidget | QWidget]]:
Wherever your program uses "quoted text" for text that will be presented to the user, ensure that it is processed by the [[Qt:Документация 4.3.2/qcoreapplication#translate | QCoreApplication::translate]]() function. Essentially all that is necessary to achieve this is to use [[Qt:Документация 4.3.2/qobject#tr | QObject::tr]](). For example, assuming the <tt>LoginWidget</tt> is a subclass of [[Qt:Документация 4.3.2/qwidget | QWidget]]:
Строка 129: Строка 112:
If your source language uses characters outside Latin1, you might find [[Qt:Документация 4.3.2/qobject#trUtf8 | QObject::trUtf8]]() more convenient than [[Qt:Документация 4.3.2/qobject#tr | QObject::tr]](), as tr() depends on the [[Qt:Документация 4.3.2/qtextcodec#codecForTr | QTextCodec::codecForTr]](), which makes it more fragile than [[Qt:Документация 4.3.2/qobject#trUtf8 | QObject::trUtf8]]().
If your source language uses characters outside Latin1, you might find [[Qt:Документация 4.3.2/qobject#trUtf8 | QObject::trUtf8]]() more convenient than [[Qt:Документация 4.3.2/qobject#tr | QObject::tr]](), as tr() depends on the [[Qt:Документация 4.3.2/qtextcodec#codecForTr | QTextCodec::codecForTr]](), which makes it more fragile than [[Qt:Документация 4.3.2/qobject#trUtf8 | QObject::trUtf8]]().
-
<div id="use-qkeysequence-for-accelerator-values"></div>
+
 
====Use QKeySequence() for Accelerator Values====
====Use QKeySequence() for Accelerator Values====
Accelerator values such as Ctrl+Q or Alt+F need to be translated too. If you hardcode [[Qt:Документация 4.3.2/qt#Modifier-enum | Qt::CTRL]] + [[Qt:Документация 4.3.2/qt#Key-enum | Qt::Key_Q]] for "quit" in your application, translators won't be able to override it. The correct idiom is
Accelerator values such as Ctrl+Q or Alt+F need to be translated too. If you hardcode [[Qt:Документация 4.3.2/qt#Modifier-enum | Qt::CTRL]] + [[Qt:Документация 4.3.2/qt#Key-enum | Qt::Key_Q]] for "quit" in your application, translators won't be able to override it. The correct idiom is
<source lang="cpp-qt">    exitAct = new QAction(tr("E&amp;xit"), this);
<source lang="cpp-qt">    exitAct = new QAction(tr("E&amp;xit"), this);
-
     exitAct->setShortcut(tr("Ctrl+Q"));</source> <div id="use-qstring-arg-for-dynamic-text"></div>
+
     exitAct->setShortcut(tr("Ctrl+Q"));</source>  
====Use QString::arg() for Dynamic Text====
====Use QString::arg() for Dynamic Text====
The [[Qt:Документация 4.3.2/qstring#arg | QString::arg]]() functions offer a simple means for substituting arguments:
The [[Qt:Документация 4.3.2/qstring#arg | QString::arg]]() functions offer a simple means for substituting arguments:
Строка 152: Строка 135:
produces the correct output in English and Norwegian:
produces the correct output in English and Norwegian:
<source lang="cpp-qt"> 5 of 10 files copied. Copying: somefile.txt
<source lang="cpp-qt"> 5 of 10 files copied. Copying: somefile.txt
-
  Kopierer nu somefile.txt. Av totalt 10 filer er 5 kopiert.</source> <div id="produce-translations"></div>
+
  Kopierer nu somefile.txt. Av totalt 10 filer er 5 kopiert.</source>  
====Produce Translations====
====Produce Translations====
Once you are using tr() throughout an application, you can start producing translations of the user-visible text in your program.
Once you are using tr() throughout an application, you can start producing translations of the user-visible text in your program.
Строка 184: Строка 167:
<tt>linguist</tt>, <tt>lupdate</tt> and <tt>lrelease</tt> are installed in the <tt>bin</tt> subdirectory of the base directory Qt is installed into. Click Help|Manual in ''Qt Linguist'' to access the user's manual; it contains a tutorial to get you started.
<tt>linguist</tt>, <tt>lupdate</tt> and <tt>lrelease</tt> are installed in the <tt>bin</tt> subdirectory of the base directory Qt is installed into. Click Help|Manual in ''Qt Linguist'' to access the user's manual; it contains a tutorial to get you started.
-
<div id="qt-itself"></div>
+
 
Qt itself contains over 400 strings that will also need to be translated into the languages that you are targeting. You will find translation files for French and German in <tt>$QTDIR/translations</tt> as well as a template for translating to other languages. (This directory also contains some additional unsupported translations which may be useful.)
Qt itself contains over 400 strings that will also need to be translated into the languages that you are targeting. You will find translation files for French and German in <tt>$QTDIR/translations</tt> as well as a template for translating to other languages. (This directory also contains some additional unsupported translations which may be useful.)
Строка 202: Строка 185:
         ...
         ...
         return app.exec();
         return app.exec();
-
     }</source> <div id="support-for-encodings"></div>
+
     }</source>  
====Support for Encodings====
====Support for Encodings====
The [[Qt:Документация 4.3.2/qtextcodec | QTextCodec]] class and the facilities in [[Qt:Документация 4.3.2/qtextstream | QTextStream]] make it easy to support many input and output encodings for your users' data. When an application starts, the locale of the machine will determine the 8-bit encoding used when dealing with 8-bit data: such as for font selection, text display, 8-bit text I/O, and character input.
The [[Qt:Документация 4.3.2/qtextcodec | QTextCodec]] class and the facilities in [[Qt:Документация 4.3.2/qtextstream | QTextStream]] make it easy to support many input and output encodings for your users' data. When an application starts, the locale of the machine will determine the 8-bit encoding used when dealing with 8-bit data: such as for font selection, text display, 8-bit text I/O, and character input.
Строка 223: Строка 206:
In some cases and for less frequently used encodings it may be necessary to write your own [[Qt:Документация 4.3.2/qtextcodec | QTextCodec]] subclass. Depending on the urgency, it may be useful to contact Trolltech technical support or ask on the <tt>qt-interest</tt> mailing list to see if someone else is already working on supporting the encoding.
In some cases and for less frequently used encodings it may be necessary to write your own [[Qt:Документация 4.3.2/qtextcodec | QTextCodec]] subclass. Depending on the urgency, it may be useful to contact Trolltech technical support or ask on the <tt>qt-interest</tt> mailing list to see if someone else is already working on supporting the encoding.
-
<div id="localization"></div><div id="localize"></div>
+
 
====Localize====
====Localize====
Localization is the process of adapting to local conventions, for example presenting dates and times using the locally preferred formats. Such localizations can be accomplished using appropriate tr() strings.
Localization is the process of adapting to local conventions, for example presenting dates and times using the locally preferred formats. Such localizations can be accomplished using appropriate tr() strings.
Строка 239: Строка 222:
Localizing images is not recommended. Choose clear icons that are appropriate for all localities, rather than relying on local puns or stretched metaphors. The exception is for images of left and right pointing arrows which may need to be reversed for Arabic and Hebrew locales.
Localizing images is not recommended. Choose clear icons that are appropriate for all localities, rather than relying on local puns or stretched metaphors. The exception is for images of left and right pointing arrows which may need to be reversed for Arabic and Hebrew locales.
-
<div id="dynamic-translation"></div>
+
 
===Dynamic Translation===
===Dynamic Translation===
Some applications, such as Qt Linguist, must be able to support changes to the user's language settings while they are still running. To make widgets aware of changes to the system language, reimplement the widget's [[Qt:Документация 4.3.2/qwidget#changeEvent | changeEvent()]] function to check whether the event is a [[Qt:Документация 4.3.2/qevent#Type-enum | LanguageChange]] event, and update the text displayed by widgets using the [[Qt:Документация 4.3.2/qobject#tr | tr()]] function in the usual way. For example:
Some applications, such as Qt Linguist, must be able to support changes to the user's language settings while they are still running. To make widgets aware of changes to the system language, reimplement the widget's [[Qt:Документация 4.3.2/qwidget#changeEvent | changeEvent()]] function to check whether the event is a [[Qt:Документация 4.3.2/qevent#Type-enum | LanguageChange]] event, and update the text displayed by widgets using the [[Qt:Документация 4.3.2/qobject#tr | tr()]] function in the usual way. For example:
Строка 254: Строка 237:
The default event handler for [[Qt:Документация 4.3.2/qwidget | QWidget]] subclasses responds to the [[Qt:Документация 4.3.2/qevent#Type-enum | QEvent::LanguageChange]] event, and will call this function when necessary; other application components can also force widgets to update themselves by posting the [[Qt:Документация 4.3.2/qevent#Type-enum | LanguageChange]] event to them.
The default event handler for [[Qt:Документация 4.3.2/qwidget | QWidget]] subclasses responds to the [[Qt:Документация 4.3.2/qevent#Type-enum | QEvent::LanguageChange]] event, and will call this function when necessary; other application components can also force widgets to update themselves by posting the [[Qt:Документация 4.3.2/qevent#Type-enum | LanguageChange]] event to them.
-
<div id="translating-non-qt-classes"></div>
+
 
===Translating Non-Qt Classes===
===Translating Non-Qt Classes===
It is sometimes necessary to provide internationalization support for strings used in classes that do not inherit [[Qt:Документация 4.3.2/qobject | QObject]] or use the [[Qt:Документация 4.3.2/qobject#Q_OBJECT | Q_OBJECT]] macro to enable translation features. Since Qt translates strings at run-time based on the class they are associated with and <tt>lupdate</tt> looks for translatable strings in the source code, non-Qt classes must use mechanisms that also provide this information.
It is sometimes necessary to provide internationalization support for strings used in classes that do not inherit [[Qt:Документация 4.3.2/qobject | QObject]] or use the [[Qt:Документация 4.3.2/qobject#Q_OBJECT | Q_OBJECT]] macro to enable translation features. Since Qt translates strings at run-time based on the class they are associated with and <tt>lupdate</tt> looks for translatable strings in the source code, non-Qt classes must use mechanisms that also provide this information.
Строка 270: Строка 253:
Alternatively, the [[Qt:Документация 4.3.2/qcoreapplication#translate | QCoreApplication::translate]]() function can be called with a specific context, and this will be recognized by <tt>lupdate</tt> and Qt Linguist.
Alternatively, the [[Qt:Документация 4.3.2/qcoreapplication#translate | QCoreApplication::translate]]() function can be called with a specific context, and this will be recognized by <tt>lupdate</tt> and Qt Linguist.
-
<div id="system-support"></div>
+
 
===System Support===
===System Support===
Some of the operating systems and windowing systems that Qt runs on only have limited support for Unicode. The level of support available in the underlying system has some influence on the support that Qt can provide on those platforms, although in general Qt applications need not be too concerned with platform-specific limitations.
Some of the operating systems and windowing systems that Qt runs on only have limited support for Unicode. The level of support available in the underlying system has some influence on the support that Qt can provide on those platforms, although in general Qt applications need not be too concerned with platform-specific limitations.
-
<div id="unix-x11"></div>
+
 
====Unix/X11====
====Unix/X11====
*Locale-oriented fonts and input methods. Qt hides these and provides Unicode input and output.
*Locale-oriented fonts and input methods. Qt hides these and provides Unicode input and output.
*Filesystem conventions such as [http://www.ietf.org/rfc/rfc2279.txt UTF-8] are under development in some Unix variants. All Qt file functions allow Unicode, but convert filenames to the local 8-bit encoding, as this is the Unix convention (see [[Qt:Документация 4.3.2/qfile#setEncodingFunction | QFile::setEncodingFunction]]() to explore alternative encodings).
*Filesystem conventions such as [http://www.ietf.org/rfc/rfc2279.txt UTF-8] are under development in some Unix variants. All Qt file functions allow Unicode, but convert filenames to the local 8-bit encoding, as this is the Unix convention (see [[Qt:Документация 4.3.2/qfile#setEncodingFunction | QFile::setEncodingFunction]]() to explore alternative encodings).
*File I/O defaults to the local 8-bit encoding, with Unicode options in [[Qt:Документация 4.3.2/qtextstream | QTextStream]].
*File I/O defaults to the local 8-bit encoding, with Unicode options in [[Qt:Документация 4.3.2/qtextstream | QTextStream]].
-
<div id="windows"></div>
+
 
====Windows====
====Windows====
*Qt provides full Unicode support, including input methods, fonts, clipboard, drag-and-drop and file names.
*Qt provides full Unicode support, including input methods, fonts, clipboard, drag-and-drop and file names.
*File I/O defaults to Latin1, with Unicode options in [[Qt:Документация 4.3.2/qtextstream | QTextStream]]. Note that some Windows programs do not understand big-endian Unicode text files even though that is the order prescribed by the Unicode Standard in the absence of higher-level protocols.
*File I/O defaults to Latin1, with Unicode options in [[Qt:Документация 4.3.2/qtextstream | QTextStream]]. Note that some Windows programs do not understand big-endian Unicode text files even though that is the order prescribed by the Unicode Standard in the absence of higher-level protocols.
*Unlike programs written with MFC or plain winlib, Qt programs are portable between Windows 98 and Windows NT. ''You do not need different binaries to support Unicode.''
*Unlike programs written with MFC or plain winlib, Qt programs are portable between Windows 98 and Windows NT. ''You do not need different binaries to support Unicode.''
-
<div id="note-about-locales-on-x11"></div>
+
 
===Note about Locales on X11===
===Note about Locales on X11===
Many Unix distributions contain only partial support for some locales. For example, if you have a <tt>/usr/share/locale/ja_JP.EUC</tt> directory, this does not necessarily mean you can display Japanese text; you also need JIS encoded fonts (or Unicode fonts), and the <tt>/usr/share/locale/ja_JP.EUC</tt> directory needs to be complete. For best results, use complete locales from your system vendor.
Many Unix distributions contain only partial support for some locales. For example, if you have a <tt>/usr/share/locale/ja_JP.EUC</tt> directory, this does not necessarily mean you can display Japanese text; you also need JIS encoded fonts (or Unicode fonts), and the <tt>/usr/share/locale/ja_JP.EUC</tt> directory needs to be complete. For best results, use complete locales from your system vendor.
-
<div id="relevant-qt-classes"></div>
+
 
===Relevant Qt Classes===
===Relevant Qt Classes===
These classes are relevant to internationalizing Qt applications.
These classes are relevant to internationalizing Qt applications.

Пожалуйста, обратите внимание, что все ваши добавления могут быть отредактированы или удалены другими участниками. Если вы не хотите, чтобы кто-либо изменял ваши тексты, не помещайте их сюда.
Вы также подтверждаете, что являетесь автором вносимых дополнений, или скопировали их из источника, допускающего свободное распространение и изменение своего содержимого (см. Wiki.crossplatform.ru:Авторское право). НЕ РАЗМЕЩАЙТЕ БЕЗ РАЗРЕШЕНИЯ ОХРАНЯЕМЫЕ АВТОРСКИМ ПРАВОМ МАТЕРИАЛЫ!


Шаблоны, использованные на текущей версии страницы: