From fe844f61937d3af03577488362dc116abade2c8d Mon Sep 17 00:00:00 2001
From: Felipe Erias Morandeira
Date: Mon, 24 Jun 2013 16:29:49 +0100
Subject: Experimenting with translations. [endlessm/eos-sdk#113]
---
test/smoke-tests/webview.js | 33 +++++++++++++++++++++++++++++---
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 {
I want stars!
+
+This is text that will not be translated: Bom dia, mundo!
+
+This is text that will be translated: Hello, world!
+
+