Gettext.pm 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. # Copied from /usr/share/perl5/Debconf/Gettext.pm
  2. #
  3. # Redistribution and use in source and binary forms, with or without
  4. # modification, are permitted provided that the following conditions
  5. # are met:
  6. # 1. Redistributions of source code must retain the above copyright
  7. # notice, this list of conditions and the following disclaimer.
  8. # 2. Redistributions in binary form must reproduce the above copyright
  9. # notice, this list of conditions and the following disclaimer in the
  10. # documentation and/or other materials provided with the distribution.
  11. #
  12. # THIS SOFTWARE IS PROVIDED BY AUTHORS AND CONTRIBUTORS ``AS IS'' AND
  13. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  14. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  15. # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
  16. # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  17. # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  18. # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  19. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  20. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  21. # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  22. # SUCH DAMAGE.
  23. package Dpkg::Gettext;
  24. use strict;
  25. use warnings;
  26. our $VERSION = '1.00';
  27. =encoding utf8
  28. =head1 NAME
  29. Dpkg::Gettext - convenience wrapper around Locale::gettext
  30. =head1 DESCRIPTION
  31. The Dpkg::Gettext module is a convenience wrapper over the Locale::gettext
  32. module, to guarantee we always have working gettext functions, and to add
  33. some commonly used aliases.
  34. =head1 FUNCTIONS
  35. =over 4
  36. =item my $trans = _g($msgid)
  37. Calls gettext() on the $msgid and returns its translation for the current
  38. locale. If gettext() is not available, simply returns $msgid.
  39. =item my $trans = P_($msgid, $msgid_plural, $n)
  40. Calls ngettext(), returning the correct translation for the plural form
  41. dependent on $n. If gettext() is not available, returns $msgid if $n is 1
  42. or $msgid_plural otherwise.
  43. =back
  44. =cut
  45. BEGIN {
  46. eval 'use Locale::gettext';
  47. if ($@) {
  48. eval q{
  49. sub _g {
  50. return shift;
  51. }
  52. sub textdomain {
  53. }
  54. sub ngettext {
  55. my ($msgid, $msgid_plural, $n) = @_;
  56. if ($n == 1) {
  57. return $msgid;
  58. } else {
  59. return $msgid_plural;
  60. }
  61. }
  62. sub P_ {
  63. return ngettext(@_);
  64. }
  65. };
  66. } else {
  67. eval q{
  68. sub _g {
  69. return gettext(shift);
  70. }
  71. sub P_ {
  72. return ngettext(@_);
  73. }
  74. };
  75. }
  76. }
  77. use Exporter qw(import);
  78. our @EXPORT=qw(_g P_ textdomain ngettext);
  79. =head1 CHANGES
  80. =head2 Version 1.00
  81. Mark the module as public.
  82. =cut
  83. 1;