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