]> git.ipfire.org Git - thirdparty/git.git/blame_incremental - perl/Git/I18N.pm
Merge branch 'la/strvec-comment-fix' into maint-2.43
[thirdparty/git.git] / perl / Git / I18N.pm
... / ...
CommitLineData
1package Git::I18N;
2use 5.008001;
3use strict;
4use warnings $ENV{GIT_PERL_FATAL_WARNINGS} ? qw(FATAL all) : ();
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(__ __n N__);
17our @EXPORT_OK = @EXPORT;
18
19# See Git::LoadCPAN's NO_PERL_CPAN_FALLBACKS_STR for a description of
20# this "'@@' [...] '@@'" pattern.
21use constant NO_GETTEXT_STR => '@@' . 'NO_GETTEXT' . '@@';
22use constant NO_GETTEXT => (
23 q[@@NO_GETTEXT@@] ne ''
24 and
25 q[@@NO_GETTEXT@@] ne NO_GETTEXT_STR
26);
27
28sub __bootstrap_locale_messages {
29 our $TEXTDOMAIN = 'git';
30 our $TEXTDOMAINDIR ||= $ENV{GIT_TEXTDOMAINDIR} || '@@LOCALEDIR@@';
31 die "NO_GETTEXT=" . NO_GETTEXT_STR if NO_GETTEXT;
32
33 require POSIX;
34 POSIX->import(qw(setlocale));
35 # Non-core prerequisite module
36 require Locale::Messages;
37 Locale::Messages->import(qw(:locale_h :libintl_h));
38
39 setlocale(LC_MESSAGES(), '');
40 setlocale(LC_CTYPE(), '');
41 textdomain($TEXTDOMAIN);
42 bindtextdomain($TEXTDOMAIN => $TEXTDOMAINDIR);
43
44 return;
45}
46
47BEGIN
48{
49 # Used by our test script to see if it should test fallbacks or
50 # not.
51 our $__HAS_LIBRARY = 1;
52
53 local $@;
54 eval {
55 __bootstrap_locale_messages();
56 *__ = \&Locale::Messages::gettext;
57 *__n = \&Locale::Messages::ngettext;
58 1;
59 } or do {
60 # Tell test.pl that we couldn't load the gettext library.
61 $Git::I18N::__HAS_LIBRARY = 0;
62
63 # Just a fall-through no-op
64 *__ = sub ($) { $_[0] };
65 *__n = sub ($$$) { $_[2] == 1 ? $_[0] : $_[1] };
66 };
67
68 sub N__($) { return shift; }
69}
70
711;
72
73__END__
74
75=head1 NAME
76
77Git::I18N - Perl interface to Git's Gettext localizations
78
79=head1 SYNOPSIS
80
81 use Git::I18N;
82
83 print __("Welcome to Git!\n");
84
85 printf __("The following error occurred: %s\n"), $error;
86
87 printf __n("committed %d file\n", "committed %d files\n", $files), $files;
88
89
90=head1 DESCRIPTION
91
92Git's internal Perl interface to gettext via L<Locale::Messages>. If
93L<Locale::Messages> can't be loaded (it's not a core module) we
94provide stub passthrough fallbacks.
95
96This is a distilled interface to gettext, see C<info '(gettext)Perl'>
97for the full interface. This module implements only a small part of
98it.
99
100=head1 FUNCTIONS
101
102=head2 __($)
103
104L<Locale::Messages>'s gettext function if all goes well, otherwise our
105passthrough fallback function.
106
107=head2 __n($$$)
108
109L<Locale::Messages>'s ngettext function or passthrough fallback function.
110
111=head2 N__($)
112
113No-operation that only returns its argument. Use this if you want xgettext to
114extract the text to the pot template but do not want to trigger retrival of the
115translation at run time.
116
117=head1 AUTHOR
118
119E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avarab@gmail.com>
120
121=head1 COPYRIGHT
122
123Copyright 2010 E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avarab@gmail.com>
124
125=cut