Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

feat(autocomplete): allow localization of query result announcements #12059

Merged
merged 1 commit into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/components/autocomplete/js/autocompleteController.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $mdTheming,
ctrl.isReadonly = null;
ctrl.hasNotFound = false;
ctrl.selectedMessage = $scope.selectedMessage || 'selected';
ctrl.noMatchMessage = $scope.noMatchMessage || 'There are no matches available.';
ctrl.singleMatchMessage = $scope.singleMatchMessage || 'There is 1 match available.';
ctrl.multipleMatchStartMessage = $scope.multipleMatchStartMessage || 'There are ';
ctrl.multipleMatchEndMessage = $scope.multipleMatchEndMessage || ' matches available.';
ctrl.defaultEscapeOptions = 'clear';

// Public Exported Methods
Expand Down Expand Up @@ -1024,11 +1028,11 @@ function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $mdTheming,
function getCountMessage () {
switch (ctrl.matches.length) {
case 0:
return 'There are no matches available.';
return ctrl.noMatchMessage;
case 1:
return 'There is 1 match available.';
return ctrl.singleMatchMessage;
default:
return 'There are ' + ctrl.matches.length + ' matches available.';
return ctrl.multipleMatchStartMessage + ctrl.matches.length + ctrl.multipleMatchEndMessage;
}
}

Expand Down
22 changes: 21 additions & 1 deletion src/components/autocomplete/js/autocompleteDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,23 @@ angular
* @param {string=} md-selected-message Attribute to specify the text that the screen reader will
* announce after a value is selected. Default is: "selected". If `Alaska` is selected in the
* options panel, it will read "Alaska selected". You will want to override this when your app
* is running in a non-English locale.
* runs in a non-English locale.
* @param {string=} md-no-match-message Attribute to specify the text that the screen reader will
* announce after a query returns no matching results.
* Default is: "There are no matches available.". You will want to override this when your app
* runs in a non-English locale.
* @param {string=} md-single-match-message Attribute to specify the text that the screen reader
* will announce after a query returns a single matching result.
* Default is: "There is 1 match available.". You will want to override this when your app
* runs in a non-English locale.
* @param {string=} md-multiple-match-start-message Attribute to specify the text that the screen
* reader will announce after a query returns multiple matching results. The number of matching
* results will be read after this text. Default is: "There are ". You will want to override this
* when your app runs in a non-English locale.
* @param {string=} md-multiple-match-end-message Attribute to specify the text that the screen
* reader will announce after a query returns multiple matching results. The number of matching
* results will be read before this text. Default is: " matches available.". You will want to
* override this when your app runs in a non-English locale.
* @param {boolean=} ng-trim If set to false, the search text will be not trimmed automatically.
* Defaults to true.
* @param {string=} ng-pattern Adds the pattern validator to the ngModel of the search text.
Expand Down Expand Up @@ -336,6 +352,10 @@ function MdAutocomplete ($$mdSvgRegistry) {
dropdownPosition: '@?mdDropdownPosition',
clearButton: '=?mdClearButton',
selectedMessage: '@?mdSelectedMessage',
noMatchMessage: '@?mdNoMatchMessage',
singleMatchMessage: '@?mdSingleMatchMessage',
multipleMatchStartMessage: '@?mdMultipleMatchStartMessage',
multipleMatchEndMessage: '@?mdMultipleMatchEndMessage',
mdMode: '=?mdMode'
},
compile: function(tElement, tAttrs) {
Expand Down