OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This code is used in conjunction with the Google Translate Element script. | 5 // This code is used in conjunction with the Google Translate Element script. |
6 // It is executed in an isolated world of a page to translate it from one | 6 // It is executed in an isolated world of a page to translate it from one |
7 // language to another. | 7 // language to another. |
8 // It should be included in the page before the Translate Element script. | 8 // It should be included in the page before the Translate Element script. |
9 | 9 |
10 var cr = {}; | 10 var cr = {}; |
11 | 11 |
12 cr.googleTranslate = (function(key) { | 12 /** |
| 13 * An object to provide functions to interact with the Translate library. |
| 14 * @type {object} |
| 15 */ |
| 16 cr.googleTranslate = (function() { |
13 /** | 17 /** |
14 * The Translate Element library's instance. | 18 * The Translate Element library's instance. |
15 * @type {object} | 19 * @type {object} |
16 */ | 20 */ |
17 var lib; | 21 var lib; |
18 | 22 |
19 /** | 23 /** |
20 * A flag representing if the Translate Element library is initialized. | 24 * A flag representing if the Translate Element library is initialized. |
21 * @type {boolean} | 25 * @type {boolean} |
22 */ | 26 */ |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 }, | 256 }, |
253 | 257 |
254 /** | 258 /** |
255 * Entry point called by the Translate Element once it has been injected in | 259 * Entry point called by the Translate Element once it has been injected in |
256 * the page. | 260 * the page. |
257 */ | 261 */ |
258 onTranslateElementLoad: function() { | 262 onTranslateElementLoad: function() { |
259 loadedTime = performance.now(); | 263 loadedTime = performance.now(); |
260 try { | 264 try { |
261 lib = google.translate.TranslateService({ | 265 lib = google.translate.TranslateService({ |
262 'key': key, | 266 // translateApiKey is predefined by translate_script.cc. |
| 267 'key': translateApiKey, |
263 'useSecureConnection': true | 268 'useSecureConnection': true |
264 }); | 269 }); |
| 270 translateApiKey = undefined; |
265 } catch (err) { | 271 } catch (err) { |
266 error = true; | 272 error = true; |
| 273 translateApiKey = undefined; |
267 return; | 274 return; |
268 } | 275 } |
269 // The TranslateService is not available immediately as it needs to start | 276 // The TranslateService is not available immediately as it needs to start |
270 // Flash. Let's wait until it is ready. | 277 // Flash. Let's wait until it is ready. |
271 checkLibReady(); | 278 checkLibReady(); |
272 } | 279 } |
273 }; | 280 }; |
274 })/* Calling code '(|key|);' will be appended by TranslateHelper in C++ here. */ | 281 })(); |
OLD | NEW |