浏览代码

Adds multi language support for notifications.

j8
hristoterezov 10 年前
父节点
当前提交
79cdd94833

+ 1
- 1
index.html 查看文件

@@ -19,7 +19,7 @@
19 19
     <script src="libs/popover.js?v=1"></script><!-- bootstrap tooltip lib -->
20 20
     <script src="libs/toastr.js?v=1"></script><!-- notifications lib -->
21 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 24
     <script src="analytics.js?v=1"></script><!-- google analytics plugin -->
25 25
     <link rel="stylesheet" href="css/font.css?v=6"/>

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

@@ -108,7 +108,13 @@
108 108
     "notify": {
109 109
         "disconnected": "disconnected",
110 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,9 +1625,9 @@ function onMucLeft(jid) {
1625 1625
     console.log('left.muc', jid);
1626 1626
     var displayName = $('#participant_' + Strophe.getResourceFromJid(jid) +
1627 1627
         '>.displayname').html();
1628
-    messageHandler.notify(displayName || 'Somebody',
1628
+    messageHandler.notify(displayName,'notify.somebody', "Somebody",
1629 1629
         'disconnected',
1630
-        'disconnected');
1630
+        'notify.disconnected', "disconnected");
1631 1631
     // Need to call this with a slight delay, otherwise the element couldn't be
1632 1632
     // found for some reason.
1633 1633
     // XXX(gp) it works fine without the timeout for me (with Chrome 38).
@@ -1659,8 +1659,9 @@ function onLocalRoleChange(jid, info, pres, isModerator, isExternalAuthEnabled)
1659 1659
 
1660 1660
     if (isModerator) {
1661 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,9 +1705,9 @@ function onPasswordReqiured(callback) {
1704 1705
     );
1705 1706
 }
1706 1707
 function onMucEntered(jid, id, displayName) {
1707
-    messageHandler.notify(displayName || 'Somebody',
1708
+    messageHandler.notify(displayName,'notify.somebody', "Somebody",
1708 1709
         'connected',
1709
-        'connected');
1710
+        'notify.connected', "connected");
1710 1711
 
1711 1712
     // Add Peer's container
1712 1713
     VideoLayout.ensurePeerContainerExists(jid,id);
@@ -1721,14 +1722,22 @@ function onMucRoleChanged(role, displayName) {
1721 1722
     VideoLayout.showModeratorIndicator();
1722 1723
 
1723 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 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,13 +5529,32 @@ var messageHandler = (function(my) {
5520 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 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 5558
             '</span>');
5531 5559
     };
5532 5560
 
@@ -7507,7 +7535,7 @@ var VideoLayout = (function (my) {
7507 7535
                     "top");
7508 7536
                 videoMutedSpan.appendChild(mutedIndicator);
7509 7537
                 //translate texts for muted indicator
7510
-                APP.translation.translateElement($('#' + videoSpanId  + " > i"));
7538
+                APP.translation.translateElement($('#' + videoSpanId  + " > span > i"));
7511 7539
             }
7512 7540
 
7513 7541
             VideoLayout.updateMutePosition(videoSpanId);
@@ -11443,13 +11471,13 @@ module.exports = {
11443 11471
             options.lng = lang;
11444 11472
         i18n.init(options, initCompleted);
11445 11473
     },
11446
-    translateString: function (key, cb) {
11474
+    translateString: function (key, cb, defaultValue) {
11447 11475
         if(!cb)
11448
-            return i18n.t(key);
11476
+            return i18n.t(key, defaultValue);
11449 11477
 
11450 11478
         if(initialized)
11451 11479
         {
11452
-            cb(i18n.t(key));
11480
+            cb(i18n.t(key, defaultValue));
11453 11481
         }
11454 11482
         else
11455 11483
         {
@@ -14506,11 +14534,13 @@ var Moderator = {
14506 14534
                 var waitMs = getNextErrorTimeout();
14507 14535
                 console.error("Focus error, retry after " + waitMs, error);
14508 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 14539
                         Moderator.getFocusComponent() +
14512 14540
                         ' not available - retry in ' +
14513
-                        (waitMs / 1000) + ' sec');
14541
+                        (waitMs / 1000) + ' sec',
14542
+                    {component: Moderator.getFocusComponent(),
14543
+                        ms: (waitMs / 1000)});
14514 14544
                 // Reset response timeout
14515 14545
                 getNextTimeout(true);
14516 14546
                 window.setTimeout(

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

@@ -390,9 +390,9 @@ function onMucLeft(jid) {
390 390
     console.log('left.muc', jid);
391 391
     var displayName = $('#participant_' + Strophe.getResourceFromJid(jid) +
392 392
         '>.displayname').html();
393
-    messageHandler.notify(displayName || 'Somebody',
393
+    messageHandler.notify(displayName,'notify.somebody', "Somebody",
394 394
         'disconnected',
395
-        'disconnected');
395
+        'notify.disconnected', "disconnected");
396 396
     // Need to call this with a slight delay, otherwise the element couldn't be
397 397
     // found for some reason.
398 398
     // XXX(gp) it works fine without the timeout for me (with Chrome 38).
@@ -424,8 +424,9 @@ function onLocalRoleChange(jid, info, pres, isModerator, isExternalAuthEnabled)
424 424
 
425 425
     if (isModerator) {
426 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,9 +470,9 @@ function onPasswordReqiured(callback) {
469 470
     );
470 471
 }
471 472
 function onMucEntered(jid, id, displayName) {
472
-    messageHandler.notify(displayName || 'Somebody',
473
+    messageHandler.notify(displayName,'notify.somebody', "Somebody",
473 474
         'connected',
474
-        'connected');
475
+        'notify.connected', "connected");
475 476
 
476 477
     // Add Peer's container
477 478
     VideoLayout.ensurePeerContainerExists(jid,id);
@@ -486,14 +487,22 @@ function onMucRoleChanged(role, displayName) {
486 487
     VideoLayout.showModeratorIndicator();
487 488
 
488 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 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,13 +149,32 @@ var messageHandler = (function(my) {
149 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 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 178
             '</span>');
160 179
     };
161 180
 

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

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

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

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

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

@@ -231,11 +231,13 @@ var Moderator = {
231 231
                 var waitMs = getNextErrorTimeout();
232 232
                 console.error("Focus error, retry after " + waitMs, error);
233 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 236
                         Moderator.getFocusComponent() +
237 237
                         ' not available - retry in ' +
238
-                        (waitMs / 1000) + ' sec');
238
+                        (waitMs / 1000) + ' sec',
239
+                    {component: Moderator.getFocusComponent(),
240
+                        ms: (waitMs / 1000)});
239 241
                 // Reset response timeout
240 242
                 getNextTimeout(true);
241 243
                 window.setTimeout(

正在加载...
取消
保存