diff options
author | Felipe Erias Morandeira <femorandeira@igalia.com> | 2013-06-24 16:29:49 +0100 |
---|---|---|
committer | Felipe Erias Morandeira <femorandeira@igalia.com> | 2013-06-24 16:29:49 +0100 |
commit | fe844f61937d3af03577488362dc116abade2c8d (patch) | |
tree | 1ddbbcfaf1a50ff2db891fb17048abb19d86130e /test/smoke-tests | |
parent | 08ba6254f1a24456667998106ad1af36a718171f (diff) |
Experimenting with translations.
[endlessm/eos-sdk#113]
Diffstat (limited to 'test/smoke-tests')
-rw-r--r-- | test/smoke-tests/webview.js | 33 | ||||
-rw-r--r-- | test/smoke-tests/webview/first_page.html | 6 |
2 files changed, 36 insertions, 3 deletions
diff --git a/test/smoke-tests/webview.js b/test/smoke-tests/webview.js index 94a873f..63a2c23 100644 --- a/test/smoke-tests/webview.js +++ b/test/smoke-tests/webview.js @@ -16,9 +16,16 @@ const TestApplication = new Lang.Class({ /* *** CONVENIENCE LIBRARY *** */ + _onLoadStatus: function (web_view) { + if (web_view.load_status == WebKit.LoadStatus.FINISHED) { + // now we translate to Brazilian Portuguese + this._translateHTML (web_view, 'pt_BR'); + } + }, + _onNavigationPolicyDecisionRequested: function(web_view, frame, request, - navigation_action, policy_decision, - user_data) { + navigation_action, policy_decision, + user_data) { // lame way of getting function name and parameters, without error check let uri = request.get_uri(); @@ -61,10 +68,27 @@ const TestApplication = new Lang.Class({ // WebKit.DOMDocument let dom = webview.get_dom_document(); - // WebKitDOMElement + // WebKit.DOMElement return dom.get_element_by_id(id); }, + _translateHTML: function(webview, lang) { + let dom = webview.get_dom_document(); + + // WebKit.DOMNodeList + let translatable = dom.get_elements_by_name('translatable'); + + for (var i = 0 ; i < translatable.get_length() ; i++) { + // WebKit.DOMNode + let element = translatable.item(i); + + if (element.lang != lang) { + // TODO here is where we would do the translation + element.inner_text = '(TRANSLATE FROM '+element.lang+' TO '+lang+')'; + } + } + }, + /* *** APP-SPECIFIC FUNCTIONS *** */ actions: { @@ -119,6 +143,9 @@ const TestApplication = new Lang.Class({ let target = cwd + '/test/smoke-tests/webview/first_page.html'; this._webview.load_uri(GLib.filename_to_uri(target, null)); + this._webview.connect('notify::load-status', + Lang.bind(this, this._onLoadStatus)); + this._webview.connect('navigation-policy-decision-requested', Lang.bind(this, this._onNavigationPolicyDecisionRequested)); diff --git a/test/smoke-tests/webview/first_page.html b/test/smoke-tests/webview/first_page.html index 5b33c48..e2c2c1e 100644 --- a/test/smoke-tests/webview/first_page.html +++ b/test/smoke-tests/webview/first_page.html @@ -46,5 +46,11 @@ body { <a href="endless://addStars?id=starspan">I want stars!</a> <span id="starspan" /> </p> +<p> +This is text that will not be translated: <span name="translatable" lang="pt_BR">Bom dia, mundo!</span> +<br/> +This is text that will be translated: <span name="translatable" lang="en_US">Hello, world!</span> +</p> + </body> </html>
\ No newline at end of file |