瀏覽代碼

Adds multi language support for notifications.

master
hristoterezov 10 年之前
父節點
當前提交
79cdd94833

+ 1
- 1
index.html 查看文件

19
     <script src="libs/popover.js?v=1"></script><!-- bootstrap tooltip lib -->
19
     <script src="libs/popover.js?v=1"></script><!-- bootstrap tooltip lib -->
20
     <script src="libs/toastr.js?v=1"></script><!-- notifications lib -->
20
     <script src="libs/toastr.js?v=1"></script><!-- notifications lib -->
21
     <script src="interface_config.js?v=5"></script>
21
     <script src="interface_config.js?v=5"></script>
22
-    <script src="libs/app.bundle.js?v=10"></script>
22
+    <script src="libs/app.bundle.js?v=11"></script>
23
 
23
 
24
     <script src="analytics.js?v=1"></script><!-- google analytics plugin -->
24
     <script src="analytics.js?v=1"></script><!-- google analytics plugin -->
25
     <link rel="stylesheet" href="css/font.css?v=6"/>
25
     <link rel="stylesheet" href="css/font.css?v=6"/>

+ 7
- 1
lang/main.json 查看文件

108
     "notify": {
108
     "notify": {
109
         "disconnected": "disconnected",
109
         "disconnected": "disconnected",
110
         "moderator": "Moderator rights granted !",
110
         "moderator": "Moderator rights granted !",
111
-        "connected": "connected"
111
+        "connected": "connected",
112
+        "somebody": "Somebody",
113
+        "me": "Me",
114
+        "focus": "Conference focus",
115
+        "focusFail": "__component__ not available - retry in __ms__ sec",
116
+        "grantedTo": "Moderator rights granted to __to__!",
117
+        "grantedToUnknown": "Moderator rights granted to $t(somebody)!"
112
 
118
 
113
     }
119
     }
114
 
120
 

+ 55
- 25
libs/app.bundle.js 查看文件

1625
     console.log('left.muc', jid);
1625
     console.log('left.muc', jid);
1626
     var displayName = $('#participant_' + Strophe.getResourceFromJid(jid) +
1626
     var displayName = $('#participant_' + Strophe.getResourceFromJid(jid) +
1627
         '>.displayname').html();
1627
         '>.displayname').html();
1628
-    messageHandler.notify(displayName || 'Somebody',
1628
+    messageHandler.notify(displayName,'notify.somebody', "Somebody",
1629
         'disconnected',
1629
         'disconnected',
1630
-        'disconnected');
1630
+        'notify.disconnected', "disconnected");
1631
     // Need to call this with a slight delay, otherwise the element couldn't be
1631
     // Need to call this with a slight delay, otherwise the element couldn't be
1632
     // found for some reason.
1632
     // found for some reason.
1633
     // XXX(gp) it works fine without the timeout for me (with Chrome 38).
1633
     // XXX(gp) it works fine without the timeout for me (with Chrome 38).
1659
 
1659
 
1660
     if (isModerator) {
1660
     if (isModerator) {
1661
         Authentication.closeAuthenticationWindow();
1661
         Authentication.closeAuthenticationWindow();
1662
-        messageHandler.notify(
1663
-            'Me', 'connected', 'Moderator rights granted !');
1662
+        messageHandler.notify(null, "notify.me",
1663
+            'Me', 'connected', "notify.moderator",
1664
+            'Moderator rights granted !');
1664
     }
1665
     }
1665
 }
1666
 }
1666
 
1667
 
1704
     );
1705
     );
1705
 }
1706
 }
1706
 function onMucEntered(jid, id, displayName) {
1707
 function onMucEntered(jid, id, displayName) {
1707
-    messageHandler.notify(displayName || 'Somebody',
1708
+    messageHandler.notify(displayName,'notify.somebody', "Somebody",
1708
         'connected',
1709
         'connected',
1709
-        'connected');
1710
+        'notify.connected', "connected");
1710
 
1711
 
1711
     // Add Peer's container
1712
     // Add Peer's container
1712
     VideoLayout.ensurePeerContainerExists(jid,id);
1713
     VideoLayout.ensurePeerContainerExists(jid,id);
1721
     VideoLayout.showModeratorIndicator();
1722
     VideoLayout.showModeratorIndicator();
1722
 
1723
 
1723
     if (role === 'moderator') {
1724
     if (role === 'moderator') {
1724
-        var displayName = displayName;
1725
-        if (!displayName) {
1726
-            displayName = 'Somebody';
1725
+        var messageKey, messageOptions = {};
1726
+        var lDisplayName = displayName;
1727
+        if (!lDisplayName) {
1728
+            lDisplayName = 'Somebody';
1729
+            messageKey = "notify.grantedToUnknown";
1730
+        }
1731
+        else
1732
+        {
1733
+            messageKey = "notify.grantedTo";
1734
+            messageOptions = {to: displayName};
1727
         }
1735
         }
1728
         messageHandler.notify(
1736
         messageHandler.notify(
1729
-            displayName,
1730
-            'connected',
1731
-                'Moderator rights granted to ' + displayName + '!');
1737
+            displayName,'notify.somebody', "Somebody",
1738
+            'connected', messageKey,
1739
+            'Moderator rights granted to ' + lDisplayName + '!',
1740
+            messageOptions);
1732
     }
1741
     }
1733
 }
1742
 }
1734
 
1743
 
5520
         messageHandler.openMessageDialog(title, message);
5529
         messageHandler.openMessageDialog(title, message);
5521
     };
5530
     };
5522
 
5531
 
5523
-    my.notify = function(displayName, cls, message) {
5532
+    my.notify = function(displayName, displayNameKey, displayNameDefault,
5533
+                         cls, messageKey, messageDefault, messageArguments) {
5534
+        var displayNameSpan = '<span class="nickname" ';
5535
+        if(displayName)
5536
+        {
5537
+            displayNameSpan += ">" + displayName;
5538
+        }
5539
+        else
5540
+        {
5541
+            displayNameSpan += "data-i18n='" + displayNameKey +
5542
+                "'>" + APP.translation.translateString(displayNameKey, null,
5543
+                {defaultValue: displayNameDefault});
5544
+        }
5545
+        displayNameSpan += "</span>";
5546
+        var lMessageArguments = messageArguments;
5547
+        if(!messageArguments)
5548
+            lMessageArguments = {};
5549
+        lMessageArguments.defaultValue = messageDefault;
5524
         toastr.info(
5550
         toastr.info(
5525
-            '<span class="nickname">' +
5526
-                displayName +
5527
-            '</span><br>' +
5528
-            '<span class=' + cls + '>' +
5529
-                message +
5551
+            displayNameSpan + '<br>' +
5552
+            '<span class=' + cls + ' data-i18n="' + messageKey + '"' +
5553
+                (messageArguments?
5554
+                    " i18n-options='" + JSON.stringify(messageArguments) + "'"
5555
+                    : "") + ">" +
5556
+            APP.translation.translateString(messageKey, null,
5557
+                lMessageArguments) +
5530
             '</span>');
5558
             '</span>');
5531
     };
5559
     };
5532
 
5560
 
7507
                     "top");
7535
                     "top");
7508
                 videoMutedSpan.appendChild(mutedIndicator);
7536
                 videoMutedSpan.appendChild(mutedIndicator);
7509
                 //translate texts for muted indicator
7537
                 //translate texts for muted indicator
7510
-                APP.translation.translateElement($('#' + videoSpanId  + " > i"));
7538
+                APP.translation.translateElement($('#' + videoSpanId  + " > span > i"));
7511
             }
7539
             }
7512
 
7540
 
7513
             VideoLayout.updateMutePosition(videoSpanId);
7541
             VideoLayout.updateMutePosition(videoSpanId);
11443
             options.lng = lang;
11471
             options.lng = lang;
11444
         i18n.init(options, initCompleted);
11472
         i18n.init(options, initCompleted);
11445
     },
11473
     },
11446
-    translateString: function (key, cb) {
11474
+    translateString: function (key, cb, defaultValue) {
11447
         if(!cb)
11475
         if(!cb)
11448
-            return i18n.t(key);
11476
+            return i18n.t(key, defaultValue);
11449
 
11477
 
11450
         if(initialized)
11478
         if(initialized)
11451
         {
11479
         {
11452
-            cb(i18n.t(key));
11480
+            cb(i18n.t(key, defaultValue));
11453
         }
11481
         }
11454
         else
11482
         else
11455
         {
11483
         {
14506
                 var waitMs = getNextErrorTimeout();
14534
                 var waitMs = getNextErrorTimeout();
14507
                 console.error("Focus error, retry after " + waitMs, error);
14535
                 console.error("Focus error, retry after " + waitMs, error);
14508
                 // Show message
14536
                 // Show message
14509
-                APP.UI.messageHandler.notify(
14510
-                    'Conference focus', 'disconnected',
14537
+                APP.UI.messageHandler.notify( null, "notify.focus",
14538
+                    'Conference focus', 'disconnected',"notify.focusFail",
14511
                         Moderator.getFocusComponent() +
14539
                         Moderator.getFocusComponent() +
14512
                         ' not available - retry in ' +
14540
                         ' not available - retry in ' +
14513
-                        (waitMs / 1000) + ' sec');
14541
+                        (waitMs / 1000) + ' sec',
14542
+                    {component: Moderator.getFocusComponent(),
14543
+                        ms: (waitMs / 1000)});
14514
                 // Reset response timeout
14544
                 // Reset response timeout
14515
                 getNextTimeout(true);
14545
                 getNextTimeout(true);
14516
                 window.setTimeout(
14546
                 window.setTimeout(

+ 21
- 12
modules/UI/UI.js 查看文件

390
     console.log('left.muc', jid);
390
     console.log('left.muc', jid);
391
     var displayName = $('#participant_' + Strophe.getResourceFromJid(jid) +
391
     var displayName = $('#participant_' + Strophe.getResourceFromJid(jid) +
392
         '>.displayname').html();
392
         '>.displayname').html();
393
-    messageHandler.notify(displayName || 'Somebody',
393
+    messageHandler.notify(displayName,'notify.somebody', "Somebody",
394
         'disconnected',
394
         'disconnected',
395
-        'disconnected');
395
+        'notify.disconnected', "disconnected");
396
     // Need to call this with a slight delay, otherwise the element couldn't be
396
     // Need to call this with a slight delay, otherwise the element couldn't be
397
     // found for some reason.
397
     // found for some reason.
398
     // XXX(gp) it works fine without the timeout for me (with Chrome 38).
398
     // XXX(gp) it works fine without the timeout for me (with Chrome 38).
424
 
424
 
425
     if (isModerator) {
425
     if (isModerator) {
426
         Authentication.closeAuthenticationWindow();
426
         Authentication.closeAuthenticationWindow();
427
-        messageHandler.notify(
428
-            'Me', 'connected', 'Moderator rights granted !');
427
+        messageHandler.notify(null, "notify.me",
428
+            'Me', 'connected', "notify.moderator",
429
+            'Moderator rights granted !');
429
     }
430
     }
430
 }
431
 }
431
 
432
 
469
     );
470
     );
470
 }
471
 }
471
 function onMucEntered(jid, id, displayName) {
472
 function onMucEntered(jid, id, displayName) {
472
-    messageHandler.notify(displayName || 'Somebody',
473
+    messageHandler.notify(displayName,'notify.somebody', "Somebody",
473
         'connected',
474
         'connected',
474
-        'connected');
475
+        'notify.connected', "connected");
475
 
476
 
476
     // Add Peer's container
477
     // Add Peer's container
477
     VideoLayout.ensurePeerContainerExists(jid,id);
478
     VideoLayout.ensurePeerContainerExists(jid,id);
486
     VideoLayout.showModeratorIndicator();
487
     VideoLayout.showModeratorIndicator();
487
 
488
 
488
     if (role === 'moderator') {
489
     if (role === 'moderator') {
489
-        var displayName = displayName;
490
-        if (!displayName) {
491
-            displayName = 'Somebody';
490
+        var messageKey, messageOptions = {};
491
+        var lDisplayName = displayName;
492
+        if (!lDisplayName) {
493
+            lDisplayName = 'Somebody';
494
+            messageKey = "notify.grantedToUnknown";
495
+        }
496
+        else
497
+        {
498
+            messageKey = "notify.grantedTo";
499
+            messageOptions = {to: displayName};
492
         }
500
         }
493
         messageHandler.notify(
501
         messageHandler.notify(
494
-            displayName,
495
-            'connected',
496
-                'Moderator rights granted to ' + displayName + '!');
502
+            displayName,'notify.somebody', "Somebody",
503
+            'connected', messageKey,
504
+            'Moderator rights granted to ' + lDisplayName + '!',
505
+            messageOptions);
497
     }
506
     }
498
 }
507
 }
499
 
508
 

+ 25
- 6
modules/UI/util/MessageHandler.js 查看文件

149
         messageHandler.openMessageDialog(title, message);
149
         messageHandler.openMessageDialog(title, message);
150
     };
150
     };
151
 
151
 
152
-    my.notify = function(displayName, cls, message) {
152
+    my.notify = function(displayName, displayNameKey, displayNameDefault,
153
+                         cls, messageKey, messageDefault, messageArguments) {
154
+        var displayNameSpan = '<span class="nickname" ';
155
+        if(displayName)
156
+        {
157
+            displayNameSpan += ">" + displayName;
158
+        }
159
+        else
160
+        {
161
+            displayNameSpan += "data-i18n='" + displayNameKey +
162
+                "'>" + APP.translation.translateString(displayNameKey, null,
163
+                {defaultValue: displayNameDefault});
164
+        }
165
+        displayNameSpan += "</span>";
166
+        var lMessageArguments = messageArguments;
167
+        if(!messageArguments)
168
+            lMessageArguments = {};
169
+        lMessageArguments.defaultValue = messageDefault;
153
         toastr.info(
170
         toastr.info(
154
-            '<span class="nickname">' +
155
-                displayName +
156
-            '</span><br>' +
157
-            '<span class=' + cls + '>' +
158
-                message +
171
+            displayNameSpan + '<br>' +
172
+            '<span class=' + cls + ' data-i18n="' + messageKey + '"' +
173
+                (messageArguments?
174
+                    " i18n-options='" + JSON.stringify(messageArguments) + "'"
175
+                    : "") + ">" +
176
+            APP.translation.translateString(messageKey, null,
177
+                lMessageArguments) +
159
             '</span>');
178
             '</span>');
160
     };
179
     };
161
 
180
 

+ 1
- 1
modules/UI/videolayout/VideoLayout.js 查看文件

1422
                     "top");
1422
                     "top");
1423
                 videoMutedSpan.appendChild(mutedIndicator);
1423
                 videoMutedSpan.appendChild(mutedIndicator);
1424
                 //translate texts for muted indicator
1424
                 //translate texts for muted indicator
1425
-                APP.translation.translateElement($('#' + videoSpanId  + " > i"));
1425
+                APP.translation.translateElement($('#' + videoSpanId  + " > span > i"));
1426
             }
1426
             }
1427
 
1427
 
1428
             VideoLayout.updateMutePosition(videoSpanId);
1428
             VideoLayout.updateMutePosition(videoSpanId);

+ 3
- 3
modules/translation/translation.js 查看文件

82
             options.lng = lang;
82
             options.lng = lang;
83
         i18n.init(options, initCompleted);
83
         i18n.init(options, initCompleted);
84
     },
84
     },
85
-    translateString: function (key, cb) {
85
+    translateString: function (key, cb, defaultValue) {
86
         if(!cb)
86
         if(!cb)
87
-            return i18n.t(key);
87
+            return i18n.t(key, defaultValue);
88
 
88
 
89
         if(initialized)
89
         if(initialized)
90
         {
90
         {
91
-            cb(i18n.t(key));
91
+            cb(i18n.t(key, defaultValue));
92
         }
92
         }
93
         else
93
         else
94
         {
94
         {

+ 5
- 3
modules/xmpp/moderator.js 查看文件

231
                 var waitMs = getNextErrorTimeout();
231
                 var waitMs = getNextErrorTimeout();
232
                 console.error("Focus error, retry after " + waitMs, error);
232
                 console.error("Focus error, retry after " + waitMs, error);
233
                 // Show message
233
                 // Show message
234
-                APP.UI.messageHandler.notify(
235
-                    'Conference focus', 'disconnected',
234
+                APP.UI.messageHandler.notify( null, "notify.focus",
235
+                    'Conference focus', 'disconnected',"notify.focusFail",
236
                         Moderator.getFocusComponent() +
236
                         Moderator.getFocusComponent() +
237
                         ' not available - retry in ' +
237
                         ' not available - retry in ' +
238
-                        (waitMs / 1000) + ' sec');
238
+                        (waitMs / 1000) + ' sec',
239
+                    {component: Moderator.getFocusComponent(),
240
+                        ms: (waitMs / 1000)});
239
                 // Reset response timeout
241
                 // Reset response timeout
240
                 getNextTimeout(true);
242
                 getNextTimeout(true);
241
                 window.setTimeout(
243
                 window.setTimeout(

Loading…
取消
儲存