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 injected in a page to translate it from one language to another. | 6 // It is injected in a page to translate it from one language to another. |
7 // It should be included in the page before the Translate Element script. | 7 // It should be included in the page before the Translate Element script. |
8 | 8 |
9 var cr = {}; | 9 var cr = {}; |
10 | 10 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 * @type {boolean} | 123 * @type {boolean} |
124 */ | 124 */ |
125 get error() { | 125 get error() { |
126 return error; | 126 return error; |
127 }, | 127 }, |
128 | 128 |
129 /** | 129 /** |
130 * The language the page translated was in. Is valid only after the page | 130 * The language the page translated was in. Is valid only after the page |
131 * has been successfully translated and the original language specified to | 131 * has been successfully translated and the original language specified to |
132 * the translate function was 'auto'. Is empty otherwise. | 132 * the translate function was 'auto'. Is empty otherwise. |
| 133 * Some versions of Element library don't provide |getDetectedLanguage| |
| 134 * function. In that case, this function returns 'und'. |
133 * @type {boolean} | 135 * @type {boolean} |
134 */ | 136 */ |
135 get sourceLang() { | 137 get sourceLang() { |
136 if (!libReady || !finished || error) | 138 if (!libReady || !finished || error) |
137 return ''; | 139 return ''; |
| 140 if (!lib.getDetectedLanguage) |
| 141 return 'und'; // defined as chrome::kUnknownLanguageCode in C++ world. |
138 return lib.getDetectedLanguage(); | 142 return lib.getDetectedLanguage(); |
139 }, | 143 }, |
140 | 144 |
141 /** | 145 /** |
142 * Time in msec from this script being injected to all server side scripts | 146 * Time in msec from this script being injected to all server side scripts |
143 * being loaded. | 147 * being loaded. |
144 * @type {number} | 148 * @type {number} |
145 */ | 149 */ |
146 get loadTime() { | 150 get loadTime() { |
147 if (loadedTime == 0) | 151 if (loadedTime == 0) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 } catch (err) { | 212 } catch (err) { |
209 error = true; | 213 error = true; |
210 return; | 214 return; |
211 } | 215 } |
212 // The TranslateService is not available immediately as it needs to start | 216 // The TranslateService is not available immediately as it needs to start |
213 // Flash. Let's wait until it is ready. | 217 // Flash. Let's wait until it is ready. |
214 checkLibReady(); | 218 checkLibReady(); |
215 } | 219 } |
216 }; | 220 }; |
217 })/* Calling code '(|key|);' will be appended by TranslateHelper in C++ here. */ | 221 })/* Calling code '(|key|);' will be appended by TranslateHelper in C++ here. */ |
OLD | NEW |