Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Berry <bryan@olenepal.org>2010-02-28 13:04:51 (GMT)
committer Bryan Berry <bryan@olenepal.org>2010-02-28 13:04:51 (GMT)
commitd5031d8b6a4c94f84341998a9967f288be1125f9 (patch)
treec081455d9eb9782db244076bab53a891d8ce4b87
parentd8d94d6849139ac2e4db6afd5862759ac598153c (diff)
parentc2ffd7a66e70c286df5b886e6afac4820522284e (diff)
fix merge conflicts
-rwxr-xr-xexamples/6_Maths_matchingAnglesAndShapes/index.html1
-rwxr-xr-xexamples/6_Maths_matchingAnglesAndShapes/js/lesson.js83
-rw-r--r--examples/6_Maths_matchingAnglesAndShapes/js/messages.es.json29
l---------examples/6_Maths_matchingAnglesAndShapes/js/messages.json1
-rw-r--r--examples/6_Maths_matchingAnglesAndShapes/js/messages.nl.json18
-rw-r--r--js/jquery.i18n.js19
6 files changed, 142 insertions, 9 deletions
diff --git a/examples/6_Maths_matchingAnglesAndShapes/index.html b/examples/6_Maths_matchingAnglesAndShapes/index.html
index 9c4202f..da1cee4 100755
--- a/examples/6_Maths_matchingAnglesAndShapes/index.html
+++ b/examples/6_Maths_matchingAnglesAndShapes/index.html
@@ -18,6 +18,7 @@
<script type="text/javascript" src="./js/messages.es.json"></script>
<script type="text/javascript" src="../../js/ui.feedback.js"></script>
<script type="text/javascript" src="../../js/karma.js"></script>
+ <script type="text/javascript" src="js/messages.json"></script>
<script type="text/javascript" src="js/lesson.js"></script>
</head>
diff --git a/examples/6_Maths_matchingAnglesAndShapes/js/lesson.js b/examples/6_Maths_matchingAnglesAndShapes/js/lesson.js
index 2aff46c..5bff562 100755
--- a/examples/6_Maths_matchingAnglesAndShapes/js/lesson.js
+++ b/examples/6_Maths_matchingAnglesAndShapes/js/lesson.js
@@ -1,5 +1,49 @@
-$(document).ready(function() {
+/*
+Bugs (firefox 3.5.7):
+* sometimes mulitple cards are shown
+* the image of one of the angles is not showing properly
+* if you have a text without a hyphen it doesn't work (e.g. angulo
+recto iso angulo-recto)
+* the text for angulo-obtuso is not displaying properly
+* title in english: 'matching angles with shapes' should maybe be
+'matching angles and shapes'
+
+Questions:
+* how do we set locale? cfr beginning of $(document).ready()
+
+Peeves:
+* tabs for indenting
+* trailing whitespace everywhere
+
+*/
+// TBD: use jquery plugin instead, http://plugins.jquery.com/project/psprintf
+function format(format_string /*, args*/) {
+ var args = [].slice.call(arguments); // arguments is not a real array
+ args.shift();
+ var result = '';
+ for (var i = 0; i < format_string.length; i += 1) {
+ var c = format_string.charAt(i);
+ if (c == '%') {
+ i += 1; // Breaks on format_string ending with %
+ var c2 = format_string.charAt(i);
+ if (c2 == '%') {
+ result += '%'
+ } else if (c2 == 'd') {
+ result += args.shift();
+ } else {
+ alert('unsupported format character: ' + c2);
+ }
+ } else {
+ result += c;
+ }
+ }
+ return result;
+}
+
+
+$(document).ready(function() {
+ var _ = $._;
var i = 0, j = 0, flag = 0;
var s=0, m=0, h=0;
var clickedObjects = []; //array storing the clicks of the two succesive clicks
@@ -14,14 +58,14 @@ $(document).ready(function() {
var restart = 0; //not restarted
var clickCounter = 0;
var NUM_OBJECTS = 24; //total number of objects in the game
- var shapes_angles = new Array('Acute-Angle','Right-Angle','Obtuse-Angle','Triangle','Square','Rhombus','Rectangle','Parallelogram','Pentagon','Hexagon','Septagon','Octagon','Acute-Angle','Right-Angle','Obtuse-Angle','Triangle','Square','Rhombus','Rectangle','Parallelogram','Pentagon','Hexagon','Septagon','Octagon');
+ var shapes_angles = new Array('Acute-Angle','Right-Angle','Obtuse-Angle','Triangle','Square','Rhombus','Rectangle','Parallelogram','Pentagon','Hexagon','Septagon','Octagon',_('Acute-Angle'),_('Right-Angle'),_('Obtuse-Angle'),_('Triangle'),_('Square'),_('Rhombus'),_('Rectangle'),_('Parallelogram'),_('Pentagon'),_('Hexagon'),_('Septagon'),_('Octagon'));
//var section = $('#section');
var $content = $('#content');
var shapes; //store the current shape or angle name
Karma.scaleWindow();
- $('#kHeader').kHeader({title:"Maths: Matching Angles with Shapes"});
+ $('#kHeader').kHeader({title:_("Maths: Matching Angles with Shapes")});
var $kFooter = $('#kFooter').kFooter({scoreboard: false, startButton: true,
pauseButton: true, restartButton: true, timer: true});
@@ -52,15 +96,42 @@ $(document).ready(function() {
};
+ // example of ngettext usage
+ alert(function(clickCounter, h, m, s) {
+ return format($.i18n.ngettext('You have completed the game in <span class="specialText">%d</span> clicks within <span class="specialText">%d</span> hour,',
+ 'You have completed the game in <span class="specialText">%d</span> clicks within <span class="specialText">%d</span> hours,',
+ h),
+ clickCounter, h)
+ + format($.i18n.ngettext('<span class="specialText">%d</span> minute and ',
+ '<span class="specialText">%d</span> minutes and ',
+ m),
+ m)
+ + format ($.i18n.ngettext('<span class="specialText">%d</span> second.',
+ '<span class="specialText">%d</span> seconds.',
+ s),
+ s);
+ }(10, 2, 3, 1));
var check_game_over = function(){
if(numMatched === NUM_OBJECTS){ //show all
play = 0;
$('#content').html('');
$('#content').append('<div id="gameOver">GAME OVER<br/>Congratulations!!!</div>');
- $('#content').append('<div id="gameOverInfo">You have completed the game in <span class="specialText">'+clickCounter+
- '</span> clicks within <span class="specialText">'+h+'</span> hour <span class="specialText">'+m+
- '</span> minutes and <span class="specialText">'+s+'</span> seconds .</div>');
+ $('#content').append($(document.createElement('div'))
+ .attr({id: 'gameOverInfo'})
+ // clicks < 2 is impossible
+ .html(format($.i18n.ngettext('You have completed the game in <span class="specialText">%d</span> clicks within <span class="specialText">%d</span> hour,',
+ 'You have completed the game in <span class="specialText">%d</span> clicks within <span class="specialText">%d</span> hours,',
+ h),
+ clickCounter, h)
+ + format($.i18n.ngettext('<span class="specialText">%d</span> minute and ',
+ '<span class="specialText">%d</span> minutes and ',
+ m),
+ m)
+ + format ($.i18n.ngettext('<span class="specialText">%d</span> second.',
+ '<span class="specialText">%d</span> seconds.',
+ s),
+ s)));
}
};
diff --git a/examples/6_Maths_matchingAnglesAndShapes/js/messages.es.json b/examples/6_Maths_matchingAnglesAndShapes/js/messages.es.json
index c9be5bd..bad90a9 100644
--- a/examples/6_Maths_matchingAnglesAndShapes/js/messages.es.json
+++ b/examples/6_Maths_matchingAnglesAndShapes/js/messages.es.json
@@ -2,12 +2,25 @@
$.i18n.es = {};
$.i18n.es.strings = {
"default":{
+ 'Acute-Angle' : 'Ángulo-agudo',
+ 'Right-Angle' : 'Ángulo-recto',
+ 'Obtuse-Angle' : 'Ángulo-obtuso',
+ 'Triangle' : 'Triángulo',
+ 'Square' : 'Cuadrado',
+ 'Rhombus' : 'Rombo',
+ 'Rectangle' : 'Rectángulo',
+ 'Parallelogram' : 'Paralelogramo',
+ 'Pentagon' : 'Pentágono',
+ 'Hexagon' : 'Hexágono',
+ 'Septagon' : 'Heptágono',
+ 'Octagon' : 'Octágono',
+ 'Maths: Matching Angles with Shapes' : 'Matemáticas: reunir angulos y formas'
},
"$.ui.kFooter":{
"Play Again": "Repite",
"Pause" : "Pausa",
- "Start" : "Comienza",
+ "Start" : "Comienza",
"Timer" : "Reloj",
"Total" : "Total",
"Score" : "Puntos"
@@ -18,4 +31,16 @@ $.i18n.es.strings = {
}
};
-$(function() { $.i18n.setLocale('es'); }); \ No newline at end of file
+$(function() { $.i18n.setLocale('es'); });
+
+// You can put these inside the dict above, but for now this will be easier to merge.
+$.i18n.es.strings['You have completed the game in <span class="specialText">%d</span> clicks within <span class="specialText">%d</span> hour,'] =
+ ['Has acabado el juego en <span class="specialText">%d</span> clics en <span class="specialText">%d</span> hora,',
+ 'Has acabado el juego en <span class="specialText">%d</span> clics en <span class="specialText">%d</span> horas,'];
+$.i18n.es.strings['<span class="specialText">%d</span> minute and '] =
+ ['<span class="specialText">%d</span> minuto y ',
+ '<span class="specialText">%d</span> minutos y '];
+$.i18n.es.strings['<span class="specialText">%d</span> second.'] =
+ ['<span class="specialText">%d</span> segundo.',
+ '<span class="specialText">%d</span> segundos.'];
+
diff --git a/examples/6_Maths_matchingAnglesAndShapes/js/messages.json b/examples/6_Maths_matchingAnglesAndShapes/js/messages.json
new file mode 120000
index 0000000..0c2aab1
--- /dev/null
+++ b/examples/6_Maths_matchingAnglesAndShapes/js/messages.json
@@ -0,0 +1 @@
+messages.es.json \ No newline at end of file
diff --git a/examples/6_Maths_matchingAnglesAndShapes/js/messages.nl.json b/examples/6_Maths_matchingAnglesAndShapes/js/messages.nl.json
new file mode 100644
index 0000000..bc4c278
--- /dev/null
+++ b/examples/6_Maths_matchingAnglesAndShapes/js/messages.nl.json
@@ -0,0 +1,18 @@
+$.i18n.nl = {};
+$.i18n.nl.strings = {
+ 'Acute-Angle' : 'Scherpe hoek',
+ 'Right-Angle' : 'Rechte hoek',
+ 'Obtuse-Angle' : 'Stompe hoek',
+ 'Triangle' : 'Driehoek',
+ 'Square' : 'Vierkant',
+ 'Rhombus' : 'Ruit',
+ 'Rectangle' : 'Rechthoek',
+ 'Parallelogram' : 'Parallellogram',
+ 'Pentagon' : 'Vijfhoek',
+ 'Hexagon' : 'Zeshoek',
+ 'Septagon' : 'Zevenhoek',
+ 'Octagon' : 'Achthoek',
+ 'Maths: Matching Angles with Shapes' : 'Wiskunde: passende hoeken en vormen zoeken'
+};
+
+$(function() { $.i18n.setLocale('nl'); });
diff --git a/js/jquery.i18n.js b/js/jquery.i18n.js
index 9d9c294..2df5e53 100644
--- a/js/jquery.i18n.js
+++ b/js/jquery.i18n.js
@@ -6,10 +6,11 @@
*/
(function($){
+ // PG: Maybe put everything in namespace i18n and rename the following function $.i18n.gettext?
$.i18n = function(string, locale){
var lang = locale || $.i18n.lang;
- if (!this.i18n[lang] || !this.i18n[lang].strings){
+ if (!$.i18n[lang] || !$.i18n[lang].strings){
return string;
}
return this.i18n[lang].strings['default'][string]||string;
@@ -23,6 +24,22 @@
return this.i18n[lang].strings[context][string]||string;
};
+ // You can override this in messages.<lang>.json.
+ $.i18n.choose_pluralized_msg = function (choices, n) {
+ return n == 1 ? choices[0] : choices[1];
+ }
+
+ $.i18n.ngettext = function (msgid1, msgid2, n) {
+ var lang = $.i18n.lang;
+ if (!$.i18n[lang] || !$.i18n[lang].strings) {
+ return $.choose_pluralized_msg([msgid1, msgid2], n);
+ }
+ // Is using msgid1 as the key ok?
+ return $.i18n.choose_pluralized_msg($.i18n[lang].strings[msgid1]
+ || [msgid1, msgid2],
+ n)
+ }
+
$._ = $.i18n;
$._c = $.i18n.cgettext;