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 @@
id="languagesSubpageTrigger"
label="$i18n{osLanguagesPageTitle}"
sub-label="[[getSubLabel_(languages.prospectiveUILanguage,
languages.inputMethods.currentId,
languages.inputMethods.enabled, languageHelper)]]"
languages.inputMethods.currentId, languageHelper)]]"
on-click="onLanguagesTap_"
role-description="$i18n{subpageArrowRoleDescription}">
</cr-link-row>
......@@ -45,6 +44,8 @@
<cr-link-row
id="languagesPageTrigger"
label="$i18n{languagesPageTitle}"
sub-label="[[getLanguageDisplayName_(
languages.prospectiveUILanguage, languageHelper)]]"
on-click="onLanguagesV2Click_"
role-description="$i18n{subpageArrowRoleDescription}">
</cr-link-row>
......@@ -52,6 +53,8 @@
class="hr"
id="inputPageTrigger"
label="$i18n{inputPageTitle}"
sub-label="[[getInputMethodDisplayName_(
languages.inputMethods.currentId, languageHelper)]]"
on-click="onInputClick_"
role-description="$i18n{subpageArrowRoleDescription}">
</cr-link-row>
......
......@@ -94,22 +94,18 @@ Polymer({
* @param {string|undefined} uiLanguage Current UI language fully specified,
* e.g. "English (United States)".
* @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
* @private
*/
getSubLabel_(uiLanguage, id, enabledInputMethods, languageHelper) {
if (uiLanguage === undefined) {
getSubLabel_(uiLanguage, id, languageHelper) {
const languageDisplayName =
this.getLanguageDisplayName_(uiLanguage, languageHelper);
if (!languageDisplayName) {
return '';
}
const languageDisplayName =
languageHelper.getLanguage(uiLanguage).displayName;
const inputMethod = enabledInputMethods.find(function(inputMethod) {
return inputMethod.id === id;
});
const inputMethodDisplayName = inputMethod ? inputMethod.displayName : '';
const inputMethodDisplayName =
this.getInputMethodDisplayName_(id, languageHelper);
if (!inputMethodDisplayName) {
return languageDisplayName;
}
......@@ -117,4 +113,37 @@ Polymer({
// element list (i.e. it's a standard format).
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