-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.html
80 lines (80 loc) · 3.26 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<html lang="fr">
<head>
<link href="javascript.en.json" lang="en" rel="gettext" />
<link href="javascript.fr.json" lang="fr" rel="gettext" />
<style>
body {
font-family: tahoma;
font-size: 0.8em;
}
pre {
font-family: tahoma;
border: 1px dashed #999;
padding: 10px;
background: #F8F8F8;
}
</style>
</head>
<body>
<h1>Javascript i18n using gettext, jQuery and Python</h1>
<p>
This toolkit uses a combination of gettext, a jQuery plugin and a Python script to enable the internationalization of Javascript files.
</p>
<p>
This technique is to be used before deploying or commiting javascript code. It take the form of a single console command which goes through multiple parsing and conversion steps. After this command is executed, a JSON file is available and can be used via a jQuery plugin.
</p>
<h2>Requirements:</h2>
<ul>
<li><a href="http://www.gnu.org/software/gettext/">Gettext</a></li>
<li><a href="http://www.python.org/">Python 2.5x or 2.6x</a></li>
</ul>
<h2>Sample translated output:</h2>
<pre id="console"></pre>
<h2>Sample javascript code:</h2>
<pre class="code">
function write(txt) {
$("#console").append(txt + "<br/>")
}
write(_("Humpty Dumpty sat on a wall,"));
write(_("Humpty Dumpty had a great fall."));
write(_("All the king's horses, And all the king's men,"));
write(_("Couldn't put Humpty together again."));
</pre>
<h2>Setup needed in the HTML document:</h2>
<pre class="code">
<html lang="fr">
<link href="javascript.en.json" lang="en" rel="gettext" />
<link href="javascript.fr.json" lang="fr" rel="gettext" />
</pre>
<pre class="code">
<script type="text/javascript" src="jquery/jquery.js"></script>
<script type="text/javascript" src="jquery/jquery.gettext.js"></script>
<script type="text/javascript">$.gt.load()</script>
<script type="text/javascript" src="test.js"></script>
</pre>
<h2>Console command and expected output:</h2>
<pre class="code">
<strong>C:\gettext> makemessages.bat</strong>
Extracting keys from javascript code
Merging new keys with existing keys
Converting message files to binary
0 translated messages, 4 untranslated messages.
4 translated messages.
Converting binary files to JSON
Removing temp files
</pre>
<h2>Resulting JSON files:</h2>
<pre class="code">
{
"": "Project-Id-Version: \nReport-Msgid-Bugs-To: \nPOT-Creation-Date: 2009-01-29 14:30-0500\nPO-Revision-Date: 2009-01-30 11:05-0500\nLast-Translator: John Doe <[email protected]>\nLanguage-Team: fr <[email protected]>\nMIME-Version: 1.0\nContent-Type: text/plain; charset=utf-8\nContent-Transfer-Encoding: 8bit\n",
"Couldn't put Humpty together again.": "Ne purent jamais Remonter Humpty.",
"Humpty Dumpty sat on a wall,": "Humpty Dumpty s'assit sur le mur,",
"All the king's horses, And all the king's men,": "Tous les chevaux du roi, Et tous les soldats du roi",
"Humpty Dumpty had a great fall.": "Humpty Dumpty se cassa la figure."
}
</pre>
</body>
<script type="text/javascript" src="jquery/jquery.js"></script>
<script type="text/javascript" src="jquery/jquery.gettext.js"></script>
<script type="text/javascript" src="test.js"></script>
</html>