Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 (function() { | 5 (function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 cr.define('cr.translateInternals', function() { | 8 cr.define('cr.translateInternals', function() { |
| 9 | 9 |
| 10 var detectionLogs_ = null; | 10 var detectionLogs_ = null; |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 var text = formatLanguageCode(language); | 246 var text = formatLanguageCode(language); |
| 247 if (details['alpha_languages'].indexOf(language) != -1) | 247 if (details['alpha_languages'].indexOf(language) != -1) |
| 248 text += ' - alpha'; | 248 text += ' - alpha'; |
| 249 li.innerText = text; | 249 li.innerText = text; |
| 250 | 250 |
| 251 ul.appendChild(li); | 251 ul.appendChild(li); |
| 252 } | 252 } |
| 253 } | 253 } |
| 254 | 254 |
| 255 /** | 255 /** |
| 256 * Addes '0's to |number| as a string. |width| is length of the string | 256 * Handles the message of 'countryUpdated' from the browser. |
| 257 * | |
| 258 * @param {Object} details the object containing the country | |
| 259 * information. | |
| 260 */ | |
| 261 function onCountryUpdated(details) { | |
| 262 var p; | |
| 263 p = $('country-override'); | |
| 264 | |
| 265 p.innerHTML = ''; | |
| 266 | |
| 267 if ('country' in details) { | |
| 268 var country = details['country']; | |
| 269 | |
| 270 var tooltip = document.createElement('div'); | |
|
Alexei Svitkine (slow)
2016/04/22 17:24:59
Nit: a tooltip is usually what appears on mouseove
hamelphi
2016/04/22 17:39:44
Done.
| |
| 271 tooltip.textContent = ( | |
| 272 'Changing this value will override the permanent country stored ' + | |
| 273 'by variations. This value is automatically updated with the ' + | |
| 274 'current country when Chrome is updated.'); | |
|
Alexei Svitkine (slow)
2016/04/22 17:24:59
Nit: I'd change the second sentence to:
Normally,
hamelphi
2016/04/22 17:39:44
Done.
| |
| 275 | |
| 276 var input = document.createElement('input'); | |
| 277 input.type = 'text'; | |
| 278 input.value = country; | |
| 279 | |
| 280 var button = document.createElement('button'); | |
| 281 button.textContent = 'update'; | |
| 282 button.addEventListener('click', function() { | |
| 283 chrome.send('overrideCountry', [input.value]); | |
| 284 }, false); | |
| 285 p.appendChild(tooltip); | |
| 286 p.appendChild(input); | |
| 287 p.appendChild(document.createElement('br')); | |
| 288 p.appendChild(button); | |
| 289 | |
| 290 if ('update' in details && details['update']) { | |
| 291 var div1 = document.createElement('div'); | |
| 292 div1.textContent = 'Permanent stored country updated.'; | |
| 293 var div2 = document.createElement('div'); | |
| 294 div2.textContent = ('You will need to restart your browser ' + | |
| 295 'for the changes to take effect.'); | |
| 296 p.appendChild(div1); | |
| 297 p.appendChild(div2); | |
| 298 } | |
| 299 } else { | |
| 300 p.textContent = 'Could not load country info from Variations.'; | |
| 301 } | |
| 302 } | |
| 303 | |
| 304 /** | |
| 305 * Adds '0's to |number| as a string. |width| is length of the string | |
| 257 * including '0's. | 306 * including '0's. |
| 258 * | 307 * |
| 259 * @param {string} number The number to be converted into a string. | 308 * @param {string} number The number to be converted into a string. |
| 260 * @param {number} width The width of the returned string. | 309 * @param {number} width The width of the returned string. |
| 261 * @return {string} The formatted string. | 310 * @return {string} The formatted string. |
| 262 */ | 311 */ |
| 263 function padWithZeros(number, width) { | 312 function padWithZeros(number, width) { |
| 264 var numberStr = number.toString(); | 313 var numberStr = number.toString(); |
| 265 var restWidth = width - numberStr.length; | 314 var restWidth = width - numberStr.length; |
| 266 if (restWidth <= 0) | 315 if (restWidth <= 0) |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 switch (message) { | 447 switch (message) { |
| 399 case 'languageDetectionInfoAdded': | 448 case 'languageDetectionInfoAdded': |
| 400 onLanguageDetectionInfoAdded(details); | 449 onLanguageDetectionInfoAdded(details); |
| 401 break; | 450 break; |
| 402 case 'prefsUpdated': | 451 case 'prefsUpdated': |
| 403 onPrefsUpdated(details); | 452 onPrefsUpdated(details); |
| 404 break; | 453 break; |
| 405 case 'supportedLanguagesUpdated': | 454 case 'supportedLanguagesUpdated': |
| 406 onSupportedLanguagesUpdated(details); | 455 onSupportedLanguagesUpdated(details); |
| 407 break; | 456 break; |
| 457 case 'countryUpdated': | |
| 458 onCountryUpdated(details); | |
| 459 break; | |
| 408 case 'translateErrorDetailsAdded': | 460 case 'translateErrorDetailsAdded': |
| 409 onTranslateErrorDetailsAdded(details); | 461 onTranslateErrorDetailsAdded(details); |
| 410 break; | 462 break; |
| 411 case 'translateEventDetailsAdded': | 463 case 'translateEventDetailsAdded': |
| 412 onTranslateEventDetailsAdded(details); | 464 onTranslateEventDetailsAdded(details); |
| 413 break; | 465 break; |
| 414 default: | 466 default: |
| 415 console.error('Unknown message:', message); | 467 console.error('Unknown message:', message); |
| 416 break; | 468 break; |
| 417 } | 469 } |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 446 /** | 498 /** |
| 447 * The entry point of the UI. | 499 * The entry point of the UI. |
| 448 */ | 500 */ |
| 449 function main() { | 501 function main() { |
| 450 cr.doc.addEventListener('DOMContentLoaded', | 502 cr.doc.addEventListener('DOMContentLoaded', |
| 451 cr.translateInternals.initialize); | 503 cr.translateInternals.initialize); |
| 452 } | 504 } |
| 453 | 505 |
| 454 main(); | 506 main(); |
| 455 })(); | 507 })(); |
| OLD | NEW |