1Template::Multilingual:U:sPearrsCeorn(t3r)ibuted Perl DoTceummpelnattaet:i:oMnultilingual::Parser(3)
2
3
4

NAME

6       Template::Multilingual::Parser - Multilingual template parser
7

SYNOPSIS

9           use Template;
10           use Template::Multilingual::Parser;
11
12           my $parser = Template::Multilingual::Parser->new();
13           my $template = Template->new(PARSER => $parser);
14           $template->process('example.ttml', { language => 'en'});
15

DESCRIPTION

17       This subclass of Template Toolkit's "Template::Parser" parses
18       multilingual templates: templates that contain text in several
19       languages.
20
21           <t>
22             <en>Hello!</en>
23             <fr>Bonjour !</fr>
24           </t>
25
26       Use this module directly if you have subclassed "Template", otherwise
27       you may find it easier to use "Template::Multilingual".
28
29       Language codes can be any string that matches "\w+", but we suggest
30       sticking to ISO-639 which provides 2-letter codes for common languages
31       and 3-letter codes for many others.
32

METHODS

34   new(\%params)
35       The new() constructor creates and returns a reference to a new parser
36       object. A reference to a hash may be supplied as a parameter to provide
37       configuration values.
38
39       Parser objects are typically provided as the "PARSER" option to the
40       "Template" constructor.
41
42       Configuration values are all valid "Template::Parser" superclass
43       options, and one specific to this class:
44
45       LANGUAGE_VAR
46           The LANGUAGE_VAR option can be used to set the name of the template
47           variable which contains the current language. Defaults to language.
48
49             my $parser = Template::Multilingual::Parser->new({
50                LANGUAGE_VAR => 'global.language',
51             });
52
53           You will need to set this variable with the current language value
54           at request time, usually in your "Template" subclass' process()
55           method.
56
57   parse($text)
58       parse() is called by the Template Toolkit. It parses multilingual
59       sections from the input text and translates them to Template Toolkit
60       directives. The result is then passed to the "Template::Parser"
61       superclass.
62
63   sections
64       Returns a reference to an array of tokenized sections. Each section is
65       a reference to hash with either a "nolang" key or a "lang" key.
66
67       A "nolang" key denotes text outside of any multilingual sections. The
68       value is the text itself.
69
70       A "lang" key denotes text inside a multilingual section. The value is a
71       reference to a hash, whose keys are language codes and values the
72       corresponding text. For example, the following multilingual template:
73
74         foo <t><fr>bonjour</fr><en>Hello</en></t> bar
75
76       will parse to the following sections:
77
78         [ { nolang => 'foo ' },
79           {   lang => { fr => 'bonjour', en => 'hello' } },
80           { nolang => ' bar' },
81         ]
82

LANGUAGE SUBTAG HANDLING

84       This module supports language subtags to express variants, e.g. "en_US"
85       or "en-US".  Here are the rules used for language matching:
86
87       •   Exact match: the current language is found in the template
88
89             language    template                              output
90             fr          <fr>foo</fr><fr_CA>bar</fr_CA>        foo
91             fr_CA       <fr>foo</fr><fr_CA>bar</fr_CA>        bar
92
93       •   Fallback to the primary language
94
95             language    template                              output
96             fr_CA       <fr>foo</fr><fr_BE>bar</fr_BE>        foo
97
98       •   Fallback to first (in alphabetical order) other variant of the
99           primary language
100
101             language    template                              output
102             fr          <fr_FR>foo</fr_FR><fr_BE>bar</fr_BE>  bar
103             fr_CA       <fr_FR>foo</fr_FR><fr_BE>bar</fr_BE>  bar
104

AUTHOR

106       Eric Cholet, "<cholet@logilune.com>"
107

BUGS

109       Multilingual text sections cannot be used inside TT directives.  The
110       following is illegal and will trigger a TT syntax error:
111
112           [% title = "<t><fr>Bonjour</fr><en>Hello</en></t>" %]
113
114       Use this instead:
115
116           [% title = BLOCK %]<t><fr>Bonjour</fr><en>Hello</en></t>[% END %]
117
118       The TAG_STYLE, START_TAG and END_TAG directives are supported, but the
119       TAGS directive is not.
120
121       Please report any bugs or feature requests to
122       "bug-template-multilingual@rt.cpan.org", or through the web interface
123       at
124       <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Template-Multilingual>.
125       I will be notified, and then you'll automatically be notified of
126       progress on your bug as I make changes.
127

SEE ALSO

129       Template::Multilingual
130
131       ISO 639-2 Codes for the Representation of Names of Languages:
132       http://www.loc.gov/standards/iso639-2/langcodes.html
133
135       Copyright 2009 Eric Cholet, All Rights Reserved.
136
137       This program is free software; you can redistribute it and/or modify it
138       under the same terms as Perl itself.
139
140
141
142perl v5.36.0                      2023-01-20 Template::Multilingual::Parser(3)
Impressum