nonenglish.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: nonenglish.h
  3. // Purpose: topic overview
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @page overview_nonenglish Writing Non-English Applications
  9. @tableofcontents
  10. This article describes how to write applications that communicate with the user
  11. in a language other than English. Unfortunately many languages use different
  12. charsets under Unix and Windows (and other platforms, to make the situation
  13. even more complicated). These charsets usually differ in so many characters
  14. that it is impossible to use the same texts under all platforms.
  15. The wxWidgets library provides a mechanism that helps you avoid distributing
  16. many identical, only differently encoded, packages with your application (e.g.
  17. help files and menu items in iso8859-13 and windows-1257). Thanks to this
  18. mechanism you can, for example, distribute only iso8859-13 data and it will be
  19. handled transparently under all systems.
  20. Please read the @ref overview_i18n which describes the locales concept.
  21. In the following text, wherever @e iso8859-2 and @e windows-1250 are used, any
  22. encodings are meant and any encodings may be substituted there.
  23. @section overview_nonenglish_locales Locales
  24. The best way to ensure correctly displayed texts in a GUI across platforms is
  25. to use locales. Write your in-code messages in English or without diacritics
  26. and put real messages into the message catalog (see @ref overview_i18n).
  27. A standard .po file begins with a header like this:
  28. @code
  29. # SOME DESCRIPTIVE TITLE.
  30. # Copyright (C) YEAR Free Software Foundation, Inc.
  31. # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
  32. #
  33. msgid ""
  34. msgstr ""
  35. "Project-Id-Version: PACKAGE VERSION\n"
  36. "POT-Creation-Date: 1999-02-19 16:03+0100\n"
  37. "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
  38. "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
  39. "Language-Team: LANGUAGE <LL@li.org>\n"
  40. "MIME-Version: 1.0\n"
  41. "Content-Type: text/plain; charset=CHARSET\n"
  42. "Content-Transfer-Encoding: ENCODING\n"
  43. @endcode
  44. Note this particular line:
  45. @code
  46. "Content-Type: text/plain; charset=CHARSET\n"
  47. @endcode
  48. It specifies the charset used by the catalog. All strings in the catalog are
  49. encoded using this charset.
  50. You have to fill in proper charset information. Your .po file may look like
  51. this after doing so:
  52. @code
  53. # SOME DESCRIPTIVE TITLE.
  54. # Copyright (C) YEAR Free Software Foundation, Inc.
  55. # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
  56. #
  57. msgid ""
  58. msgstr ""
  59. "Project-Id-Version: PACKAGE VERSION\n"
  60. "POT-Creation-Date: 1999-02-19 16:03+0100\n"
  61. "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
  62. "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
  63. "Language-Team: LANGUAGE <LL@li.org>\n"
  64. "MIME-Version: 1.0\n"
  65. "Content-Type: text/plain; charset=iso8859-2\n"
  66. "Content-Transfer-Encoding: 8bit\n"
  67. @endcode
  68. (Make sure that the header is @b not marked as @e fuzzy.)
  69. wxWidgets is able to use this catalog under any supported platform
  70. (although iso8859-2 is a Unix encoding and is normally not understood by
  71. Windows).
  72. How is this done? When you tell the wxLocale class to load a message catalog
  73. that contains a correct header, it checks the charset. The catalog is then
  74. converted to the charset used (see wxLocale::GetSystemEncoding and
  75. wxLocale::GetSystemEncodingName) by the user's operating system.
  76. @section overview_nonenglish_strings Non-English Strings or 8-bit Characters in Source
  77. By convention, you should only use characters without diacritics (i.e. 7-bit
  78. ASCII strings) for msgids in the source code and write them in English.
  79. If you port software to wxWidgets, you may be confronted with legacy source
  80. code containing non-English string literals. Instead of translating the strings
  81. in the source code to English and putting the original strings into message
  82. catalog, you may configure wxWidgets to use non-English msgids and translate to
  83. English using message catalogs:
  84. @li If you use the program @c xgettext to extract the strings from the source
  85. code, specify the option <tt>--from-code=@<source code charset@></tt>.
  86. @li Specify the source code language and charset as arguments to
  87. wxLocale::AddCatalog. For example:
  88. @code
  89. locale.AddCatalog(wxT("myapp"), wxLANGUAGE_GERMAN, wxT("iso-8859-1"));
  90. @endcode
  91. @section overview_nonenglish_fontmapping Font Mapping
  92. You can use @ref overview_mbconv and wxFontMapper to display text:
  93. @code
  94. if (!wxFontMapper::Get()->IsEncodingAvailable(enc, facename))
  95. {
  96. wxFontEncoding alternative;
  97. if (wxFontMapper::Get()->GetAltForEncoding(enc, &alternative,
  98. facename, false))
  99. {
  100. wxCSConv convFrom(wxFontMapper::Get()->GetEncodingName(enc));
  101. wxCSConv convTo(wxFontMapper::Get()->GetEncodingName(alternative));
  102. text = wxString(text.mb_str(convFrom), convTo);
  103. }
  104. else
  105. ...failure (or we may try iso8859-1/7bit ASCII)...
  106. }
  107. ...display text...
  108. @endcode
  109. @section overview_nonenglish_converting Converting Data
  110. You may want to store all program data (created documents etc.) in the same
  111. encoding, let's say @c utf-8. You can use wxCSConv to convert data to the
  112. encoding used by the system your application is running on (see
  113. wxLocale::GetSystemEncoding).
  114. @section overview_nonenglish_help Help Files
  115. If you're using wxHtmlHelpController there is no problem at all. You only need
  116. to make sure that all the HTML files contain the META tag:
  117. @code
  118. <meta http-equiv="Content-Type" content="text/html; charset=iso8859-2">
  119. @endcode
  120. Also, the hhp project file needs one additional line in the @c OPTIONS section:
  121. @code
  122. Charset=iso8859-2
  123. @endcode
  124. This additional entry tells the HTML help controller what encoding is used in
  125. contents and index tables.
  126. */