Mercurial > hg > OKFNAnnotator
annotate annotator_files/lib/vendor/gettext.js @ 3:6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
author | casties |
---|---|
date | Thu, 05 Apr 2012 19:37:27 +0200 |
parents | |
children |
rev | line source |
---|---|
3
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1 /* |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
2 Pure Javascript implementation of Uniforum message translation. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
3 Copyright (C) 2008 Joshua I. Miller <unrtst@cpan.org>, all rights reserved |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
4 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
5 This program is free software; you can redistribute it and/or modify it |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
6 under the terms of the GNU Library General Public License as published |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
7 by the Free Software Foundation; either version 2, or (at your option) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
8 any later version. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
9 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
10 This program is distributed in the hope that it will be useful, |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
13 Library General Public License for more details. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
14 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
15 You should have received a copy of the GNU Library General Public |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
16 License along with this program; if not, write to the Free Software |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
18 USA. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
19 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
20 =head1 NAME |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
21 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
22 Javascript Gettext - Javascript implemenation of GNU Gettext API. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
23 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
24 =head1 SYNOPSIS |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
25 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
26 // ////////////////////////////////////////////////////////// |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
27 // Optimum caching way |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
28 <script language="javascript" src="/path/LC_MESSAGES/myDomain.json"></script> |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
29 <script language="javascript" src="/path/Gettext.js'></script> |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
30 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
31 // assuming myDomain.json defines variable json_locale_data |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
32 var params = { "domain" : "myDomain", |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
33 "locale_data" : json_locale_data |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
34 }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
35 var gt = new Gettext(params); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
36 // create a shortcut if you'd like |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
37 function _ (msgid) { return gt.gettext(msgid); } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
38 alert(_("some string")); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
39 // or use fully named method |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
40 alert(gt.gettext("some string")); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
41 // change to use a different "domain" |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
42 gt.textdomain("anotherDomain"); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
43 alert(gt.gettext("some string")); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
44 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
45 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
46 // ////////////////////////////////////////////////////////// |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
47 // The other way to load the language lookup is a "link" tag |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
48 // Downside is that not all browsers cache XMLHttpRequests the |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
49 // same way, so caching of the language data isn't guarenteed |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
50 // across page loads. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
51 // Upside is that it's easy to specify multiple files |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
52 <link rel="gettext" href="/path/LC_MESSAGES/myDomain.json" /> |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
53 <script language="javascript" src="/path/Gettext.js'></script> |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
54 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
55 var gt = new Gettext({ "domain" : "myDomain" }); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
56 // rest is the same |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
57 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
58 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
59 // ////////////////////////////////////////////////////////// |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
60 // The reson the shortcuts aren't exported by default is because they'd be |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
61 // glued to the single domain you created. So, if you're adding i18n support |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
62 // to some js library, you should use it as so: |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
63 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
64 if (typeof(MyNamespace) == 'undefined') MyNamespace = {}; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
65 MyNamespace.MyClass = function () { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
66 var gtParms = { "domain" : 'MyNamespace_MyClass' }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
67 this.gt = new Gettext(gtParams); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
68 return this; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
69 }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
70 MyNamespace.MyClass.prototype._ = function (msgid) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
71 return this.gt.gettext(msgid); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
72 }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
73 MyNamespace.MyClass.prototype.something = function () { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
74 var myString = this._("this will get translated"); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
75 }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
76 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
77 // ////////////////////////////////////////////////////////// |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
78 // Adding the shortcuts to a global scope is easier. If that's |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
79 // ok in your app, this is certainly easier. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
80 var myGettext = new Gettext({ 'domain' : 'myDomain' }); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
81 function _ (msgid) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
82 return myGettext.gettext(msgid); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
83 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
84 alert( _("text") ); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
85 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
86 // ////////////////////////////////////////////////////////// |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
87 // Data structure of the json data |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
88 // NOTE: if you're loading via the <script> tag, you can only |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
89 // load one file, but it can contain multiple domains. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
90 var json_locale_data = { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
91 "MyDomain" : { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
92 "" : { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
93 "header_key" : "header value", |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
94 "header_key" : "header value", |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
95 "msgid" : [ "msgid_plural", "msgstr", "msgstr_plural", "msgstr_pluralN" ], |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
96 "msgctxt\004msgid" : [ null, "msgstr" ], |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
97 }, |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
98 "AnotherDomain" : { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
99 }, |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
100 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
101 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
102 =head1 DESCRIPTION |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
103 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
104 This is a javascript implementation of GNU Gettext, providing internationalization support for javascript. It differs from existing javascript implementations in that it will support all current Gettext features (ex. plural and context support), and will also support loading language catalogs from .mo, .po, or preprocessed json files (converter included). |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
105 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
106 The locale initialization differs from that of GNU Gettext / POSIX. Rather than setting the category, domain, and paths, and letting the libs find the right file, you must explicitly load the file at some point. The "domain" will still be honored. Future versions may be expanded to include support for set_locale like features. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
107 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
108 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
109 =head1 INSTALL |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
110 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
111 To install this module, simply copy the file lib/Gettext.js to a web accessable location, and reference it from your application. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
112 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
113 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
114 =head1 CONFIGURATION |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
115 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
116 Configure in one of two ways: |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
117 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
118 =over |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
119 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
120 =item 1. Optimal. Load language definition from statically defined json data. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
121 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
122 <script language="javascript" src="/path/locale/domain.json"></script> |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
123 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
124 // in domain.json |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
125 json_locale_data = { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
126 "mydomain" : { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
127 // po header fields |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
128 "" : { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
129 "plural-forms" : "...", |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
130 "lang" : "en", |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
131 }, |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
132 // all the msgid strings and translations |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
133 "msgid" : [ "msgid_plural", "translation", "plural_translation" ], |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
134 }, |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
135 }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
136 // please see the included bin/po2json script for the details on this format |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
137 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
138 This method also allows you to use unsupported file formats, so long as you can parse them into the above format. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
139 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
140 =item 2. Use AJAX to load language file. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
141 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
142 Use XMLHttpRequest (actually, SJAX - syncronous) to load an external resource. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
143 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
144 Supported external formats are: |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
145 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
146 =over |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
147 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
148 =item * Javascript Object Notation (.json) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
149 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
150 (see bin/po2json) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
151 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
152 type=application/json |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
153 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
154 =item * Uniforum Portable Object (.po) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
155 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
156 (see GNU Gettext's xgettext) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
157 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
158 type=application/x-po |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
159 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
160 =item * Machine Object (compiled .po) (.mo) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
161 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
162 NOTE: .mo format isn't actually supported just yet, but support is planned. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
163 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
164 (see GNU Gettext's msgfmt) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
165 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
166 type=application/x-mo |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
167 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
168 =back |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
169 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
170 =back |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
171 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
172 =head1 METHODS |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
173 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
174 The following methods are implemented: |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
175 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
176 new Gettext(args) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
177 textdomain (domain) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
178 gettext (msgid) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
179 dgettext (domainname, msgid) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
180 dcgettext (domainname, msgid, LC_MESSAGES) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
181 ngettext (msgid, msgid_plural, count) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
182 dngettext (domainname, msgid, msgid_plural, count) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
183 dcngettext (domainname, msgid, msgid_plural, count, LC_MESSAGES) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
184 pgettext (msgctxt, msgid) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
185 dpgettext (domainname, msgctxt, msgid) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
186 dcpgettext (domainname, msgctxt, msgid, LC_MESSAGES) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
187 npgettext (msgctxt, msgid, msgid_plural, count) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
188 dnpgettext (domainname, msgctxt, msgid, msgid_plural, count) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
189 dcnpgettext (domainname, msgctxt, msgid, msgid_plural, count, LC_MESSAGES) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
190 strargs (string, args_array) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
191 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
192 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
193 =head2 new Gettext (args) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
194 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
195 Several methods of loading locale data are included. You may specify a plugin or alternative method of loading data by passing the data in as the "locale_data" option. For example: |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
196 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
197 var get_locale_data = function () { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
198 // plugin does whatever to populate locale_data |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
199 return locale_data; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
200 }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
201 var gt = new Gettext( 'domain' : 'messages', |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
202 'locale_data' : get_locale_data() ); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
203 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
204 The above can also be used if locale data is specified in a statically included <SCRIPT> tag. Just specify the variable name in the call to new. Ex: |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
205 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
206 var gt = new Gettext( 'domain' : 'messages', |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
207 'locale_data' : json_locale_data_variable ); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
208 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
209 Finally, you may load the locale data by referencing it in a <LINK> tag. Simply exclude the 'locale_data' option, and all <LINK rel="gettext" ...> items will be tried. The <LINK> should be specified as: |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
210 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
211 <link rel="gettext" type="application/json" href="/path/to/file.json"> |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
212 <link rel="gettext" type="text/javascript" href="/path/to/file.json"> |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
213 <link rel="gettext" type="application/x-po" href="/path/to/file.po"> |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
214 <link rel="gettext" type="application/x-mo" href="/path/to/file.mo"> |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
215 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
216 args: |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
217 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
218 =over |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
219 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
220 =item domain |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
221 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
222 The Gettext domain, not www.whatev.com. It's usually your applications basename. If the .po file was "myapp.po", this would be "myapp". |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
223 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
224 =item locale_data |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
225 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
226 Raw locale data (in json structure). If specified, from_link data will be ignored. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
227 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
228 =back |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
229 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
230 =cut |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
231 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
232 */ |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
233 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
234 Gettext = function (args) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
235 this.domain = 'messages'; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
236 // locale_data will be populated from <link...> if not specified in args |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
237 this.locale_data = undefined; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
238 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
239 // set options |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
240 var options = [ "domain", "locale_data" ]; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
241 if (this.isValidObject(args)) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
242 for (var i in args) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
243 for (var j=0; j<options.length; j++) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
244 if (i == options[j]) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
245 // don't set it if it's null or undefined |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
246 if (this.isValidObject(args[i])) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
247 this[i] = args[i]; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
248 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
249 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
250 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
251 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
252 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
253 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
254 // try to load the lang file from somewhere |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
255 this.try_load_lang(); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
256 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
257 return this; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
258 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
259 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
260 Gettext.context_glue = "\004"; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
261 Gettext._locale_data = {}; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
262 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
263 Gettext.prototype.try_load_lang = function() { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
264 // check to see if language is statically included |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
265 if (typeof(this.locale_data) != 'undefined') { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
266 // we're going to reformat it, and overwrite the variable |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
267 var locale_copy = this.locale_data; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
268 this.locale_data = undefined; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
269 this.parse_locale_data(locale_copy); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
270 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
271 if (typeof(Gettext._locale_data[this.domain]) == 'undefined') { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
272 throw new Error("Error: Gettext 'locale_data' does not contain the domain '"+this.domain+"'"); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
273 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
274 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
275 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
276 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
277 // try loading from JSON |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
278 // get lang links |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
279 var lang_link = this.get_lang_refs(); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
280 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
281 if (typeof(lang_link) == 'object' && lang_link.length > 0) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
282 // NOTE: there will be a delay here, as this is async. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
283 // So, any i18n calls made right after page load may not |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
284 // get translated. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
285 // XXX: we may want to see if we can "fix" this behavior |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
286 for (var i=0; i<lang_link.length; i++) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
287 var link = lang_link[i]; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
288 if (link.type == 'application/json') { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
289 if (! this.try_load_lang_json(link.href) ) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
290 throw new Error("Error: Gettext 'try_load_lang_json' failed. Unable to exec xmlhttprequest for link ["+link.href+"]"); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
291 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
292 } else if (link.type == 'application/x-po') { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
293 if (! this.try_load_lang_po(link.href) ) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
294 throw new Error("Error: Gettext 'try_load_lang_po' failed. Unable to exec xmlhttprequest for link ["+link.href+"]"); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
295 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
296 } else { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
297 // TODO: implement the other types (.mo) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
298 throw new Error("TODO: link type ["+link.type+"] found, and support is planned, but not implemented at this time."); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
299 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
300 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
301 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
302 }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
303 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
304 // This takes the bin/po2json'd data, and moves it into an internal form |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
305 // for use in our lib, and puts it in our object as: |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
306 // Gettext._locale_data = { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
307 // domain : { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
308 // head : { headfield : headvalue }, |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
309 // msgs : { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
310 // msgid : [ msgid_plural, msgstr, msgstr_plural ], |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
311 // }, |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
312 Gettext.prototype.parse_locale_data = function(locale_data) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
313 if (typeof(Gettext._locale_data) == 'undefined') { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
314 Gettext._locale_data = { }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
315 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
316 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
317 // suck in every domain defined in the supplied data |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
318 for (var domain in locale_data) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
319 // skip empty specs (flexibly) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
320 if ((! locale_data.hasOwnProperty(domain)) || (! this.isValidObject(locale_data[domain]))) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
321 continue; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
322 // skip if it has no msgid's |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
323 var has_msgids = false; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
324 for (var msgid in locale_data[domain]) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
325 has_msgids = true; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
326 break; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
327 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
328 if (! has_msgids) continue; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
329 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
330 // grab shortcut to data |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
331 var data = locale_data[domain]; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
332 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
333 // if they specifcy a blank domain, default to "messages" |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
334 if (domain == "") domain = "messages"; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
335 // init the data structure |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
336 if (! this.isValidObject(Gettext._locale_data[domain]) ) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
337 Gettext._locale_data[domain] = { }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
338 if (! this.isValidObject(Gettext._locale_data[domain].head) ) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
339 Gettext._locale_data[domain].head = { }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
340 if (! this.isValidObject(Gettext._locale_data[domain].msgs) ) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
341 Gettext._locale_data[domain].msgs = { }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
342 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
343 for (var key in data) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
344 if (key == "") { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
345 var header = data[key]; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
346 for (var head in header) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
347 var h = head.toLowerCase(); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
348 Gettext._locale_data[domain].head[h] = header[head]; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
349 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
350 } else { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
351 Gettext._locale_data[domain].msgs[key] = data[key]; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
352 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
353 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
354 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
355 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
356 // build the plural forms function |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
357 for (var domain in Gettext._locale_data) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
358 if (this.isValidObject(Gettext._locale_data[domain].head['plural-forms']) && |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
359 typeof(Gettext._locale_data[domain].head.plural_func) == 'undefined') { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
360 // untaint data |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
361 var plural_forms = Gettext._locale_data[domain].head['plural-forms']; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
362 var pf_re = new RegExp('^(\\s*nplurals\\s*=\\s*[0-9]+\\s*;\\s*plural\\s*=\\s*(?:\\s|[-\\?\\|&=!<>+*/%:;a-zA-Z0-9_\(\)])+)', 'm'); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
363 if (pf_re.test(plural_forms)) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
364 //ex english: "Plural-Forms: nplurals=2; plural=(n != 1);\n" |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
365 //pf = "nplurals=2; plural=(n != 1);"; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
366 //ex russian: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10< =4 && (n%100<10 or n%100>=20) ? 1 : 2) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
367 //pf = "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)"; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
368 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
369 var pf = Gettext._locale_data[domain].head['plural-forms']; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
370 if (! /;\s*$/.test(pf)) pf = pf.concat(';'); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
371 /* We used to use eval, but it seems IE has issues with it. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
372 * We now use "new Function", though it carries a slightly |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
373 * bigger performance hit. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
374 var code = 'function (n) { var plural; var nplurals; '+pf+' return { "nplural" : nplurals, "plural" : (plural === true ? 1 : plural ? plural : 0) }; };'; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
375 Gettext._locale_data[domain].head.plural_func = eval("("+code+")"); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
376 */ |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
377 var code = 'var plural; var nplurals; '+pf+' return { "nplural" : nplurals, "plural" : (plural === true ? 1 : plural ? plural : 0) };'; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
378 Gettext._locale_data[domain].head.plural_func = new Function("n", code); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
379 } else { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
380 throw new Error("Syntax error in language file. Plural-Forms header is invalid ["+plural_forms+"]"); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
381 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
382 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
383 // default to english plural form |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
384 } else if (typeof(Gettext._locale_data[domain].head.plural_func) == 'undefined') { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
385 Gettext._locale_data[domain].head.plural_func = function (n) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
386 var p = (n != 1) ? 1 : 0; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
387 return { 'nplural' : 2, 'plural' : p }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
388 }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
389 } // else, plural_func already created |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
390 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
391 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
392 return; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
393 }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
394 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
395 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
396 // try_load_lang_po : do an ajaxy call to load in the .po lang defs |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
397 Gettext.prototype.try_load_lang_po = function(uri) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
398 var data = this.sjax(uri); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
399 if (! data) return; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
400 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
401 var domain = this.uri_basename(uri); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
402 var parsed = this.parse_po(data); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
403 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
404 var rv = {}; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
405 // munge domain into/outof header |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
406 if (parsed) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
407 if (! parsed[""]) parsed[""] = {}; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
408 if (! parsed[""]["domain"]) parsed[""]["domain"] = domain; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
409 domain = parsed[""]["domain"]; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
410 rv[domain] = parsed; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
411 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
412 this.parse_locale_data(rv); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
413 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
414 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
415 return 1; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
416 }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
417 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
418 Gettext.prototype.uri_basename = function(uri) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
419 var rv; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
420 if (rv = uri.match(/^(.*\/)?(.*)/)) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
421 var ext_strip; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
422 if (ext_strip = rv[2].match(/^(.*)\..+$/)) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
423 return ext_strip[1]; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
424 else |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
425 return rv[2]; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
426 } else { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
427 return ""; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
428 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
429 }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
430 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
431 Gettext.prototype.parse_po = function(data) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
432 var rv = {}; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
433 var buffer = {}; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
434 var lastbuffer = ""; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
435 var errors = []; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
436 var lines = data.split("\n"); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
437 for (var i=0; i<lines.length; i++) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
438 // chomp |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
439 lines[i] = lines[i].replace(/(\n|\r)+$/, ''); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
440 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
441 var match; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
442 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
443 // Empty line / End of an entry. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
444 if (/^$/.test(lines[i])) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
445 if (typeof(buffer['msgid']) != 'undefined') { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
446 var msg_ctxt_id = (typeof(buffer['msgctxt']) != 'undefined' && |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
447 buffer['msgctxt'].length) ? |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
448 buffer['msgctxt']+Gettext.context_glue+buffer['msgid'] : |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
449 buffer['msgid']; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
450 var msgid_plural = (typeof(buffer['msgid_plural']) != 'undefined' && |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
451 buffer['msgid_plural'].length) ? |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
452 buffer['msgid_plural'] : |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
453 null; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
454 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
455 // find msgstr_* translations and push them on |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
456 var trans = []; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
457 for (var str in buffer) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
458 var match; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
459 if (match = str.match(/^msgstr_(\d+)/)) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
460 trans[parseInt(match[1])] = buffer[str]; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
461 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
462 trans.unshift(msgid_plural); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
463 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
464 // only add it if we've got a translation |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
465 // NOTE: this doesn't conform to msgfmt specs |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
466 if (trans.length > 1) rv[msg_ctxt_id] = trans; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
467 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
468 buffer = {}; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
469 lastbuffer = ""; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
470 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
471 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
472 // comments |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
473 } else if (/^#/.test(lines[i])) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
474 continue; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
475 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
476 // msgctxt |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
477 } else if (match = lines[i].match(/^msgctxt\s+(.*)/)) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
478 lastbuffer = 'msgctxt'; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
479 buffer[lastbuffer] = this.parse_po_dequote(match[1]); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
480 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
481 // msgid |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
482 } else if (match = lines[i].match(/^msgid\s+(.*)/)) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
483 lastbuffer = 'msgid'; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
484 buffer[lastbuffer] = this.parse_po_dequote(match[1]); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
485 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
486 // msgid_plural |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
487 } else if (match = lines[i].match(/^msgid_plural\s+(.*)/)) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
488 lastbuffer = 'msgid_plural'; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
489 buffer[lastbuffer] = this.parse_po_dequote(match[1]); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
490 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
491 // msgstr |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
492 } else if (match = lines[i].match(/^msgstr\s+(.*)/)) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
493 lastbuffer = 'msgstr_0'; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
494 buffer[lastbuffer] = this.parse_po_dequote(match[1]); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
495 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
496 // msgstr[0] (treak like msgstr) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
497 } else if (match = lines[i].match(/^msgstr\[0\]\s+(.*)/)) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
498 lastbuffer = 'msgstr_0'; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
499 buffer[lastbuffer] = this.parse_po_dequote(match[1]); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
500 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
501 // msgstr[n] |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
502 } else if (match = lines[i].match(/^msgstr\[(\d+)\]\s+(.*)/)) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
503 lastbuffer = 'msgstr_'+match[1]; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
504 buffer[lastbuffer] = this.parse_po_dequote(match[2]); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
505 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
506 // continued string |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
507 } else if (/^"/.test(lines[i])) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
508 buffer[lastbuffer] += this.parse_po_dequote(lines[i]); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
509 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
510 // something strange |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
511 } else { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
512 errors.push("Strange line ["+i+"] : "+lines[i]); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
513 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
514 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
515 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
516 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
517 // handle the final entry |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
518 if (typeof(buffer['msgid']) != 'undefined') { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
519 var msg_ctxt_id = (typeof(buffer['msgctxt']) != 'undefined' && |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
520 buffer['msgctxt'].length) ? |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
521 buffer['msgctxt']+Gettext.context_glue+buffer['msgid'] : |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
522 buffer['msgid']; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
523 var msgid_plural = (typeof(buffer['msgid_plural']) != 'undefined' && |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
524 buffer['msgid_plural'].length) ? |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
525 buffer['msgid_plural'] : |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
526 null; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
527 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
528 // find msgstr_* translations and push them on |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
529 var trans = []; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
530 for (var str in buffer) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
531 var match; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
532 if (match = str.match(/^msgstr_(\d+)/)) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
533 trans[parseInt(match[1])] = buffer[str]; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
534 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
535 trans.unshift(msgid_plural); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
536 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
537 // only add it if we've got a translation |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
538 // NOTE: this doesn't conform to msgfmt specs |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
539 if (trans.length > 1) rv[msg_ctxt_id] = trans; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
540 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
541 buffer = {}; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
542 lastbuffer = ""; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
543 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
544 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
545 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
546 // parse out the header |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
547 if (rv[""] && rv[""][1]) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
548 var cur = {}; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
549 var hlines = rv[""][1].split(/\\n/); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
550 for (var i=0; i<hlines.length; i++) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
551 if (! hlines.length) continue; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
552 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
553 var pos = hlines[i].indexOf(':', 0); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
554 if (pos != -1) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
555 var key = hlines[i].substring(0, pos); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
556 var val = hlines[i].substring(pos +1); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
557 var keylow = key.toLowerCase(); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
558 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
559 if (cur[keylow] && cur[keylow].length) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
560 errors.push("SKIPPING DUPLICATE HEADER LINE: "+hlines[i]); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
561 } else if (/#-#-#-#-#/.test(keylow)) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
562 errors.push("SKIPPING ERROR MARKER IN HEADER: "+hlines[i]); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
563 } else { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
564 // remove begining spaces if any |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
565 val = val.replace(/^\s+/, ''); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
566 cur[keylow] = val; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
567 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
568 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
569 } else { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
570 errors.push("PROBLEM LINE IN HEADER: "+hlines[i]); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
571 cur[hlines[i]] = ''; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
572 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
573 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
574 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
575 // replace header string with assoc array |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
576 rv[""] = cur; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
577 } else { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
578 rv[""] = {}; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
579 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
580 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
581 // TODO: XXX: if there are errors parsing, what do we want to do? |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
582 // GNU Gettext silently ignores errors. So will we. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
583 // alert( "Errors parsing po file:\n" + errors.join("\n") ); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
584 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
585 return rv; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
586 }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
587 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
588 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
589 Gettext.prototype.parse_po_dequote = function(str) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
590 var match; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
591 if (match = str.match(/^"(.*)"/)) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
592 str = match[1]; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
593 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
594 // unescale all embedded quotes (fixes bug #17504) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
595 str = str.replace(/\\"/g, "\""); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
596 return str; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
597 }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
598 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
599 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
600 // try_load_lang_json : do an ajaxy call to load in the lang defs |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
601 Gettext.prototype.try_load_lang_json = function(uri) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
602 var data = this.sjax(uri); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
603 if (! data) return; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
604 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
605 var rv = this.JSON(data); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
606 this.parse_locale_data(rv); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
607 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
608 return 1; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
609 }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
610 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
611 // this finds all <link> tags, filters out ones that match our |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
612 // specs, and returns a list of hashes of those |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
613 Gettext.prototype.get_lang_refs = function() { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
614 var langs = new Array(); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
615 var links = document.getElementsByTagName("link"); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
616 // find all <link> tags in dom; filter ours |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
617 for (var i=0; i<links.length; i++) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
618 if (links[i].rel == 'gettext' && links[i].href) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
619 if (typeof(links[i].type) == 'undefined' || |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
620 links[i].type == '') { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
621 if (/\.json$/i.test(links[i].href)) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
622 links[i].type = 'application/json'; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
623 } else if (/\.js$/i.test(links[i].href)) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
624 links[i].type = 'application/json'; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
625 } else if (/\.po$/i.test(links[i].href)) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
626 links[i].type = 'application/x-po'; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
627 } else if (/\.mo$/i.test(links[i].href)) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
628 links[i].type = 'application/x-mo'; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
629 } else { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
630 throw new Error("LINK tag with rel=gettext found, but the type and extension are unrecognized."); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
631 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
632 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
633 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
634 links[i].type = links[i].type.toLowerCase(); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
635 if (links[i].type == 'application/json') { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
636 links[i].type = 'application/json'; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
637 } else if (links[i].type == 'text/javascript') { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
638 links[i].type = 'application/json'; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
639 } else if (links[i].type == 'application/x-po') { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
640 links[i].type = 'application/x-po'; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
641 } else if (links[i].type == 'application/x-mo') { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
642 links[i].type = 'application/x-mo'; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
643 } else { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
644 throw new Error("LINK tag with rel=gettext found, but the type attribute ["+links[i].type+"] is unrecognized."); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
645 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
646 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
647 langs.push(links[i]); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
648 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
649 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
650 return langs; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
651 }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
652 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
653 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
654 /* |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
655 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
656 =head2 textdomain( domain ) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
657 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
658 Set domain for future gettext() calls |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
659 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
660 A message domain is a set of translatable msgid messages. Usually, |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
661 every software package has its own message domain. The domain name is |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
662 used to determine the message catalog where a translation is looked up; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
663 it must be a non-empty string. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
664 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
665 The current message domain is used by the gettext, ngettext, pgettext, |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
666 npgettext functions, and by the dgettext, dcgettext, dngettext, dcngettext, |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
667 dpgettext, dcpgettext, dnpgettext and dcnpgettext functions when called |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
668 with a NULL domainname argument. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
669 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
670 If domainname is not NULL, the current message domain is set to |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
671 domainname. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
672 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
673 If domainname is undefined, null, or empty string, the function returns |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
674 the current message domain. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
675 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
676 If successful, the textdomain function returns the current message |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
677 domain, after possibly changing it. (ie. if you set a new domain, the |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
678 value returned will NOT be the previous domain). |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
679 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
680 =cut |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
681 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
682 */ |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
683 Gettext.prototype.textdomain = function (domain) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
684 if (domain && domain.length) this.domain = domain; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
685 return this.domain; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
686 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
687 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
688 /* |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
689 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
690 =head2 gettext( MSGID ) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
691 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
692 Returns the translation for B<MSGID>. Example: |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
693 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
694 alert( gt.gettext("Hello World!\n") ); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
695 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
696 If no translation can be found, the unmodified B<MSGID> is returned, |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
697 i. e. the function can I<never> fail, and will I<never> mess up your |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
698 original message. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
699 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
700 One common mistake is to interpolate a variable into the string like this: |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
701 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
702 var translated = gt.gettext("Hello " + full_name); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
703 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
704 The interpolation will happen before it's passed to gettext, and it's |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
705 unlikely you'll have a translation for every "Hello Tom" and "Hello Dick" |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
706 and "Hellow Harry" that may arise. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
707 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
708 Use C<strargs()> (see below) to solve this problem: |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
709 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
710 var translated = Gettext.strargs( gt.gettext("Hello %1"), [full_name] ); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
711 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
712 This is espeically useful when multiple replacements are needed, as they |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
713 may not appear in the same order within the translation. As an English to |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
714 French example: |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
715 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
716 Expected result: "This is the red ball" |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
717 English: "This is the %1 %2" |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
718 French: "C'est le %2 %1" |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
719 Code: Gettext.strargs( gt.gettext("This is the %1 %2"), ["red", "ball"] ); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
720 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
721 (The example is stupid because neither color nor thing will get |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
722 translated here ...). |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
723 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
724 =head2 dgettext( TEXTDOMAIN, MSGID ) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
725 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
726 Like gettext(), but retrieves the message for the specified |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
727 B<TEXTDOMAIN> instead of the default domain. In case you wonder what |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
728 a textdomain is, see above section on the textdomain() call. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
729 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
730 =head2 dcgettext( TEXTDOMAIN, MSGID, CATEGORY ) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
731 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
732 Like dgettext() but retrieves the message from the specified B<CATEGORY> |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
733 instead of the default category C<LC_MESSAGES>. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
734 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
735 NOTE: the categories are really useless in javascript context. This is |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
736 here for GNU Gettext API compatability. In practice, you'll never need |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
737 to use this. This applies to all the calls including the B<CATEGORY>. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
738 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
739 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
740 =head2 ngettext( MSGID, MSGID_PLURAL, COUNT ) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
741 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
742 Retrieves the correct translation for B<COUNT> items. In legacy software |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
743 you will often find something like: |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
744 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
745 alert( count + " file(s) deleted.\n" ); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
746 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
747 or |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
748 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
749 printf(count + " file%s deleted.\n", $count == 1 ? '' : 's'); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
750 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
751 I<NOTE: javascript lacks a builtin printf, so the above isn't a working example> |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
752 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
753 The first example looks awkward, the second will only work in English |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
754 and languages with similar plural rules. Before ngettext() was introduced, |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
755 the best practice for internationalized programs was: |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
756 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
757 if (count == 1) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
758 alert( gettext("One file deleted.\n") ); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
759 } else { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
760 printf( gettext("%d files deleted.\n"), count ); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
761 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
762 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
763 This is a nuisance for the programmer and often still not sufficient |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
764 for an adequate translation. Many languages have completely different |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
765 ideas on numerals. Some (French, Italian, ...) treat 0 and 1 alike, |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
766 others make no distinction at all (Japanese, Korean, Chinese, ...), |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
767 others have two or more plural forms (Russian, Latvian, Czech, |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
768 Polish, ...). The solution is: |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
769 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
770 printf( ngettext("One file deleted.\n", |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
771 "%d files deleted.\n", |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
772 count), // argument to ngettext! |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
773 count); // argument to printf! |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
774 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
775 In English, or if no translation can be found, the first argument |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
776 (B<MSGID>) is picked if C<count> is one, the second one otherwise. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
777 For other languages, the correct plural form (of 1, 2, 3, 4, ...) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
778 is automatically picked, too. You don't have to know anything about |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
779 the plural rules in the target language, ngettext() will take care |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
780 of that. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
781 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
782 This is most of the time sufficient but you will have to prove your |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
783 creativity in cases like |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
784 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
785 "%d file(s) deleted, and %d file(s) created.\n" |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
786 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
787 That said, javascript lacks C<printf()> support. Supplied with Gettext.js |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
788 is the C<strargs()> method, which can be used for these cases: |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
789 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
790 Gettext.strargs( gt.ngettext( "One file deleted.\n", |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
791 "%d files deleted.\n", |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
792 count), // argument to ngettext! |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
793 count); // argument to strargs! |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
794 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
795 NOTE: the variable replacement isn't done for you, so you must |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
796 do it yourself as in the above. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
797 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
798 =head2 dngettext( TEXTDOMAIN, MSGID, MSGID_PLURAL, COUNT ) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
799 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
800 Like ngettext() but retrieves the translation from the specified |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
801 textdomain instead of the default domain. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
802 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
803 =head2 dcngettext( TEXTDOMAIN, MSGID, MSGID_PLURAL, COUNT, CATEGORY ) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
804 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
805 Like dngettext() but retrieves the translation from the specified |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
806 category, instead of the default category C<LC_MESSAGES>. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
807 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
808 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
809 =head2 pgettext( MSGCTXT, MSGID ) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
810 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
811 Returns the translation of MSGID, given the context of MSGCTXT. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
812 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
813 Both items are used as a unique key into the message catalog. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
814 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
815 This allows the translator to have two entries for words that may |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
816 translate to different foreign words based on their context. For |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
817 example, the word "View" may be a noun or a verb, which may be |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
818 used in a menu as File->View or View->Source. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
819 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
820 alert( pgettext( "Verb: To View", "View" ) ); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
821 alert( pgettext( "Noun: A View", "View" ) ); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
822 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
823 The above will both lookup different entries in the message catalog. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
824 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
825 In English, or if no translation can be found, the second argument |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
826 (B<MSGID>) is returned. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
827 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
828 =head2 dpgettext( TEXTDOMAIN, MSGCTXT, MSGID ) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
829 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
830 Like pgettext(), but retrieves the message for the specified |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
831 B<TEXTDOMAIN> instead of the default domain. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
832 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
833 =head2 dcpgettext( TEXTDOMAIN, MSGCTXT, MSGID, CATEGORY ) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
834 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
835 Like dpgettext() but retrieves the message from the specified B<CATEGORY> |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
836 instead of the default category C<LC_MESSAGES>. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
837 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
838 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
839 =head2 npgettext( MSGCTXT, MSGID, MSGID_PLURAL, COUNT ) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
840 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
841 Like ngettext() with the addition of context as in pgettext(). |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
842 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
843 In English, or if no translation can be found, the second argument |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
844 (MSGID) is picked if B<COUNT> is one, the third one otherwise. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
845 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
846 =head2 dnpgettext( TEXTDOMAIN, MSGCTXT, MSGID, MSGID_PLURAL, COUNT ) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
847 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
848 Like npgettext() but retrieves the translation from the specified |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
849 textdomain instead of the default domain. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
850 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
851 =head2 dcnpgettext( TEXTDOMAIN, MSGCTXT, MSGID, MSGID_PLURAL, COUNT, CATEGORY ) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
852 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
853 Like dnpgettext() but retrieves the translation from the specified |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
854 category, instead of the default category C<LC_MESSAGES>. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
855 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
856 =cut |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
857 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
858 */ |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
859 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
860 // gettext |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
861 Gettext.prototype.gettext = function (msgid) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
862 var msgctxt; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
863 var msgid_plural; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
864 var n; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
865 var category; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
866 return this.dcnpgettext(null, msgctxt, msgid, msgid_plural, n, category); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
867 }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
868 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
869 Gettext.prototype.dgettext = function (domain, msgid) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
870 var msgctxt; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
871 var msgid_plural; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
872 var n; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
873 var category; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
874 return this.dcnpgettext(domain, msgctxt, msgid, msgid_plural, n, category); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
875 }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
876 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
877 Gettext.prototype.dcgettext = function (domain, msgid, category) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
878 var msgctxt; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
879 var msgid_plural; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
880 var n; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
881 return this.dcnpgettext(domain, msgctxt, msgid, msgid_plural, n, category); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
882 }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
883 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
884 // ngettext |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
885 Gettext.prototype.ngettext = function (msgid, msgid_plural, n) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
886 var msgctxt; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
887 var category; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
888 return this.dcnpgettext(null, msgctxt, msgid, msgid_plural, n, category); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
889 }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
890 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
891 Gettext.prototype.dngettext = function (domain, msgid, msgid_plural, n) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
892 var msgctxt; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
893 var category; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
894 return this.dcnpgettext(domain, msgctxt, msgid, msgid_plural, n, category); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
895 }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
896 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
897 Gettext.prototype.dcngettext = function (domain, msgid, msgid_plural, n, category) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
898 var msgctxt; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
899 return this.dcnpgettext(domain, msgctxt, msgid, msgid_plural, n, category, category); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
900 }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
901 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
902 // pgettext |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
903 Gettext.prototype.pgettext = function (msgctxt, msgid) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
904 var msgid_plural; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
905 var n; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
906 var category; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
907 return this.dcnpgettext(null, msgctxt, msgid, msgid_plural, n, category); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
908 }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
909 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
910 Gettext.prototype.dpgettext = function (domain, msgctxt, msgid) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
911 var msgid_plural; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
912 var n; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
913 var category; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
914 return this.dcnpgettext(domain, msgctxt, msgid, msgid_plural, n, category); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
915 }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
916 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
917 Gettext.prototype.dcpgettext = function (domain, msgctxt, msgid, category) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
918 var msgid_plural; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
919 var n; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
920 return this.dcnpgettext(domain, msgctxt, msgid, msgid_plural, n, category); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
921 }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
922 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
923 // npgettext |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
924 Gettext.prototype.npgettext = function (msgctxt, msgid, msgid_plural, n) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
925 var category; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
926 return this.dcnpgettext(null, msgctxt, msgid, msgid_plural, n, category); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
927 }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
928 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
929 Gettext.prototype.dnpgettext = function (domain, msgctxt, msgid, msgid_plural, n) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
930 var category; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
931 return this.dcnpgettext(domain, msgctxt, msgid, msgid_plural, n, category); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
932 }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
933 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
934 // this has all the options, so we use it for all of them. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
935 Gettext.prototype.dcnpgettext = function (domain, msgctxt, msgid, msgid_plural, n, category) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
936 if (! this.isValidObject(msgid)) return ''; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
937 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
938 var plural = this.isValidObject(msgid_plural); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
939 var msg_ctxt_id = this.isValidObject(msgctxt) ? msgctxt+Gettext.context_glue+msgid : msgid; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
940 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
941 var domainname = this.isValidObject(domain) ? domain : |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
942 this.isValidObject(this.domain) ? this.domain : |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
943 'messages'; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
944 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
945 // category is always LC_MESSAGES. We ignore all else |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
946 var category_name = 'LC_MESSAGES'; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
947 var category = 5; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
948 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
949 var locale_data = new Array(); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
950 if (typeof(Gettext._locale_data) != 'undefined' && |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
951 this.isValidObject(Gettext._locale_data[domainname])) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
952 locale_data.push( Gettext._locale_data[domainname] ); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
953 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
954 } else if (typeof(Gettext._locale_data) != 'undefined') { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
955 // didn't find domain we're looking for. Search all of them. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
956 for (var dom in Gettext._locale_data) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
957 locale_data.push( Gettext._locale_data[dom] ); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
958 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
959 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
960 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
961 var trans = []; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
962 var found = false; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
963 var domain_used; // so we can find plural-forms if needed |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
964 if (locale_data.length) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
965 for (var i=0; i<locale_data.length; i++) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
966 var locale = locale_data[i]; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
967 if (this.isValidObject(locale.msgs[msg_ctxt_id])) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
968 // make copy of that array (cause we'll be destructive) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
969 for (var j=0; j<locale.msgs[msg_ctxt_id].length; j++) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
970 trans[j] = locale.msgs[msg_ctxt_id][j]; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
971 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
972 trans.shift(); // throw away the msgid_plural |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
973 domain_used = locale; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
974 found = true; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
975 // only break if found translation actually has a translation. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
976 if ( trans.length > 0 && trans[0].length != 0 ) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
977 break; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
978 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
979 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
980 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
981 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
982 // default to english if we lack a match, or match has zero length |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
983 if ( trans.length == 0 || trans[0].length == 0 ) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
984 trans = [ msgid, msgid_plural ]; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
985 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
986 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
987 var translation = trans[0]; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
988 if (plural) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
989 var p; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
990 if (found && this.isValidObject(domain_used.head.plural_func) ) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
991 var rv = domain_used.head.plural_func(n); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
992 if (! rv.plural) rv.plural = 0; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
993 if (! rv.nplural) rv.nplural = 0; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
994 // if plurals returned is out of bound for total plural forms |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
995 if (rv.nplural <= rv.plural) rv.plural = 0; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
996 p = rv.plural; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
997 } else { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
998 p = (n != 1) ? 1 : 0; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
999 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1000 if (this.isValidObject(trans[p])) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1001 translation = trans[p]; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1002 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1003 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1004 return translation; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1005 }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1006 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1007 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1008 /* |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1009 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1010 =head2 strargs (string, argument_array) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1011 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1012 string : a string that potentially contains formatting characters. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1013 argument_array : an array of positional replacement values |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1014 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1015 This is a utility method to provide some way to support positional parameters within a string, as javascript lacks a printf() method. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1016 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1017 The format is similar to printf(), but greatly simplified (ie. fewer features). |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1018 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1019 Any percent signs followed by numbers are replaced with the corrosponding item from the B<argument_array>. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1020 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1021 Example: |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1022 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1023 var string = "%2 roses are red, %1 violets are blue"; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1024 var args = new Array("10", "15"); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1025 var result = Gettext.strargs(string, args); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1026 // result is "15 roses are red, 10 violets are blue" |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1027 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1028 The format numbers are 1 based, so the first itme is %1. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1029 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1030 A lone percent sign may be escaped by preceeding it with another percent sign. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1031 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1032 A percent sign followed by anything other than a number or another percent sign will be passed through as is. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1033 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1034 Some more examples should clear up any abmiguity. The following were called with the orig string, and the array as Array("[one]", "[two]") : |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1035 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1036 orig string "blah" becomes "blah" |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1037 orig string "" becomes "" |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1038 orig string "%%" becomes "%" |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1039 orig string "%%%" becomes "%%" |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1040 orig string "%%%%" becomes "%%" |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1041 orig string "%%%%%" becomes "%%%" |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1042 orig string "tom%%dick" becomes "tom%dick" |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1043 orig string "thing%1bob" becomes "thing[one]bob" |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1044 orig string "thing%1%2bob" becomes "thing[one][two]bob" |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1045 orig string "thing%1asdf%2asdf" becomes "thing[one]asdf[two]asdf" |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1046 orig string "%1%2%3" becomes "[one][two]" |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1047 orig string "tom%1%%2%aDick" becomes "tom[one]%2%aDick" |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1048 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1049 This is especially useful when using plurals, as the string will nearly always contain the number. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1050 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1051 It's also useful in translated strings where the translator may have needed to move the position of the parameters. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1052 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1053 For example: |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1054 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1055 var count = 14; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1056 Gettext.strargs( gt.ngettext('one banana', '%1 bananas', count), [count] ); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1057 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1058 NOTE: this may be called as an instance method, or as a class method. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1059 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1060 // instance method: |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1061 var gt = new Gettext(params); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1062 gt.strargs(string, args); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1063 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1064 // class method: |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1065 Gettext.strargs(string, args); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1066 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1067 =cut |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1068 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1069 */ |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1070 /* utility method, since javascript lacks a printf */ |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1071 Gettext.strargs = function (str, args) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1072 // make sure args is an array |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1073 if ( null == args || |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1074 'undefined' == typeof(args) ) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1075 args = []; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1076 } else if (args.constructor != Array) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1077 args = [args]; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1078 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1079 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1080 // NOTE: javascript lacks support for zero length negative look-behind |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1081 // in regex, so we must step through w/ index. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1082 // The perl equiv would simply be: |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1083 // $string =~ s/(?<!\%)\%([0-9]+)/$args[$1]/g; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1084 // $string =~ s/\%\%/\%/g; # restore escaped percent signs |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1085 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1086 var newstr = ""; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1087 while (true) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1088 var i = str.indexOf('%'); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1089 var match_n; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1090 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1091 // no more found. Append whatever remains |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1092 if (i == -1) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1093 newstr += str; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1094 break; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1095 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1096 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1097 // we found it, append everything up to that |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1098 newstr += str.substr(0, i); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1099 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1100 // check for escpaed %% |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1101 if (str.substr(i, 2) == '%%') { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1102 newstr += '%'; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1103 str = str.substr((i+2)); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1104 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1105 // % followed by number |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1106 } else if ( match_n = str.substr(i).match(/^%(\d+)/) ) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1107 var arg_n = parseInt(match_n[1]); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1108 var length_n = match_n[1].length; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1109 if ( arg_n > 0 && args[arg_n -1] != null && typeof(args[arg_n -1]) != 'undefined' ) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1110 newstr += args[arg_n -1]; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1111 str = str.substr( (i + 1 + length_n) ); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1112 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1113 // % followed by some other garbage - just remove the % |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1114 } else { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1115 newstr += '%'; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1116 str = str.substr((i+1)); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1117 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1118 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1119 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1120 return newstr; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1121 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1122 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1123 /* instance method wrapper of strargs */ |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1124 Gettext.prototype.strargs = function (str, args) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1125 return Gettext.strargs(str, args); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1126 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1127 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1128 /* verify that something is an array */ |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1129 Gettext.prototype.isArray = function (thisObject) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1130 return this.isValidObject(thisObject) && thisObject.constructor == Array; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1131 }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1132 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1133 /* verify that an object exists and is valid */ |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1134 Gettext.prototype.isValidObject = function (thisObject) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1135 if (null == thisObject) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1136 return false; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1137 } else if ('undefined' == typeof(thisObject) ) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1138 return false; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1139 } else { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1140 return true; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1141 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1142 }; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1143 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1144 Gettext.prototype.sjax = function (uri) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1145 var xmlhttp; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1146 if (window.XMLHttpRequest) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1147 xmlhttp = new XMLHttpRequest(); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1148 } else if (navigator.userAgent.toLowerCase().indexOf('msie 5') != -1) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1149 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1150 } else { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1151 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1152 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1153 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1154 if (! xmlhttp) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1155 throw new Error("Your browser doesn't do Ajax. Unable to support external language files."); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1156 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1157 xmlhttp.open('GET', uri, false); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1158 try { xmlhttp.send(null); } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1159 catch (e) { return; } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1160 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1161 // we consider status 200 and 0 as ok. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1162 // 0 happens when we request local file, allowing this to run on local files |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1163 var sjax_status = xmlhttp.status; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1164 if (sjax_status == 200 || sjax_status == 0) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1165 return xmlhttp.responseText; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1166 } else { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1167 var error = xmlhttp.statusText + " (Error " + xmlhttp.status + ")"; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1168 if (xmlhttp.responseText.length) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1169 error += "\n" + xmlhttp.responseText; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1170 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1171 alert(error); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1172 return; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1173 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1174 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1175 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1176 Gettext.prototype.JSON = function (data) { |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1177 return eval('(' + data + ')'); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1178 } |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1179 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1180 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1181 /* |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1182 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1183 =head1 NOTES |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1184 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1185 These are some notes on the internals |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1186 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1187 =over |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1188 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1189 =item LOCALE CACHING |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1190 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1191 Loaded locale data is currently cached class-wide. This means that if two scripts are both using Gettext.js, and both share the same gettext domain, that domain will only be loaded once. This will allow you to grab a new object many times from different places, utilize the same domain, and share a single translation file. The downside is that a domain won't be RE-loaded if a new object is instantiated on a domain that had already been instantiated. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1192 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1193 =back |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1194 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1195 =head1 BUGS / TODO |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1196 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1197 =over |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1198 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1199 =item error handling |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1200 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1201 Currently, there are several places that throw errors. In GNU Gettext, there are no fatal errors, which allows text to still be displayed regardless of how broken the environment becomes. We should evaluate and determine where we want to stand on that issue. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1202 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1203 =item syncronous only support (no ajax support) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1204 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1205 Currently, fetching language data is done purely syncronous, which means the page will halt while those files are fetched/loaded. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1206 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1207 This is often what you want, as then following translation requests will actually be translated. However, if all your calls are done dynamically (ie. error handling only or something), loading in the background may be more adventagous. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1208 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1209 It's still recommended to use the statically defined <script ...> method, which should have the same delay, but it will cache the result. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1210 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1211 =item domain support |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1212 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1213 domain support while using shortcut methods like C<_('string')> or C<i18n('string')>. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1214 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1215 Under normal apps, the domain is usually set globally to the app, and a single language file is used. Under javascript, you may have multiple libraries or applications needing translation support, but the namespace is essentially global. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1216 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1217 It's recommended that your app initialize it's own shortcut with it's own domain. (See examples/wrapper/i18n.js for an example.) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1218 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1219 Basically, you'll want to accomplish something like this: |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1220 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1221 // in some other .js file that needs i18n |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1222 this.i18nObj = new i18n; |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1223 this.i18n = this.i18nObj.init('domain'); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1224 // do translation |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1225 alert( this.i18n("string") ); |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1226 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1227 If you use this raw Gettext object, then this is all handled for you, as you have your own object then, and will be calling C<myGettextObject.gettext('string')> and such. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1228 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1229 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1230 =item encoding |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1231 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1232 May want to add encoding/reencoding stuff. See GNU iconv, or the perl module Locale::Recode from libintl-perl. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1233 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1234 =back |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1235 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1236 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1237 =head1 COMPATABILITY |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1238 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1239 This has been tested on the following browsers. It may work on others, but these are all those to which I have access. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1240 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1241 FF1.5, FF2, FF3, IE6, IE7, Opera9, Opera10, Safari3.1, Chrome |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1242 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1243 *FF = Firefox |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1244 *IE = Internet Explorer |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1245 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1246 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1247 =head1 REQUIRES |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1248 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1249 bin/po2json requires perl, and the perl modules Locale::PO and JSON. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1250 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1251 =head1 SEE ALSO |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1252 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1253 bin/po2json (included), |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1254 examples/normal/index.html, |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1255 examples/wrapper/i18n.html, examples/wrapper/i18n.js, |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1256 Locale::gettext_pp(3pm), POSIX(3pm), gettext(1), gettext(3) |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1257 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1258 =head1 AUTHOR |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1259 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1260 Copyright (C) 2008, Joshua I. Miller E<lt>unrtst@cpan.orgE<gt>, all rights reserved. See the source code for details. |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1261 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1262 =cut |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1263 |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1264 */ |
6356e78ccf5c
new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff
changeset
|
1265 |