perl / Git / I18N.pmon commit Merge branch 'jz/gitweb-conf-doc-fix' into maint (1c30f8e)
   1package Git::I18N;
   2use 5.008;
   3use strict;
   4use warnings;
   5BEGIN {
   6        require Exporter;
   7        if ($] < 5.008003) {
   8                *import = \&Exporter::import;
   9        } else {
  10                # Exporter 5.57 which supports this invocation was
  11                # released with perl 5.8.3
  12                Exporter->import('import');
  13        }
  14}
  15
  16our @EXPORT = qw(__);
  17our @EXPORT_OK = @EXPORT;
  18
  19sub __bootstrap_locale_messages {
  20        our $TEXTDOMAIN = 'git';
  21        our $TEXTDOMAINDIR = $ENV{GIT_TEXTDOMAINDIR} || '++LOCALEDIR++';
  22
  23        require POSIX;
  24        POSIX->import(qw(setlocale));
  25        # Non-core prerequisite module
  26        require Locale::Messages;
  27        Locale::Messages->import(qw(:locale_h :libintl_h));
  28
  29        setlocale(LC_MESSAGES(), '');
  30        setlocale(LC_CTYPE(), '');
  31        textdomain($TEXTDOMAIN);
  32        bindtextdomain($TEXTDOMAIN => $TEXTDOMAINDIR);
  33
  34        return;
  35}
  36
  37BEGIN
  38{
  39        # Used by our test script to see if it should test fallbacks or
  40        # not.
  41        our $__HAS_LIBRARY = 1;
  42
  43        local $@;
  44        eval {
  45                __bootstrap_locale_messages();
  46                *__ = \&Locale::Messages::gettext;
  47                1;
  48        } or do {
  49                # Tell test.pl that we couldn't load the gettext library.
  50                $Git::I18N::__HAS_LIBRARY = 0;
  51
  52                # Just a fall-through no-op
  53                *__ = sub ($) { $_[0] };
  54        };
  55}
  56
  571;
  58
  59__END__
  60
  61=head1 NAME
  62
  63Git::I18N - Perl interface to Git's Gettext localizations
  64
  65=head1 SYNOPSIS
  66
  67        use Git::I18N;
  68
  69        print __("Welcome to Git!\n");
  70
  71        printf __("The following error occurred: %s\n"), $error;
  72
  73=head1 DESCRIPTION
  74
  75Git's internal Perl interface to gettext via L<Locale::Messages>. If
  76L<Locale::Messages> can't be loaded (it's not a core module) we
  77provide stub passthrough fallbacks.
  78
  79This is a distilled interface to gettext, see C<info '(gettext)Perl'>
  80for the full interface. This module implements only a small part of
  81it.
  82
  83=head1 FUNCTIONS
  84
  85=head2 __($)
  86
  87L<Locale::Messages>'s gettext function if all goes well, otherwise our
  88passthrough fallback function.
  89
  90=head1 AUTHOR
  91
  92E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avarab@gmail.com>
  93
  94=head1 COPYRIGHT
  95
  96Copyright 2010 E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avarab@gmail.com>
  97
  98=cut