1Locale::TextDomain::OO:U:sJearvaCSocnrtirpitb(u3t)ed PerLlocDaolceu:m:eTnetxattDioomnain::OO::JavaScript(3)
2
3
4
6 Locale::TextDomain::OO::JavaScript - How to use the JavaScript part
7
8 $Id: JavaScript.pm 573 2015-02-07 20:59:51Z steffenw $
9
10 $HeadURL:
11 svn+ssh://steffenw@svn.code.sf.net/p/perl-gettext-oo/code/module/trunk/lib/Locale/TextDomain/OO/JavaScript.pm
12 $
13
15 1.017
16
18 This module provides a high-level interface to JavaScript message
19 translation.
20
21 Creating the Lexicon and the selection of the language are server
22 (Perl) based. The script gets the lexicon in a global variable named
23 localeTextDomainOOLexicon.
24
25 Inside of the constructor is a language attribute, that shoud be filled
26 from server.
27
28 It is possible to filter the lexicon. For bigger lexicon files filter
29 also by language to split the lexicon. Load only the lexicon of the
30 current language.
31
32 How to extract?
33 Use module Locale::TextDomain::OO::Extract. This is a base class for
34 all source scanner to create pot files. Use this base class and give
35 this module the rules or use one of the already exteded classes.
36 Locale::TextDomain::OO::Extract::JavaScript::JS is a extension for
37 Javacript from *.js files and so on.
38
40 Inside of this distribution is a directory named javascript. Copy this
41 files into your project. Do the same with javascript files of
42 Locale::TextDomain::OO::Util::Constants,
43 Locale::TextDomain::OO::Util::JoinSplitLexiconKeys and
44 Locale::Utils::PlaceholderNamed.
45
46 This scripts depending on <http://jquery.com/>.
47
48 Watch also the javascript/Example.html how to use.
49
50 <!-- depends on -->
51 <script type="text/javascript" src=".../jquery-...js"></script>
52 <script type="text/javascript" src=".../Locale/TextDomain/OO/Util/Constants.js"></script>
53 <script type="text/javascript" src=".../Locale/TextDomain/OO/Util/JoinSplitLexiconKeys.js"></script>
54 <script type="text/javascript" src=".../Locale/Utils/PlaceholderNamed.js"></script>
55
56 <!-- stores the lexicon into var localeTextDomainOOLexicon -->
57 <script type="text/javascript" src=".../localeTextDomainOOLexicon.js"></script>
58
59 <!-- depends on var localeTextDomainOOLexicon -->
60 <script type="text/javascript" src=".../Locale/TextDomain/OO.js"></script>
61 <script type="text/javascript" src=".../Locale/TextDomain/OO/Plugin/Expand/Gettext/Loc.js"></script>
62 <script type="text/javascript" src=".../Locale/TextDomain/OO/Plugin/Expand/Gettext/Loc/DomainAndCategory.js"></script>
63
64 <!-- initialize -->
65 <script type="text/javascript">
66 var ltdoo = new localeTextDomainOO({
67 plugins : [ 'localeTextDomainOOExpandGettextLocDomainAndCategory' ],
68 language : '@{[ $language_tag ]}', // from Perl
69 category : 'LC_MESSAGES', // optional category
70 domain : 'MyDomain', // optional domain
71 filter : function(translation) { // optional filter
72 // modifies the translation late
73 return translation;
74 },
75 logger : function (message, argMap) { // optional logger
76 console.log(message);
77 return;
78 }
79 });
80 </script>
81
82 This configuration would be use Lexicon
83 "$language_tag:LC_MESSAGES:MyDomain". That lexicon should be filled
84 with data.
85
86 <!-- translations -->
87 <script type="text/javascript">
88 // extractable, translate
89 str = ltdoo.loc_('msgid');
90 str = ltdoo.loc_x('msgid', {key1 : 'value1'});
91 str = ltdoo.loc_p('msgctxt', 'msgid');
92 str = ltdoo.loc_px('msgctxt', 'msgid', {key1 : 'value1'});
93 str = ltdoo.loc_n('msgid', 'msgid_plural', count);
94 str = ltdoo.loc_nx('msgid', 'msgid_plural', count, {key1 : 'value1'});
95 str = ltdoo.loc_np('msgctxt', 'msgid', 'msgid_plural', count);
96 str = ltdoo.loc_npx('msgctxt', 'msgid', 'msgid_plural', count, {key1 : 'value1'});
97
98 // extractable, prepare
99 arr = ltdoo.Nloc_('msgid');
100 arr = ltdoo.Nloc_x('msgid', {key1 : 'value1'});
101 arr = ltdoo.Nloc_p('msgctxt', 'msgid');
102 arr = ltdoo.Nloc_px('msgctxt', 'msgid', {key1 : 'value1'});
103 arr = ltdoo.Nloc_n('msgid', 'msgid_plural', count);
104 arr = ltdoo.Nloc_nx('msgid', 'msgid_plural', count, {key1 : 'value1'});
105 arr = ltdoo.Nloc_np('msgctxt', 'msgid', 'msgid_plural', count);
106 arr = ltdoo.Nloc_npx('msgctxt', 'msgid', 'msgid_plural', count, {key1 : 'value1'});
107
108 // with domain
109
110 // extractable, translate
111 str = ltdoo.loc_d('domain', 'msgid');
112 str = ltdoo.loc_dx('domain', 'msgid', {key1 : 'value1'});
113 str = ltdoo.loc_dp('domain', 'msgctxt', 'msgid');
114 str = ltdoo.loc_dpx('domain', 'msgctxt', 'msgid', {key1 : 'value1'});
115 str = ltdoo.loc_dn('domain', 'msgid', 'msgid_plural', count);
116 str = ltdoo.loc_dnx('domain', 'msgid', 'msgid_plural', count, {key1 : 'value1'});
117 str = ltdoo.loc_dnp('domain', 'msgctxt', 'msgid', 'msgid_plural', count);
118 str = ltdoo.loc_dnpx('domain', 'msgctxt', 'msgid', 'msgid_plural', count, {key1 : 'value1'});
119
120 // extractable, prepare
121 arr = ltdoo.Nloc_d('domain', 'msgid');
122 arr = ltdoo.Nloc_dx('domain', 'msgid', {key1 : 'value1'});
123 arr = ltdoo.Nloc_dp('domain', 'msgctxt', 'msgid');
124 arr = ltdoo.Nloc_dpx('domain', 'msgctxt', 'msgid', {key1 : 'value1'});
125 arr = ltdoo.Nloc_dn('domain', 'msgid', 'msgid_plural', count);
126 arr = ltdoo.Nloc_dnx('domain', 'msgid', 'msgid_plural', count, {key1 : 'value1'});
127 arr = ltdoo.Nloc_dnp('domain', 'msgctxt', 'msgid', 'msgid_plural', count);
128 arr = ltdoo.Nloc_dnpx('domain', 'msgctxt', 'msgid', 'msgid_plural', count, {key1 : 'value1'});
129
130 // with category
131
132 // extractable, translate
133 str = ltdoo.loc_c('msgid', 'category');
134 str = ltdoo.loc_cx('msgid', 'category', {key1 : 'value1'});
135 str = ltdoo.loc_cp('msgctxt', 'msgid', 'category');
136 str = ltdoo.loc_cpx('msgctxt', 'msgid', 'category', {key1 : 'value1'});
137 str = ltdoo.loc_cn('msgid', 'msgid_plural', count, 'category');
138 str = ltdoo.loc_cnx('msgid', 'msgid_plural', count, 'category', {key1 : 'value1'});
139 str = ltdoo.loc_cnp('msgctxt', 'msgid', 'msgid_plural', count, 'category');
140 str = ltdoo.loc_cnpx('msgctxt', 'msgid', 'msgid_plural', count, 'category', {key1 : 'value1'});
141
142 // extractable, prepare
143 arr = ltdoo.Nloc_c('msgid', 'category');
144 arr = ltdoo.Nloc_cx('msgid', 'category', {key1 : 'value1'});
145 arr = ltdoo.Nloc_cp('msgctxt', 'msgid', 'category');
146 arr = ltdoo.Nloc_cpx('msgctxt', 'msgid', 'category', {key1 : 'value1'});
147 arr = ltdoo.Nloc_cn('msgid', 'msgid_plural', count, 'category');
148 arr = ltdoo.Nloc_cnx('msgid', 'msgid_plural', count, 'category', {key1 : 'value1'});
149 arr = ltdoo.Nloc_cnp('msgctxt', 'msgid', 'msgid_plural', count, 'category');
150 arr = ltdoo.Nloc_cnpx('msgctxt', 'msgid', 'msgid_plural', count, 'category', {key1 : 'value1'});
151
152 // with domain and category
153
154 // extractable, translate
155 str = ltdoo.loc_dc('domain', 'msgid', 'category');
156 str = ltdoo.loc_dcx('domain', 'msgid', 'category', {key1 : 'value1'});
157 str = ltdoo.loc_dcp('domain', 'msgctxt', 'msgid', 'category');
158 str = ltdoo.loc_dcpx('domain', 'msgctxt', 'msgid', 'category', {key1 : 'value1'});
159 str = ltdoo.loc_dcn('domain', 'msgid', 'msgid_plural', count, 'category');
160 str = ltdoo.loc_dcnx('domain', 'msgid', 'msgid_plural', count, 'category', {key1 : 'value1'});
161 str = ltdoo.loc_dcnp('domain', 'msgctxt', 'msgid', 'msgid_plural', count, 'category');
162 str = ltdoo.loc_dcnpx('domain', 'msgctxt', 'msgid', 'msgid_plural', count, 'category', {key1 : 'value1'});
163
164 // extractable, prepare
165 arr = ltdoo.Nloc_dc('domain', 'msgid', 'category');
166 arr = ltdoo.Nloc_dcx('domain', 'msgid', 'category', {key1 : 'value1'});
167 arr = ltdoo.Nloc_dcp('domain', 'msgctxt', 'msgid', 'category');
168 arr = ltdoo.Nloc_dcpx('domain', 'msgctxt', 'msgid', 'category', {key1 : 'value1'});
169 arr = ltdoo.Nloc_dcn('domain', 'msgid', 'msgid_plural', count, 'category');
170 arr = ltdoo.Nloc_dcnx('domain', 'msgid', 'msgid_plural', count, 'category', {key1 : 'value1'});
171 arr = ltdoo.Nloc_dcnp('domain', 'msgctxt', 'msgid', 'msgid_plural', count, 'category');
172 arr = ltdoo.Nloc_dcnpx('domain', 'msgctxt', 'msgid', 'msgid_plural', count, 'category', {key1 : 'value1'});
173 </script>
174
176 see SYNOPSIS
177
179 none
180
182 none
183
185 <http://jquery.com/>
186
187 Locale::TextDomain::OO::Util::Constants
188
189 Locale::TextDomain::OO::Util::JoinSplitLexiconKeys
190
191 Locale::Utils::PlaceholderNamed
192
194 not known
195
197 not known
198
200 Locale::TextDoamin::OO
201
203 Steffen Winkler
204
206 Copyright (c) 2014 - 2015, Steffen Winkler "<steffenw at cpan.org>".
207 All rights reserved.
208
209 This module is free software; you can redistribute it and/or modify it
210 under the same terms as Perl itself.
211
212
213
214perl v5.32.1 2021-01-L2o7cale::TextDomain::OO::JavaScript(3)