| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * @fileoverview 'settings-language-detail-page' is a sub-page for editing | |
| 7 * an individual language's settings. | |
| 8 */ | |
| 9 Polymer({ | |
| 10 is: 'settings-language-detail-page', | |
| 11 | |
| 12 properties: { | |
| 13 /** | |
| 14 * Preferences state. | |
| 15 */ | |
| 16 prefs: { | |
| 17 type: Object, | |
| 18 notify: true, | |
| 19 }, | |
| 20 | |
| 21 /** | |
| 22 * Read-only reference to the languages model provided by the | |
| 23 * 'settings-languages' instance. | |
| 24 * @type {!LanguagesModel|undefined} | |
| 25 */ | |
| 26 languages: Object, | |
| 27 | |
| 28 /** @type {!LanguageHelper} */ | |
| 29 languageHelper: Object, | |
| 30 | |
| 31 /** | |
| 32 * The language to display the details for. | |
| 33 * @type {!LanguageState|undefined} | |
| 34 */ | |
| 35 detail: Object, | |
| 36 }, | |
| 37 | |
| 38 /** @override */ | |
| 39 ready: function() { | |
| 40 // In a CrOS multi-user session, the primary user controls the UI language. | |
| 41 if (this.isSecondaryUser_()) { | |
| 42 var indicator = this.$.policyIndicator; | |
| 43 indicator.indicatorType = CrPolicyIndicatorType.PRIMARY_USER; | |
| 44 indicator.controllingUser = loadTimeData.getString('primaryUserEmail'); | |
| 45 } | |
| 46 | |
| 47 // The UI language choice doesn't persist for guests. | |
| 48 if (cr.isChromeOS && | |
| 49 (uiAccountTweaks.UIAccountTweaks.loggedInAsGuest() || | |
| 50 uiAccountTweaks.UIAccountTweaks.loggedInAsPublicAccount())) { | |
| 51 this.$.languageSettings.hidden = true; | |
| 52 } | |
| 53 }, | |
| 54 | |
| 55 /** | |
| 56 * Checks whether the prospective UI language (the pref that indicates what | |
| 57 * language to use in Chrome) matches the current language. This pref is only | |
| 58 * on Chrome OS and Windows; we don't control the UI language elsewhere. | |
| 59 * @param {string} languageCode The language code identifying a language. | |
| 60 * @param {string} prospectiveUILanguage The prospective UI language. | |
| 61 * @return {boolean} True if the given language matches the prospective UI | |
| 62 * pref (which may be different from the actual UI language). | |
| 63 * @private | |
| 64 */ | |
| 65 isProspectiveUILanguage_: function(languageCode, prospectiveUILanguage) { | |
| 66 assert(cr.isChromeOS || cr.isWindows); | |
| 67 return languageCode == this.languageHelper.getProspectiveUILanguage(); | |
| 68 }, | |
| 69 | |
| 70 /** | |
| 71 * @param {string} languageCode The language code identifying a language. | |
| 72 * @param {string} prospectiveUILanguage The prospective UI language. | |
| 73 * @return {boolean} True if the the given language, the prospective UI | |
| 74 * language and the actual language all the same. | |
| 75 * @private | |
| 76 */ | |
| 77 isCurrentUILanguage_: function(languageCode, prospectiveUILanguage) { | |
| 78 assert(cr.isChromeOS || cr.isWindows); | |
| 79 return languageCode == prospectiveUILanguage && | |
| 80 languageCode == navigator.language; | |
| 81 }, | |
| 82 | |
| 83 /** | |
| 84 * @param {string} languageCode The language code identifying a language. | |
| 85 * @param {string} targetLanguageCode The default translate target language. | |
| 86 * @return {boolean} True if the language code matches the target language. | |
| 87 * @private | |
| 88 */ | |
| 89 isTranslateDisabled_: function(languageCode, targetLanguageCode) { | |
| 90 return this.languageHelper.convertLanguageCodeForTranslate(languageCode) == | |
| 91 targetLanguageCode; | |
| 92 }, | |
| 93 | |
| 94 /** | |
| 95 * @param {string} languageCode The language code identifying a language. | |
| 96 * @param {string} prospectiveUILanguage The prospective UI language. | |
| 97 * @return {boolean} True if the prospective UI language is set to | |
| 98 * |languageCode| but requires a restart to take effect. | |
| 99 * @private | |
| 100 */ | |
| 101 isRestartRequired_: function(languageCode, prospectiveUILanguage) { | |
| 102 return prospectiveUILanguage == languageCode && | |
| 103 navigator.language != languageCode; | |
| 104 }, | |
| 105 | |
| 106 /** | |
| 107 * @param {string} languageCode The language code identifying a language. | |
| 108 * @param {string} prospectiveUILanguage The chosen UI language. | |
| 109 * @return {boolean} True if the chosen language cannot currently be changed. | |
| 110 * @private | |
| 111 */ | |
| 112 isUILanguageChangeDisabled_: function(languageCode, prospectiveUILanguage) { | |
| 113 // UI language setting belongs to the primary user. | |
| 114 if (this.isSecondaryUser_()) | |
| 115 return true; | |
| 116 // If this is both the actual and the prospective language, flipping the | |
| 117 // toggle button to "off" makes no sense. | |
| 118 return this.isCurrentUILanguage_(languageCode, prospectiveUILanguage); | |
| 119 }, | |
| 120 | |
| 121 /** | |
| 122 * @return {boolean} True for a secondary user in a multi-profile session. | |
| 123 * @private | |
| 124 */ | |
| 125 isSecondaryUser_: function() { | |
| 126 return cr.isChromeOS && loadTimeData.getBoolean('isSecondaryUser'); | |
| 127 }, | |
| 128 | |
| 129 /** | |
| 130 * @param {string} languageCode The language code identifying a language. | |
| 131 * @param {boolean} translateEnabled Whether translate is enabled. | |
| 132 * @return {boolean} True if the translate section should be hidden. | |
| 133 * @private | |
| 134 */ | |
| 135 shouldHideTranslate_: function(languageCode, translateEnabled) { | |
| 136 // Translate server supports Chinese (Traditional) and Chinese (Simplified) | |
| 137 // but not 'general' Chinese. To avoid ambiguity, hide the translate | |
| 138 // checkbox when general Chinese is selected. | |
| 139 return !translateEnabled || languageCode == 'zh'; | |
| 140 }, | |
| 141 | |
| 142 /** | |
| 143 * Handler for changes to the translate checkbox. | |
| 144 * @param {!{target: !{checked: boolean}}} e | |
| 145 * @private | |
| 146 */ | |
| 147 onTranslateEnabledChange_: function(e) { | |
| 148 if (e.target.checked) | |
| 149 this.languageHelper.enableTranslateLanguage(this.detail.language.code); | |
| 150 else | |
| 151 this.languageHelper.disableTranslateLanguage(this.detail.language.code); | |
| 152 }, | |
| 153 | |
| 154 /** | |
| 155 * Handler for changes to the UI language toggle button. | |
| 156 * @param {!{target: !{checked: boolean}}} e | |
| 157 * @private | |
| 158 */ | |
| 159 onUILanguageChange_: function(e) { | |
| 160 if (e.target.checked) { | |
| 161 this.languageHelper.setUILanguage(this.detail.language.code); | |
| 162 } else { | |
| 163 // Reset the chosen UI language to the actual UI language. | |
| 164 this.languageHelper.resetUILanguage(); | |
| 165 } | |
| 166 }, | |
| 167 | |
| 168 /** | |
| 169 * Handler for the restart button. | |
| 170 * @private | |
| 171 */ | |
| 172 onRestartTap_: function() { | |
| 173 <if expr="chromeos"> | |
| 174 settings.LifetimeBrowserProxyImpl.getInstance().signOutAndRestart(); | |
| 175 </if> | |
| 176 <if expr="not chromeos"> | |
| 177 settings.LifetimeBrowserProxyImpl.getInstance().restart(); | |
| 178 </if> | |
| 179 }, | |
| 180 }); | |
| OLD | NEW |