Skip to content

Commit 9c1116d

Browse files
committed
Don't concatenate strings for translations but use interpolation.
1 parent 4ab86e4 commit 9c1116d

File tree

7 files changed

+35
-21
lines changed

7 files changed

+35
-21
lines changed

static/js/controllers/chatroomcontroller.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ define(['jquery', 'underscore', 'moment', 'text!partials/fileinfo.html', 'text!p
4646
}, 100));
4747

4848
var displayName = safeDisplayName;
49+
// To be used by chatroom.html partial.
50+
$scope.displayName = displayName;
4951
var buddyImageSrc = $filter("buddyImageSrc");
5052
var fileInfo = $compile(templateFileInfo);
5153
var contactRequest = $compile(templateContactRequest);
@@ -415,9 +417,9 @@ define(['jquery', 'underscore', 'moment', 'text!partials/fileinfo.html', 'text!p
415417
case "LeftOrJoined":
416418
$scope.showtime(new Date());
417419
if (data.LeftOrJoined === "left") {
418-
$scope.display(null, $("<i>" + displayName(from) + translation._(" is now offline.") + "</i>"));
420+
$scope.display(null, $("<i>" + translation._("%1$s is now offline.", displayName(from)) + "</i>"));
419421
} else {
420-
$scope.display(null, $("<i>" + displayName(from) + translation._(" is now online.") + "</i>"));
422+
$scope.display(null, $("<i>" + translation._("%1$s is now online.", displayName(from)) + "</i>"));
421423
}
422424
break;
423425
case "Log":

static/js/controllers/statusmessagecontroller.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
define([], function() {
2424

2525
// StatusmessageController
26-
return ["$scope", "mediaStream", function($scope, mediaStream) {
26+
return ["$scope", "mediaStream", "safeDisplayName", function($scope, mediaStream, safeDisplayName) {
27+
28+
// To be used by statusmessage.html partial.
29+
$scope.displayName = safeDisplayName;
2730

2831
$scope.doHangup = function() {
2932
mediaStream.webrtc.doHangup();

static/js/controllers/uicontroller.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,9 @@ define(['jquery', 'underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'web
407407
// Start to ring.
408408
ringer.start();
409409
// Show incoming call notification.
410-
notification = desktopNotify.notify(translation._("Incoming call"), translation._("from") + " " + displayName(from), {
410+
// TODO: This might not be correct in some languages where the
411+
// name must come first.
412+
notification = desktopNotify.notify(translation._("Incoming call"), translation._("from %1$s", displayName(from)), {
411413
timeout: null
412414
});
413415
$scope.$emit("status", "ringing");
@@ -690,21 +692,21 @@ define(['jquery', 'underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'web
690692
var message = null;
691693
switch (type) {
692694
case "busy":
693-
message = displayName(details.from) + translation._(" is busy. Try again later.");
695+
message = translation._("%1$s is busy. Try again later.", displayName(details.from));
694696
break;
695697
case "reject":
696-
message = displayName(details.from) + translation._(" rejected your call.");
698+
message = translation._("%1$s rejected your call.", displayName(details.from));
697699
break;
698700
case "pickuptimeout":
699-
message = displayName(details.from) + translation._(" does not pick up.");
701+
message = translation._("%1$s does not pick up.", displayName(details.from));
700702
break;
701703
case "incomingbusy":
702-
toastr.info(moment().format("lll"), displayName(details.from) + translation._(" tried to call you"));
704+
toastr.info(moment().format("lll"), translation._("%1$s tried to call you", displayName(details.from)));
703705
break;
704706
case "abortbeforepickup":
705707
// Fall through
706708
case "incomingpickuptimeout":
707-
toastr.info(moment().format("lll"), displayName(details.from) + translation._(" called you"));
709+
toastr.info(moment().format("lll"), translation._("%1$s called you", displayName(details.from)));
708710
break;
709711
}
710712
if (message) {

static/js/directives/chat.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
2424

2525
return ["$compile", "safeDisplayName", "mediaStream", "safeApply", "desktopNotify", "translation", "playSound", "fileUpload", "randomGen", "buddyData", "appData", "$timeout", "geolocation", function($compile, safeDisplayName, mediaStream, safeApply, desktopNotify, translation, playSound, fileUpload, randomGen, buddyData, appData, $timeout, geolocation) {
2626

27+
// Translation helpers.
28+
translation._("Chat with %1$s");
29+
translation._("Room chat %1$s");
30+
2731
var displayName = safeDisplayName;
2832
var groupChatId = "";
2933
var maxMessageSize = 200000;
@@ -137,7 +141,8 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
137141
$scope.showGroupRoom(null, options);
138142
} else {
139143
$scope.showRoom(id, {
140-
title: translation._("Chat with")
144+
// Gets translated in template.
145+
title: "Chat with %1$s"
141146
}, options);
142147
}
143148

@@ -159,7 +164,8 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
159164
return;
160165
}
161166
var subscope = $scope.showRoom(id, {
162-
title: translation._("Chat with")
167+
// Gets translated in template.
168+
title: "Chat with %1$s"
163169
}, options);
164170
subscope.sendChatServer(id, "Contact request", {
165171
ContactRequest: {
@@ -181,7 +187,8 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
181187

182188
scope.showGroupRoom = function(settings, options) {
183189
var stngs = $.extend({
184-
title: translation._("Room chat"),
190+
// Gets translated in template.
191+
title: "Room chat %1$s",
185192
group: true
186193
}, settings);
187194
return scope.showRoom(controller.group, stngs, options);
@@ -384,7 +391,7 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
384391
// before we beep and shout.
385392
if (!subscope.isgroupchat && from !== sessionid) {
386393
playSound.play("chatmessage");
387-
desktopNotify.notify(translation._("Message from ") + displayName(from), message);
394+
desktopNotify.notify(translation._("Message from %1$s", displayName(from)), message);
388395
appData.e.triggerHandler("uiNotification", ["chatmessage", {from: from, message: message, first: subscope.firstmessage}]);
389396
}
390397
subscope.firstmessage = false;

static/partials/chat.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<a ng-repeat="room in getVisibleRooms()" ng-click="activateRoom(room.id, true)" class="list-group-item" ng-class="{newmessage: room.pending, disabled: !room.enabled}">
99
<span class="badge" ng-show="room.pending">{{room.pending}}</span>
1010
<span ng-if="room.id !== ''">{{room.id|displayName}}</span>
11-
<span ng-if="room.id === ''">{{_("Room chat")}} {{currentRoomName}}</span>
11+
<span ng-if="room.id === ''">{{_("Room chat %1$s", currentRoomName)}}</span>
1212
<button ng-if="room.id !== ''" class="btn btn-sm btn-default" ng-click="hideRoom(room.id)">
1313
<i class="fa fa-trash-o"></i>
1414
</button>

static/partials/chatroom.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div ng-controller="ChatroomController" class="chat room-{{index}}" ng-class="{'newmessage': newmessage, 'visible': visible, 'chat-p2p': 'p2pstate', 'with_pictures': isgroupchat, 'active': active}">
2-
<div class="chatheader"><div class="chatstatusicon" ng-click="deactivateRoom()"><i class="fa fa-angle-left"></i> <i class="fa fa fa-comments-o"></i></div><div class="chatheadertitle"><span ng-show="p2pstate" class="fa fa-exchange" title="{{_('Peer to peer')}}"/><span>{{settings.title}} {{id|displayName}}</span></div> <div class="ctrl"><i ng-hide="layout.chatMaximized" ng-click="toggleMax()" class="fa fa-expand"></i><i ng-show="layout.chatMaximized" ng-click="toggleMax()" class="fa fa-compress"></i><!--<i title="{{_('Close chat')}}" ng-click="hide()" class="fa fa-times"></i>--></div></div>
2+
<div class="chatheader"><div class="chatstatusicon" ng-click="deactivateRoom()"><i class="fa fa-angle-left"></i> <i class="fa fa fa-comments-o"></i></div><div class="chatheadertitle"><span ng-show="p2pstate" class="fa fa-exchange" title="{{_('Peer to peer')}}"/><span>{{_(settings.title, displayName(id))}}</span></div> <div class="ctrl"><i ng-hide="layout.chatMaximized" ng-click="toggleMax()" class="fa fa-expand"></i><i ng-show="layout.chatMaximized" ng-click="toggleMax()" class="fa fa-compress"></i><!--<i title="{{_('Close chat')}}" ng-click="hide()" class="fa fa-times"></i>--></div></div>
33
<div class="chatmenu">
44
<div class="btn-group">
55
<button ng-if="!isgroupchat" class="btn btn-sm btn-default" title="{{_('Start video call')}}" ng-click="doCall()"><i class="fa fa-phone fa-fw"></i></button>
@@ -16,8 +16,8 @@
1616
</div>
1717
<div class="chatbodybottom">
1818
<div class="typinghint" ng-switch on="peerIsTyping">
19-
<span ng-switch-when="start"><i class="fa fa-pencil"></i> {{id|displayName}} {{_('is typing...')}}</span>
20-
<span ng-switch-when="stop"><i class="fa fa-pencil"></i> {{id|displayName}} {{_('has stopped typing...')}}</span>
19+
<span ng-switch-when="start"><i class="fa fa-pencil"></i> {{_('%1$s is typing...', displayName(id))}}</span>
20+
<span ng-switch-when="stop"><i class="fa fa-pencil"></i> {{_('%1$s has stopped typing...', displayName(id))}}</span>
2121
</div>
2222
<div class="inputbox">
2323
<div>

static/partials/statusmessage.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<span class="status-{{status}}" ng-switch on="status">
22
<span ng-switch-when="initializing">{{_("Initializing")}} <i class="fa fa-circle-o-notch fa-spin"></i></span>
33
<span ng-switch-when="waiting" ng-controller="UsersettingsController as usersettings"><span class="status-indicator"><i style="color:rgb(132,184,25)" class="fa fa-dot-circle-o" title="{{_('Online')}}"></i> {{id|displayName}}</span> <img class="userpicture" ng-show="master.buddyPicture" ng-src="{{master.buddyPicture}}" alt="" /><button ng-if="!authorizing && !myuserid && usersettings.loginUserid" type="button" class="btn btn-default" ng-click="usersettings.loginUserid()">{{_("Sign in")}}</button></span>
4-
<span ng-switch-when="connecting"><span class="msg">{{_("Calling")}} {{dialing|displayName}}</span> <a class="btn btn-small btn-danger" ng-click="doAbort()"><i class="fa fa-circle-o-notch fa-spin"></i> {{_("Hangup")}}</a></span>
5-
<span ng-switch-when="connected"><span class="msg">{{_("In call with")}} {{peer|displayName}}</span> <a class="btn btn-small btn-danger" ng-click="doHangup()"><i class="fa fa-sign-out"></i> {{_("Hangup")}}</a></span>
6-
<span ng-switch-when="conference"><span class="msg">{{_("Conference with")}} {{peer|displayName}}<span>{{conferencePeers|displayConference}}</span></span> <a class="btn btn-small btn-danger" ng-click="doHangup()"><i class="fa fa-sign-out"></i> {{_("Hangup")}}</a></span>
4+
<span ng-switch-when="connecting"><span class="msg">{{_("Calling %1$s", $parent.displayName(dialing))}}</span> <a class="btn btn-small btn-danger" ng-click="doAbort()"><i class="fa fa-circle-o-notch fa-spin"></i> {{_("Hangup")}}</a></span>
5+
<span ng-switch-when="connected"><span class="msg">{{_("In call with %1$s", displayName(peer))}}</span> <a class="btn btn-small btn-danger" ng-click="doHangup()"><i class="fa fa-sign-out"></i> {{_("Hangup")}}</a></span>
6+
<span ng-switch-when="conference"><span class="msg">{{_("Conference with %1$s", displayName(peer))}}<span>{{conferencePeers|displayConference}}</span></span> <a class="btn btn-small btn-danger" ng-click="doHangup()"><i class="fa fa-sign-out"></i> {{_("Hangup")}}</a></span>
77
<span ng-switch-when="closed"><span class="msg">{{_("Your are offline")}}</span> <a class="btn btn-small btn-success" ng-click="doReconnect()"><i class="fa fa-sign-in"></i> {{_("Go online")}}</a></span>
88
<span ng-switch-when="reconnecting">{{_("Connection interrupted")}} <i class="text-warning fa fa-circle-o-notch fa-spin"></i></span>
99
<span ng-switch-when="error"><span class="msg">{{_("An error occured")}}</span> <a class="btn btn-small btn-success" ng-click="doReconnect()"><i class="fa fa-refresh"></i> {{_("Retry")}}</a></span>
10-
<span ng-switch-when="ringing"><span class="msg long">{{_("Incoming call")}} {{_("from")}} {{incoming|displayName}}</span> <span class="actions"><a class="btn btn-small btn-success btn-shakeityeah" ng-click="doAccept()"><i class="fa fa-phone"></i> {{_("Accept call")}}</a> <a class="btn btn-small btn-danger" ng-click="doReject()"><i class="fa fa-sign-out"></i> {{_("Reject")}}</a></span></span>
10+
<span ng-switch-when="ringing"><span class="msg long">{{_("Incoming call from %1$s", displayName(incoming))}}</span> <span class="actions"><a class="btn btn-small btn-success btn-shakeityeah" ng-click="doAccept()"><i class="fa fa-phone"></i> {{_("Accept call")}}</a> <a class="btn btn-small btn-danger" ng-click="doReject()"><i class="fa fa-sign-out"></i> {{_("Reject")}}</a></span></span>
1111
<span ng-switch-when="waitforusermedia"><span class="msg">{{_("Waiting for camera/microphone access")}}</span> <a class="btn btn-small btn-danger" ng-click="doHangup()"><i class="fa fa-circle-o-notch fa-spin"></i> {{_("Hangup")}}</a></span>
1212
</span>

0 commit comments

Comments
 (0)