summaryrefslogtreecommitdiffstats
path: root/lib/Locale/Po4a/Chooser.pm
blob: fa96084062c58158e31815c797cf2b30c5c1cee8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# Locale::Po4a::Chooser -- Manage po4a modules
#
# This program is free software; you may redistribute it and/or modify it
# under the terms of GPL v2.0 or later (see COPYING).
#
# This module converts POD to PO file, so that it becomes possible to
# translate POD formatted documentation. See gettext documentation for
# more info about PO files.

############################################################################
# Modules and declarations
############################################################################

package Locale::Po4a::Chooser;

use 5.16.0;
use strict;
use warnings;
use Locale::Po4a::Common;

sub new {
    my ($module)  = shift;
    my (%options) = @_;

    die wrap_mod( "po4a::chooser", gettext("Please provide a module name") )
      unless defined $module;

    my $modname;
    if ( $module eq 'kernelhelp' ) {
        $modname = 'KernelHelp';
    } elsif ( $module eq 'newsdebian' ) {
        $modname = 'NewsDebian';
    } elsif ( $module eq 'latex' ) {
        $modname = 'LaTeX';
    } elsif ( $module eq 'bibtex' ) {
        $modname = 'BibTex';
    } elsif ( $module eq 'tex' ) {
        $modname = 'TeX';
    } elsif ( $module eq 'asciidoc' ) {
        $modname = 'AsciiDoc';
    } elsif ( $module eq 'Rd' || $module eq 'rubydoc' ) {
        $modname = 'RubyDoc';
    } else {
        $modname = ucfirst($module);
    }
    if ( !UNIVERSAL::can( "Locale::Po4a::$modname", 'new' ) ) {
        eval qq{use Locale::Po4a::$modname};
        if ($@) {
            my $error = $@;
            warn wrap_msg( gettext("Unknown format type: %s."), $module );
            warn wrap_mod( "po4a::chooser", gettext("Module loading error: %s"), $error )
              unless defined $options{'quiet'};
            list(1);
        }
    }
    return "Locale::Po4a::$modname"->new(%options);
}

sub list {
    warn wrap_msg(
        gettext("List of valid formats:")

          #       ."\n  - ".gettext("bibtex: BibTex bibliography format.")
          . "\n  - "
          . gettext("asciidoc: AsciiDoc format.")
          . "\n  - "
          . gettext("dia: uncompressed Dia diagrams.")
          . "\n  - "
          . gettext("docbook: DocBook XML.")
          . "\n  - "
          . gettext("guide: Gentoo Linux's XML documentation format.")
          . "\n  - "
          . gettext("ini: INI format.")
          . "\n  - "
          . gettext("kernelhelp: Help messages of each kernel compilation option.")
          . "\n  - "
          . gettext("latex: LaTeX format.")
          . "\n  - "
          . gettext("man: Good old manual page format.")
          . "\n  - "
          . gettext("pod: Perl Online Documentation format.")
          . "\n  - "
          . gettext("rubydoc: Ruby Documentation (RD) format.")
          . "\n  - "
          . gettext("sgml: either DebianDoc or DocBook DTD.")
          . "\n  - "
          . gettext("texinfo: The info page format.")
          . "\n  - "
          . gettext("tex: generic TeX documents (see also latex).")
          . "\n  - "
          . gettext("text: simple text document.")
          . "\n  - "
          . gettext("wml: WML documents.")
          . "\n  - "
          . gettext("xhtml: XHTML documents.")
          . "\n  - "
          . gettext("xml: generic XML documents (see also docbook).")
          . "\n  - "
          . gettext("yaml: YAML documents.")
    );
    exit shift;
}
##############################################################################
# Module return value and documentation
##############################################################################

1;
__END__

=encoding UTF-8

=head1 NAME

Locale::Po4a::Chooser - manage po4a modules

=head1 DESCRIPTION

Locale::Po4a::Chooser is a module to manage po4a modules. Previously, all po4a
binaries used to know all po4a modules (pod, man, sgml, etc). This made the
addition of a new module boring, because you had to make sure that the documentation is synchronized
in all modules, and that each of them can access the new module.

Now, you just have to call the Locale::Po4a::Chooser::new() function,
passing the name of module as argument.

The function Locale::Po4a::Chooser::list() lists the available
formats, and exits with the value passed as argument. So, we call
Locale::Po4a::Chooser::list(0) when requested for the list of
formats, and Locale::Po4a::Chooser::list(1) when passed an invalid
format name.

=head1 SEE ALSO

=over 4

=item About po4a:

L<Locale::Po4a::Po(3pm)>,
L<Locale::Po4a::TransTractor(3pm)>,
L<po4a(7)|po4a.7>

=item About modules:

L<Locale::Po4a::Dia(3pm)>,
L<Locale::Po4a::Docbook(3pm)>,
L<Locale::Po4a::Guide(3pm)>,
L<Locale::Po4a::Halibut(3pm)>,
L<Locale::Po4a::Ini(3pm)>,
L<Locale::Po4a::KernelHelp(3pm)>,
L<Locale::Po4a::LaTeX(3pm)>,
L<Locale::Po4a::Man(3pm)>,
L<Locale::Po4a::Pod(3pm)>,
L<Locale::Po4a::RubyDoc(3pm)>,
L<Locale::Po4a::Sgml(3pm)>,
L<Locale::Po4a::TeX(3pm)>,
L<Locale::Po4a::Texinfo(3pm)>,
L<Locale::Po4a::Text(3pm)>,
L<Locale::Po4a::Wml(3pm)>.
L<Locale::Po4a::Xhtml(3pm)>,
L<Locale::Po4a::Xml(3pm)>,
L<Locale::Po4a::Wml(3pm)>,
L<Locale::Po4a::Yaml(3pm)>.

=back

=head1 AUTHORS

 Denis Barbier <barbier@linuxfr.org>
 Martin Quinson (mquinson#debian.org)

=head1 COPYRIGHT AND LICENSE

Copyright © 2002-2005, 2014, 2017 SPI, Inc.

This program is free software; you may redistribute it and/or modify it
under the terms of GPL v2.0 or later (see the COPYING file).

=cut