README 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. README for libintl-perl
  2. =======================
  3. $Id: README,v 1.1 2009-11-01 18:59:59 pertusus Exp $
  4. The package libintl-perl is an internationalization library for Perl
  5. that aims to be compatible with the Uniforum message translations
  6. system as implemented for example in GNU gettext.
  7. [NOTE for distributors: This file and the complete subdirectory
  8. "sample" of this release should be installed along with the library
  9. itself in the according documentation section!]
  10. See the file COPYING.LESSER and the source code for licensing.
  11. More extensive information may be available at the libintl-perl homepage
  12. on the internet http://guido-flohr.net/projects/libintl-perl.
  13. Requirements
  14. ------------
  15. The library is entirely written in Perl. It should run on every
  16. system with a Perl5 interpreter. The minimum required Perl version
  17. should be 5.004.
  18. The behavior of the package varies a little depending on the Perl
  19. version:
  20. - Perl 5.8 or better
  21. Recommended. Perl 5.8 offers maximum performance and support for
  22. various multi-byte encodings (even more if Encode::Han is installed).
  23. Additionally the output charset is chosen automatically according to
  24. the information provided by I18N::Langinfo. In fact, I18N::Langinfo
  25. is already available for Perl 5.7 but this developer version is
  26. probably not much in use any more.
  27. - Perl 5.6 or better
  28. Still offers high-performance UTF-8 handling but no support for other
  29. multi-byte encodings unless the package Encode is installed.
  30. - Earlier Perl versions
  31. Full UTF-8 support but quiet slow since all conversion routines are
  32. written in Perl. More exactly: Encoding from 8 bit charsets into
  33. UTF-8 is reasonably fast and usable. Decoding UTF-8 is slow, however.
  34. Note that these are actually the requirements for the *users* of your
  35. software internationalized with libintl-perl.
  36. As a maintainer of a Perl package that uses libintl-perl, you will
  37. also need a recent version of GNU gettext (see the file README in the
  38. subdirectory "sample/" of the source distribution of libintl-perl).
  39. Translators of your software can basically do their job with any text
  40. editor, but it usually makes sense for them, too, to have GNU gettext
  41. installed. End users of your software, or people that install an
  42. internationalized Perl package do *not* need it, unless they want to
  43. add a new language to your software.
  44. Installation
  45. ------------
  46. If libintl-perl is not installed on your system, you have to build it
  47. from the sources, which is a lot easier than you may think. You need
  48. the program "make" for that and a command line shell. No C compiler is
  49. required.
  50. Unpack the package in a directory of your choice, cd into that
  51. directory and then type
  52. perl Makefile.PL
  53. make
  54. This will build the package. You can then run the tests with
  55. make test
  56. To install the package, type
  57. make install
  58. You will probably need root permissions to do that.
  59. Of course, you can also use the CPAN module to install the package.
  60. Feedback
  61. --------
  62. Send negative (and positive!) feedback to me. Bug reports can be send
  63. directly to me or you can use the bugtracking system at http://rt.cpan.org/.
  64. If you use libintl-perl for your project, private or public, free or
  65. commercial, please let me know. I am interested in such information.
  66. If you really like (or dislike?) libintl-perl, tell the world about. You
  67. can rate it and even write a review at http://cpanratings.perl.org/
  68. (search for "libintl-perl"). You can also increase the popularity index of
  69. libintl-perl at freshmeat.net by visiting its project page at
  70. http://freshmeat.net/projects/libintl-perl, by subscribing to new
  71. releases from the project page, or by rating it.
  72. Design Goals
  73. ------------
  74. The primary design goal of libintl-perl is maximum compatibility with
  75. the gettext functions available for other programming languages. It
  76. is intended that programmers, translators, and end users can fully
  77. benefit from all existing i18n tools like xgettext for message
  78. extraction, msgfmt, msgmerge, etc. for catalog manipulation, Emacs PO
  79. mode (or KBabel, PO-Edit, ...) for catalog editing and so on.
  80. Another design goal is maximum portability. The library should be
  81. functional without any additional software but with a wide range of
  82. Perl versions. Wherever possible, hooks have been inserted to benefit
  83. from advanced features in the runtime environment, but the basic
  84. functionality should be present everywhere.
  85. Overview
  86. --------
  87. The core of the library is the module Locale::gettext_pp. It is a
  88. pure Perl re-implementation of the module Locale::gettext available on
  89. CPAN. However, the XS version Locale::gettext lacks some functions
  90. (notably plural handling and output conversion) that are already
  91. present in Locale::gettext_pp. Locale::gettext_pp provides the
  92. internationalization functions that are available in your system
  93. library (libc) or additional C libraries (for example libintl in the
  94. case of GNU gettext).
  95. The class Locale::Messages is an additional abstraction layer that is
  96. prepared for dynamic switching between different gettext implementations (for
  97. example Locale::gettext_pp and Locale::gettext). It provides
  98. basically the same interface as Locale::gettext_pp but in an
  99. implementation-independent manner.
  100. The module Locale::TextDomain is the only module that you should
  101. actually use in your software. It represents the message translation
  102. system for a particular text domain (a text domain is a unique
  103. identifier for your software package), makes use of Locale::Messages
  104. for message translation and catalog location, and it provides
  105. additional utility functions, for example common shortcut names for
  106. i18n routines, tied hashes for hash-like lookups into the translation
  107. database, and finally an interpolation mechanism suitable for
  108. internationalized messages.
  109. The package also contains a charset conversion library
  110. Locale::Recode. This library is used internally by Locale::gettext_pp
  111. to allow on-the-fly charset conversion between the charset in a
  112. message catalog and the preferred (end) user charset. Its main
  113. advantage about the Encode package available for recent Perl versions
  114. is its portability, since it does not require the Unicode capabilities
  115. of Perl that were introduced with Perl 5.6. It fully supports UTF-8
  116. with every Perl version and a wealth of common 8 bit encodings. If
  117. you have to do charset conversion with older Perl versions, then
  118. Locale::Recode may be worth a try although it is really only a helper
  119. library, not intended as a competitor to Encode.
  120. Documentation
  121. -------------
  122. For a basic understanding of message translation in Perl with
  123. libintl-perl you should read the perldoc of Locale::TextDomain. Don't
  124. bother about the documentation of the other modules in the library,
  125. you will not need it unless you want to hack the library yourself.
  126. There is a mailing list <libintl-perl AT imperia DOT net> (replace
  127. " AT " with "@" and " DOT " with ".") where you can post questions
  128. related to libintl-perl. The list has also a certain focus on
  129. internationalization of Perl CGI web applications. Please note, that
  130. postings from non-subscribers will be held back for approval, and it
  131. may take a considerable amount of time until all list members will get
  132. these postings. You can subscribe to the list via a web interface at
  133. http://ml.imperia.org/mailman/listinfo/libintl-perl/, a searchable
  134. archive of prior postings to the list is available at
  135. http://ml.imperia.org/libintl-perl/.
  136. At the time of this writing (July 2003) the list is new and has
  137. exactly one subscriber and zero postings. But don't be shy, join
  138. it. ;-)
  139. In order to make use of the software, you will also need various tools
  140. from GNU gettext (http://savannah.gnu.org/projects/gettext/). The
  141. documentation is located at http://www.gnu.org/manual/gettext/.
  142. You will find there a language-independent overview of
  143. internationalization with GNU gettext, and in the Perl-specific
  144. sections you will find details about the parser that extracts
  145. translatable messages from your Perl sources.
  146. Quick-Start
  147. -----------
  148. The subdirectory "sample" of the source distribution of libintl-perl
  149. contains a full-fledged example for an internationalized Perl package,
  150. including a working Makefile. The README of that subdirectory
  151. explains all necessary steps.
  152. However, if you are on a recent GNU/Linux system or similar (cygwin
  153. should also do), chances are that you can get the following example to
  154. run:
  155. #! /usr/local/bin/perl -w
  156. use strict;
  157. # This assumes that the textdomain 'libc' is available on your
  158. # system. Try "locate libc.mo" or "locate libc.gmo" (or
  159. # "find / -type f -name libc.mo" if locate is not available on
  160. # your system).
  161. #
  162. # By the way, the "use Locale::TextDomain (TEXTDOMAIN) is the
  163. # equivalent of
  164. #
  165. # textdomain ("TEXTDOMAIN");
  166. #
  167. # in C or similar languages.
  168. use Locale::TextDomain ('libc');
  169. # The locale category LC_MESSAGES is not exported by the POSIX
  170. # module on older Perl versions.
  171. use Locale::Messages qw (LC_MESSAGES);
  172. use POSIX ('setlocale');
  173. # Set the locale according to our environment.
  174. setlocale (LC_MESSAGES, '');
  175. # This makes the assumption that your system libc defines a
  176. # message "No such file or directory". Check the exact
  177. # spelling on your system with something like
  178. # "ls NON-EXISTANT".
  179. # Note the double underscore in front of the string. This is
  180. # really a function call to the function __() that is
  181. # automagically imported by Locale::TextDomain into your
  182. # namespace. This function takes its argument, looks up a
  183. # translation for it, and returns that, or the unmodified
  184. # string in case of failure.
  185. print __"No such file or directory", ".\n";
  186. __END__
  187. Now run the command "locale -a" or "nlsinfo" to get a list of
  188. available locales on your system. Try the section "Finding locales"
  189. in "perldoc perllocale" if you have problems.
  190. If, for example, the locale "fr_FR" is available on your system, set
  191. the environment variable LANG to that value, for a POSIX shell
  192. LANG=fr_FR
  193. export LANG
  194. for the C shell
  195. setenv LANG fr_FR
  196. and run your little Perl script. It should tell you what the error
  197. message for "No such file or directory" is in French, or whatever
  198. language you chose. Not a real example, because we have "stolen" a
  199. message from a system catalog. But it should give you the general
  200. idea, especially if you are already familiar with gettext in C.
  201. If you still see the English message, this does not necessarily mean a
  202. failure, since the string is maybe not translated on your system (try
  203. "locate libc.mo" to get a list of available translations). Even for
  204. the translations listed there, that particular message might be
  205. missing. Try a common locale like "de_DE" or "fr_FR" that are usually
  206. fully translated then.
  207. Your next steps should be "perldoc Locale::TextDomain", and then study
  208. the example in the subdirectory "sample" of this distribution.
  209. Have fun with libintl-perl!
  210. Guido Flohr