From 57713bb9dccfaf4b5b72ffbbf941dce14e8e03ff Mon Sep 17 00:00:00 2001 From: Joachim Bauch Date: Tue, 11 Aug 2015 00:46:09 +0200 Subject: [PATCH] Don't concatenate strings for translations but use interpolation. --- static/js/controllers/chatroomcontroller.js | 6 ++++-- static/js/controllers/statusmessagecontroller.js | 5 ++++- static/js/controllers/uicontroller.js | 14 ++++++++------ static/js/directives/chat.js | 15 +++++++++++---- static/partials/chat.html | 2 +- static/partials/chatroom.html | 6 +++--- static/partials/statusmessage.html | 8 ++++---- 7 files changed, 35 insertions(+), 21 deletions(-) diff --git a/static/js/controllers/chatroomcontroller.js b/static/js/controllers/chatroomcontroller.js index d6611ef8..68e25526 100644 --- a/static/js/controllers/chatroomcontroller.js +++ b/static/js/controllers/chatroomcontroller.js @@ -46,6 +46,8 @@ define(['jquery', 'underscore', 'moment', 'text!partials/fileinfo.html', 'text!p }, 100)); var displayName = safeDisplayName; + // To be used by chatroom.html partial. + $scope.displayName = displayName; var buddyImageSrc = $filter("buddyImageSrc"); var fileInfo = $compile(templateFileInfo); var contactRequest = $compile(templateContactRequest); @@ -415,9 +417,9 @@ define(['jquery', 'underscore', 'moment', 'text!partials/fileinfo.html', 'text!p case "LeftOrJoined": $scope.showtime(new Date()); if (data.LeftOrJoined === "left") { - $scope.display(null, $("" + displayName(from) + translation._(" is now offline.") + "")); + $scope.display(null, $("" + translation._("%1$s is now offline.", displayName(from)) + "")); } else { - $scope.display(null, $("" + displayName(from) + translation._(" is now online.") + "")); + $scope.display(null, $("" + translation._("%1$s is now online.", displayName(from)) + "")); } break; case "Log": diff --git a/static/js/controllers/statusmessagecontroller.js b/static/js/controllers/statusmessagecontroller.js index a9af9717..28889dd5 100644 --- a/static/js/controllers/statusmessagecontroller.js +++ b/static/js/controllers/statusmessagecontroller.js @@ -23,7 +23,10 @@ define([], function() { // StatusmessageController - return ["$scope", "mediaStream", function($scope, mediaStream) { + return ["$scope", "mediaStream", "safeDisplayName", function($scope, mediaStream, safeDisplayName) { + + // To be used by statusmessage.html partial. + $scope.displayName = safeDisplayName; $scope.doHangup = function(reason, id) { mediaStream.webrtc.doHangup(reason, id); diff --git a/static/js/controllers/uicontroller.js b/static/js/controllers/uicontroller.js index 89a04dee..4e23d88f 100644 --- a/static/js/controllers/uicontroller.js +++ b/static/js/controllers/uicontroller.js @@ -512,7 +512,9 @@ define(['jquery', 'underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'web // Start to ring. ringer.start(); // Show incoming call notification. - notification = desktopNotify.notify(translation._("Incoming call"), translation._("from") + " " + displayName(from), { + // TODO: This might not be correct in some languages where the + // name must come first. + notification = desktopNotify.notify(translation._("Incoming call"), translation._("from %1$s", displayName(from)), { timeout: null }); $scope.$emit("status", "ringing"); @@ -808,21 +810,21 @@ define(['jquery', 'underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'web var message = null; switch (type) { case "busy": - message = displayName(details.from) + translation._(" is busy. Try again later."); + message = translation._("%1$s is busy. Try again later.", displayName(details.from)); break; case "reject": - message = displayName(details.from) + translation._(" rejected your call."); + message = translation._("%1$s rejected your call.", displayName(details.from)); break; case "pickuptimeout": - message = displayName(details.from) + translation._(" does not pick up."); + message = translation._("%1$s does not pick up.", displayName(details.from)); break; case "incomingbusy": - toastr.info(moment().format("lll"), displayName(details.from) + translation._(" tried to call you")); + toastr.info(moment().format("lll"), translation._("%1$s tried to call you", displayName(details.from))); break; case "abortbeforepickup": // Fall through case "incomingpickuptimeout": - toastr.info(moment().format("lll"), displayName(details.from) + translation._(" called you")); + toastr.info(moment().format("lll"), translation._("%1$s called you", displayName(details.from))); break; } if (message) { diff --git a/static/js/directives/chat.js b/static/js/directives/chat.js index 1da17e69..ce253c4e 100644 --- a/static/js/directives/chat.js +++ b/static/js/directives/chat.js @@ -24,6 +24,10 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro 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) { + // Translation helpers. + translation._("Chat with %1$s"); + translation._("Room chat %1$s"); + var displayName = safeDisplayName; var groupChatId = ""; var maxMessageSize = 200000; @@ -138,7 +142,8 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro $scope.showGroupRoom(null, options); } else { $scope.showRoom(id, { - title: translation._("Chat with") + // Gets translated in template. + title: "Chat with %1$s" }, options); } @@ -160,7 +165,8 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro return; } var subscope = $scope.showRoom(id, { - title: translation._("Chat with") + // Gets translated in template. + title: "Chat with %1$s" }, options); subscope.sendChatServer(id, "Contact request", { ContactRequest: { @@ -182,7 +188,8 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro scope.showGroupRoom = function(settings, options) { var stngs = $.extend({ - title: translation._("Room chat"), + // Gets translated in template. + title: "Room chat %1$s", group: true }, settings); return scope.showRoom(controller.group, stngs, options); @@ -385,7 +392,7 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro // before we beep and shout. if (!subscope.isgroupchat && from !== sessionid) { playSound.play("chatmessage"); - desktopNotify.notify(translation._("Message from ") + displayName(from), message); + desktopNotify.notify(translation._("Message from %1$s", displayName(from)), message); appData.e.triggerHandler("uiNotification", ["chatmessage", {from: from, message: message, first: subscope.firstmessage}]); } subscope.firstmessage = false; diff --git a/static/partials/chat.html b/static/partials/chat.html index 5e7a2630..b76eb043 100644 --- a/static/partials/chat.html +++ b/static/partials/chat.html @@ -8,7 +8,7 @@ {{room.pending}} {{room.id|displayName}} - {{_("Room chat")}} {{currentRoomName}} + {{_("Room chat %1$s", currentRoomName)}} diff --git a/static/partials/chatroom.html b/static/partials/chatroom.html index 6f59622b..f08f85ee 100644 --- a/static/partials/chatroom.html +++ b/static/partials/chatroom.html @@ -1,5 +1,5 @@
-
{{settings.title}} {{id|displayName}}
+
{{_(settings.title, displayName(id))}}
@@ -16,8 +16,8 @@
- {{id|displayName}} {{_('is typing...')}} - {{id|displayName}} {{_('has stopped typing...')}} + {{_('%1$s is typing...', displayName(id))}} + {{_('%1$s has stopped typing...', displayName(id))}}
diff --git a/static/partials/statusmessage.html b/static/partials/statusmessage.html index 49b2237f..7e89dd31 100644 --- a/static/partials/statusmessage.html +++ b/static/partials/statusmessage.html @@ -1,12 +1,12 @@ {{_("Initializing")}} {{id|displayName}} - {{_("Calling")}} {{dialing|displayName}} {{_("Hangup")}} - {{_("In call with")}} {{peer|displayName}} {{_("Hangup")}} - {{_("Conference with")}} {{peer|displayName}}{{conferencePeers|displayConference}} {{_("Hangup")}} + {{_("Calling %1$s", $parent.displayName(dialing))}} {{_("Hangup")}} + {{_("In call with %1$s", displayName(peer))}} {{_("Hangup")}} + {{_("Conference with %1$s", displayName(peer))}}{{conferencePeers|displayConference}} {{_("Hangup")}} {{_("Your are offline")}} {{_("Go online")}} {{_("Connection interrupted")}} {{_("An error occured")}} {{_("Retry")}} - {{_("Incoming call")}} {{_("from")}} {{incoming|displayName}} {{_("Accept call")}} {{_("Reject")}} + {{_("Incoming call from %1$s", displayName(incoming))}} {{_("Accept call")}} {{_("Reject")}} {{_("Waiting for camera/microphone access")}} {{_("Hangup")}}