internationalization.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: internationalization.h
  3. // Purpose: topic overview
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @page overview_i18n Internationalization
  9. @tableofcontents
  10. Although internationalization of an application (i18n for short) involves far
  11. more than just translating its text messages to another message - date, time
  12. and currency formats need changing too, some languages are written left to
  13. right and others right to left, character encoding may differ and many other
  14. things may need changing too - it is a necessary first step. wxWidgets provides
  15. facilities for message translation with its wxLocale class and is itself fully
  16. translated into several languages. Please consult wxWidgets home page for the
  17. most up-to-date translations - and if you translate it into one of the
  18. languages not done yet, your translations would be gratefully accepted for
  19. inclusion into future versions of the library!
  20. The wxWidgets approach to i18n closely follows the GNU gettext package.
  21. wxWidgets uses the message catalogs which are binary compatible with gettext
  22. catalogs and this allows to use all of the programs in this package to work
  23. with them. But note that no additional libraries are needed during run-time,
  24. however, so you have only the message catalogs to distribute and nothing else.
  25. During program development you will need the gettext package for working with
  26. message catalogs. @b Warning: gettext versions @< 0.10 are known to be buggy,
  27. so you should find a later version of it!
  28. There are two kinds of message catalogs: source catalogs which are text files
  29. with extension .po and binary catalogs which are created from the source ones
  30. with @e msgfmt program (part of gettext package) and have the extension .mo.
  31. Only the binary files are needed during program execution.
  32. Translating your application involves several steps:
  33. @li Translating the strings in the program text using wxGetTranslation or
  34. equivalently the @c _() macro.
  35. @li Extracting the strings to be translated from the program: this uses the
  36. work done in the previous step because @c xgettext program used for string
  37. extraction recognises the standard @c _() as well as (using its @c -k
  38. option) our wxGetTranslation and extracts all strings inside the calls to
  39. these functions. Alternatively, you may use @c -a option to extract all the
  40. strings, but it will usually result in many strings being found which don't
  41. have to be translated at all. This will create a text message catalog - a
  42. .po file.
  43. @li Translating the strings extracted in the previous step to other
  44. language(s). It involves editing the .po file.
  45. @li Compiling the .po file into .mo file to be used by the program.
  46. @li Installing the .mo files with your application in the appropriate location
  47. for the target system (@see overview_i18n_mofiles).
  48. @li Setting the appropriate locale in your program to use the strings for the
  49. given language: see wxLocale.
  50. @section overview_i18n_mofiles Installing translation catalogs
  51. The .mo files with compiled catalogs must be included with the application.
  52. By default, wxFileTranslationsLoader is used to load them from files installed
  53. alongside the application (although you could use wxResourceTranslationsLoader
  54. or some custom loader too).
  55. The files are expected to be in the resources directory (as returned by
  56. wxStandardPaths::GetLocalizedResourcesDir(wxStandardPaths::ResourceCat_Messages).
  57. If the message catalogs are not installed in this default location you may
  58. explicitly use wxFileTranslationsLoader::AddCatalogLookupPathPrefix() to still
  59. allow wxWidgets to find them, but it is recommended to use the default
  60. locations when possible.
  61. Depending on the platform, the default location differs. On Windows, it is
  62. alongside the executable. On Unix, translations are expected to be in
  63. "$prefix/share/locale". On OS X, application bundle's @em Resources subdirectory
  64. is used.
  65. In all cases, translations are searched for in subdirectories named using the
  66. languages codes from ISO 639. The .mo file(s) should be located either directly
  67. in that directory or in LC_MESSAGES subdirectory. On OS X, ".lproj" extension
  68. is used for the per-languages Resources subdirectories.
  69. Here's how an app would typically install the files on Unix:
  70. @code
  71. /usr/bin/myapp
  72. /usr/share/locale/de/LC_MESSAGES/myapp.mo
  73. /usr/share/locale/fr/LC_MESSAGES/myapp.mo
  74. @endcode
  75. And on OS X:
  76. @code
  77. MyApp.app/Contents/MacOS/MyApp
  78. MyApp.app/Contents/Resources/de.lproj/myapp.mo
  79. MyApp.app/Contents/Resources/fr.lproj/myapp.mo
  80. @endcode
  81. And on Windows:
  82. @code
  83. C:\Program Files\MyApp\myapp.exe
  84. C:\Program Files\MyApp\de\myapp.mo
  85. C:\Program Files\MyApp\fr\myapp.mo
  86. @endcode
  87. It is of course possible to use the Unix layout everywhere instead.
  88. @section overview_i18n_menuaccel Translating Menu Accelerators
  89. If you translate the accelerator modifier names (Ctrl, Alt and Shift) in your
  90. menu labels, you may find the accelerators no longer work. In your message
  91. catalogs, you need to provide individual translations of these modifiers from
  92. their lower case names (ctrl, alt, shift) so that the wxWidgets accelerator
  93. code can recognise them even when translated. wxWidgets does not provide
  94. translations for all of these currently. wxWidgets does not yet handle
  95. translated special key names such as Backspace, End, Insert, etc.
  96. @see
  97. @li The gettext Manual: http://www.gnu.org/software/gettext/manual/gettext.html
  98. @li @ref overview_nonenglish - It focuses on handling charsets related problems.
  99. @li @ref page_samples_internat - Shows you how all this looks in practice.
  100. */