Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/examples/yes_no/js/yes_no.js
blob: 1b8c9a5255f3237017fe7db92d1e18a80aa13795 (plain)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115

$(document).ready(function () {
    
    function _ (msgid) {
	return gt.gettext(msgid);
    }

    var params = { "domain" : "en-US",
	    "locale_data" : json_locale_data
		     };

    var gt = new Gettext(params);
       

    var audio = $('audio').load();

    var localize = function (newlocale) {

	
	var loadLang = function(newlocale) {
	    //loads the .json file that holds the strings 
	    //for the particular locale
	    $('head').append('<script type="text/javascript"' +
			     'src="./locale/' + newlocale +
			     '.json"> </script>');
	    
	    locale_data = json_locale_data[newlocale];

	    // Write translatable strings that are inline
	    for (var i in locale_data){
		if ( i !== ""){
		    $(':contains(' + i + '):last').html(locale_data[i][1]);
		}
       	    }
	    

	   //write translatable strings that are stored in attributes
	   $('img[alt!=""]').each(function(){
	       var alttxt = "";
	       alttxt = $(this).attr("alt");
	       var newalttxt = locale_data[alttxt][1];
	       $(this).attr("alt", newalttxt);
	       
	   });
           

	};

	var loadAssets = function(newlocale) {
	    //if the src attribute is empty,
	    //jquery returns the file name for document
	    $('img[src!=' + window.location + '],' +
	      'audio[src!=' + window.location + ']')
	    .each(function () { 
		var assetsrc = $(this).attr("src")
		.replace(/([^\/]*$)/, newlocale + "_$1");
		$(this).attr('src', assetsrc);
		if ($(this)[0].tagName === "AUDIO"){
		    $(this).load();
		}
	    });
	    
	};


	loadLang(newlocale);
	loadAssets(newlocale);

    };


    //$('#btnLoHE').text(_("Not Hebrew"));  


    var myscore = 0;
    $('#btnYes').click(function () {
	audio[0].play()
	myscore++;
	$("#txtScore").html("" + myscore);
    });
    $('#btnNo').click(function () {
	myscore--;
	audio[1].play()
	$("#txtScore").html("" + myscore);
    });
    $('#btnRestart').click(function () {
	myscore=0;
	audio[2].play()
	$("#txtScore").html("" + myscore);
    });
    
    $('#btnRTL').click(function (){
	$('html[dir=ltr]').width() == null ? $('html').attr('dir', 'ltr') : 
	    $('html').attr('dir','rtl');
    });

    $('#btnLoEN').click(function(){ 
	localize("en-US");
    });

    $('#btnLoNE').click(function (){
	localize("ne-NP");
    });

    $('#btnLoHE').click(function (){
	$('html').attr("dir", "rtl");
	localize("he-IS");
    });

    $('#btnLoES').click(function(){localize("es-SP");});


    
});