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 input = document.createElement('textarea'); | |
|
Alexei Svitkine (slow)
2016/04/20 21:48:41
Instead of a textarea, use an input control. This
hamelphi
2016/04/21 14:25:09
Done.
| |
| 271 input.cols = '5'; | |
| 272 input.rows = '1'; | |
| 273 input.value = country; | |
| 274 | |
| 275 var button = document.createElement('button'); | |
|
Alexei Svitkine (slow)
2016/04/20 21:48:41
What's the reason for creating these programmatica
hamelphi
2016/04/21 14:25:09
Then we can display something else if we can't get
| |
| 276 button.textContent = 'update'; | |
| 277 button.classList.add('override_country'); | |
| 278 button.addEventListener('click', function() { | |
| 279 chrome.send('overrideCountry', [input.value]); | |
| 280 }, false); | |
| 281 p.appendChild(input); | |
| 282 p.appendChild(document.createElement('br')); | |
| 283 p.appendChild(button); | |
| 284 | |
| 285 if ('update' in details && details['update']) { | |
| 286 var div1 = document.createElement('div'); | |
| 287 div1.textContent = 'Permanent stored country updated.'; | |
| 288 var div2 = document.createElement('div'); | |
| 289 div2.textContent = ('You will need to restart your browser ' + | |
| 290 'for the changes to take effect.'); | |
| 291 p.appendChild(div1); | |
| 292 p.appendChild(div2); | |
| 293 } | |
| 294 } else { | |
| 295 p.textContent = 'Could not load country info from Variations.'; | |
| 296 } | |
| 297 } | |
| 298 | |
| 299 /** | |
| 300 * Adds '0's to |number| as a string. |width| is length of the string | |
| 257 * including '0's. | 301 * including '0's. |
| 258 * | 302 * |
| 259 * @param {string} number The number to be converted into a string. | 303 * @param {string} number The number to be converted into a string. |
| 260 * @param {number} width The width of the returned string. | 304 * @param {number} width The width of the returned string. |
| 261 * @return {string} The formatted string. | 305 * @return {string} The formatted string. |
| 262 */ | 306 */ |
| 263 function padWithZeros(number, width) { | 307 function padWithZeros(number, width) { |
| 264 var numberStr = number.toString(); | 308 var numberStr = number.toString(); |
| 265 var restWidth = width - numberStr.length; | 309 var restWidth = width - numberStr.length; |
| 266 if (restWidth <= 0) | 310 if (restWidth <= 0) |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 switch (message) { | 442 switch (message) { |
| 399 case 'languageDetectionInfoAdded': | 443 case 'languageDetectionInfoAdded': |
| 400 onLanguageDetectionInfoAdded(details); | 444 onLanguageDetectionInfoAdded(details); |
| 401 break; | 445 break; |
| 402 case 'prefsUpdated': | 446 case 'prefsUpdated': |
| 403 onPrefsUpdated(details); | 447 onPrefsUpdated(details); |
| 404 break; | 448 break; |
| 405 case 'supportedLanguagesUpdated': | 449 case 'supportedLanguagesUpdated': |
| 406 onSupportedLanguagesUpdated(details); | 450 onSupportedLanguagesUpdated(details); |
| 407 break; | 451 break; |
| 452 case 'countryUpdated': | |
| 453 onCountryUpdated(details); | |
| 454 break; | |
| 408 case 'translateErrorDetailsAdded': | 455 case 'translateErrorDetailsAdded': |
| 409 onTranslateErrorDetailsAdded(details); | 456 onTranslateErrorDetailsAdded(details); |
| 410 break; | 457 break; |
| 411 case 'translateEventDetailsAdded': | 458 case 'translateEventDetailsAdded': |
| 412 onTranslateEventDetailsAdded(details); | 459 onTranslateEventDetailsAdded(details); |
| 413 break; | 460 break; |
| 414 default: | 461 default: |
| 415 console.error('Unknown message:', message); | 462 console.error('Unknown message:', message); |
| 416 break; | 463 break; |
| 417 } | 464 } |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 446 /** | 493 /** |
| 447 * The entry point of the UI. | 494 * The entry point of the UI. |
| 448 */ | 495 */ |
| 449 function main() { | 496 function main() { |
| 450 cr.doc.addEventListener('DOMContentLoaded', | 497 cr.doc.addEventListener('DOMContentLoaded', |
| 451 cr.translateInternals.initialize); | 498 cr.translateInternals.initialize); |
| 452 } | 499 } |
| 453 | 500 |
| 454 main(); | 501 main(); |
| 455 })(); | 502 })(); |
| OLD | NEW |