Commit 15e9efd9 authored by mlcui's avatar mlcui Committed by Commit Bot

OsSettingsLanguages: Add sub-labels for Languages and Inputs rows

Googlers: a screenshot of the new sub-labels can be found here:
http://screen/345FdDordriQRcu

Fixed: 1146366
Test: Manual test
Change-Id: I49ca8a731b7ef1d63d794368ff27b355298e382d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2525463Reviewed-by: default avatarMy Nguyen <myy@chromium.org>
Commit-Queue: Michael Cui <mlcui@google.com>
Cr-Commit-Position: refs/heads/master@{#828008}
parent c2420b9b
...@@ -35,8 +35,7 @@ ...@@ -35,8 +35,7 @@
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, languageHelper)]]"
languages.inputMethods.enabled, languageHelper)]]"
on-click="onLanguagesTap_" on-click="onLanguagesTap_"
role-description="$i18n{subpageArrowRoleDescription}"> role-description="$i18n{subpageArrowRoleDescription}">
</cr-link-row> </cr-link-row>
...@@ -45,6 +44,8 @@ ...@@ -45,6 +44,8 @@
<cr-link-row <cr-link-row
id="languagesPageTrigger" id="languagesPageTrigger"
label="$i18n{languagesPageTitle}" label="$i18n{languagesPageTitle}"
sub-label="[[getLanguageDisplayName_(
languages.prospectiveUILanguage, languageHelper)]]"
on-click="onLanguagesV2Click_" on-click="onLanguagesV2Click_"
role-description="$i18n{subpageArrowRoleDescription}"> role-description="$i18n{subpageArrowRoleDescription}">
</cr-link-row> </cr-link-row>
...@@ -52,6 +53,8 @@ ...@@ -52,6 +53,8 @@
class="hr" class="hr"
id="inputPageTrigger" id="inputPageTrigger"
label="$i18n{inputPageTitle}" label="$i18n{inputPageTitle}"
sub-label="[[getInputMethodDisplayName_(
languages.inputMethods.currentId, languageHelper)]]"
on-click="onInputClick_" on-click="onInputClick_"
role-description="$i18n{subpageArrowRoleDescription}"> role-description="$i18n{subpageArrowRoleDescription}">
</cr-link-row> </cr-link-row>
......
...@@ -94,22 +94,18 @@ Polymer({ ...@@ -94,22 +94,18 @@ Polymer({
* @param {string|undefined} uiLanguage Current UI language fully specified, * @param {string|undefined} uiLanguage Current UI language fully specified,
* e.g. "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. * @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, enabledInputMethods, languageHelper) { getSubLabel_(uiLanguage, id, languageHelper) {
if (uiLanguage === undefined) { const languageDisplayName =
this.getLanguageDisplayName_(uiLanguage, languageHelper);
if (!languageDisplayName) {
return ''; return '';
} }
const languageDisplayName = const inputMethodDisplayName =
languageHelper.getLanguage(uiLanguage).displayName; this.getInputMethodDisplayName_(id, languageHelper);
const inputMethod = enabledInputMethods.find(function(inputMethod) {
return inputMethod.id === id;
});
const inputMethodDisplayName = inputMethod ? inputMethod.displayName : '';
if (!inputMethodDisplayName) { if (!inputMethodDisplayName) {
return languageDisplayName; return languageDisplayName;
} }
...@@ -117,4 +113,37 @@ Polymer({ ...@@ -117,4 +113,37 @@ Polymer({
// element list (i.e. it's a standard format). // element list (i.e. it's a standard format).
return languageDisplayName + ', ' + inputMethodDisplayName; return languageDisplayName + ', ' + inputMethodDisplayName;
}, },
/**
* @param {string|undefined} code The language code of the language.
* @param {!LanguageHelper} languageHelper The LanguageHelper object.
* @return {string} The display name of the language specified.
* @private
*/
getLanguageDisplayName_(code, languageHelper) {
if (!code) {
return '';
}
const language = languageHelper.getLanguage(code);
if (!language) {
return '';
}
return language.displayName;
},
/**
* @param {string} id The input method ID.
* @param {!LanguageHelper} languageHelper The LanguageHelper object.
* @return {string} The display name of the input method.
* @private
*/
getInputMethodDisplayName_(id, languageHelper) {
// LanguageHelper.getInputMethodDisplayName will throw an error if the ID
// isn't found, such as when using CrOS on Linux.
try {
return languageHelper.getInputMethodDisplayName(id);
} catch (_) {
return '';
}
},
}); });
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