Skip to content

Commit

Permalink
Properly localize group changes (#1802)
Browse files Browse the repository at this point in the history
* Properly localize group updates

* Remove phone number in display name if contact in address book

* New string for multiple new group members
  • Loading branch information
scottnonnenberg authored Nov 22, 2017
1 parent 87d8ec7 commit 0a4f984
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
14 changes: 12 additions & 2 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@
},
"leftTheGroup": {
"message": "$name$ left the group.",
"description": "Shown in the conversation history when someone leaves the group",
"description": "Shown in the conversation history when a single person leaves the group",
"placeholders": {
"name": {
"content": "$1",
Expand All @@ -929,8 +929,18 @@
}
},
"joinedTheGroup": {
"message": "$name$ joined the group.",
"description": "Shown in the conversation history when a single person joins the group",
"placeholders": {
"name": {
"content": "$1",
"example": "Alice"
}
}
},
"multipleJoinedTheGroup": {
"message": "$names$ joined the group.",
"description": "Shown in the conversation history when people join the group",
"description": "Shown in the conversation history when more than one person joins the group",
"placeholders": {
"names": {
"content": "$1",
Expand Down
18 changes: 18 additions & 0 deletions js/models/conversations.js
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,24 @@
}
},

getDisplayName: function() {
if (!this.isPrivate()) {
return this.getTitle();
}

var name = this.get('name');
if (name) {
return name;
}

var profileName = this.get('profileName');
if (profileName) {
return this.getNumber() + ' ~' + profileName;
}

return this.getNumber();
},

getNumber: function() {
if (!this.isPrivate()) {
return '';
Expand Down
22 changes: 18 additions & 4 deletions js/models/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,33 @@
return this.sync('read', this, options);
},
// jscs:enable
getNameForNumber: function(number) {
var conversation = ConversationController.get(number);
if (!conversation) {
return number;
}
return conversation.getDisplayName();
},
getDescription: function() {
if (this.isGroupUpdate()) {
var group_update = this.get('group_update');
if (group_update.left) {
return i18n('leftTheGroup', group_update.left);
if (group_update.left === 'You') {
return i18n('youLeftTheGroup');
} else if (group_update.left) {
return i18n('leftTheGroup', this.getNameForNumber(group_update.left));
}

var messages = [i18n('updatedTheGroup')];
if (group_update.name) {
messages.push(i18n('titleIsNow', group_update.name));
}
if (group_update.joined) {
messages.push(i18n('joinedTheGroup', group_update.joined.join(', ')));
if (group_update.joined && group_update.joined.length) {
var names = _.map(group_update.joined, this.getNameForNumber.bind(this));
if (names.length > 1) {
messages.push(i18n('multipleJoinedTheGroup', names.join(', ')));
} else {
messages.push(i18n('joinedTheGroup', names[0]));
}
}

return messages.join(' ');
Expand Down

0 comments on commit 0a4f984

Please sign in to comment.