Commit f00cf69e authored by mlcui's avatar mlcui Committed by Commit Bot

OsSettingsLanguages: getSubLabel_ fixes

- Update JSDoc type of uiLanguage to include the missing undefined
- Fix exceptions if uiLanguage is undefined (doesn't happen in practice)
- Add missing dependencies to the computed binding
- Prevent extra comma from appearing if input method is not found

Bug: None
Change-Id: I5bc3dc3849bbb29e92c4a636c511dba69b60aa3e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2525562Reviewed-by: default avatarMy Nguyen <myy@chromium.org>
Commit-Queue: Michael Cui <mlcui@google.com>
Cr-Commit-Position: refs/heads/master@{#825673}
parent 74339898
...@@ -35,7 +35,8 @@ ...@@ -35,7 +35,8 @@
id="languagesSubpageTrigger" id="languagesSubpageTrigger"
label="$i18n{osLanguagesPageTitle}" label="$i18n{osLanguagesPageTitle}"
sub-label="[[getSubLabel_(languages.prospectiveUILanguage, sub-label="[[getSubLabel_(languages.prospectiveUILanguage,
languages.inputMethods.currentId)]]" languages.inputMethods.currentId,
languages.inputMethods.enabled, languageHelper)]]"
on-click="onLanguagesTap_" on-click="onLanguagesTap_"
role-description="$i18n{subpageArrowRoleDescription}"> role-description="$i18n{subpageArrowRoleDescription}">
</cr-link-row> </cr-link-row>
......
...@@ -91,20 +91,28 @@ Polymer({ ...@@ -91,20 +91,28 @@ Polymer({
}, },
/** /**
* @param {string} uiLanguage Current UI language fully specified, e.g. * @param {string|undefined} uiLanguage Current UI language fully specified,
* "English (United States)". * e.g. "English (United States)".
* @param {string} id The input method ID, e.g. "US Keyboard". * @param {string} id The input method ID, e.g. "US Keyboard".
* @param {!Array<!chrome.languageSettingsPrivate.InputMethod>}
* enabledInputMethods The list of currently enabled input methods.
* @param {!LanguageHelper} languageHelper The LanguageHelper object.
* @return {string} A sublabel for the 'Languages and input' row * @return {string} A sublabel for the 'Languages and input' row
* @private * @private
*/ */
getSubLabel_(uiLanguage, id) { getSubLabel_(uiLanguage, id, enabledInputMethods, languageHelper) {
if (uiLanguage === undefined) {
return '';
}
const languageDisplayName = const languageDisplayName =
this.languageHelper.getLanguage(uiLanguage).displayName; languageHelper.getLanguage(uiLanguage).displayName;
const inputMethod = const inputMethod = enabledInputMethods.find(function(inputMethod) {
this.languages.inputMethods.enabled.find(function(inputMethod) {
return inputMethod.id === id; return inputMethod.id === id;
}); });
const inputMethodDisplayName = inputMethod ? inputMethod.displayName : ''; const inputMethodDisplayName = inputMethod ? inputMethod.displayName : '';
if (!inputMethodDisplayName) {
return languageDisplayName;
}
// It is OK to use string concatenation here because it is just joining a 2 // It is OK to use string concatenation here because it is just joining a 2
// element list (i.e. it's a standard format). // element list (i.e. it's a standard format).
return languageDisplayName + ', ' + inputMethodDisplayName; return languageDisplayName + ', ' + inputMethodDisplayName;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment