summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPhilip Chimento <philip@endlessm.com>2015-05-19 11:31:25 -0700
committerPhilip Chimento <philip@endlessm.com>2015-05-21 13:22:23 -0700
commita58f5454c8b046ba4f17534a88db1c19ac22b822 (patch)
treeb25eca159bc2d6f54882e9f29cf0818ad15f9c7b /test
parente2729f045a9459c9a320c617ac6e599814744e56 (diff)
Expose gettext() to client-side JS
This exposes the function set by webhelper.set_gettext() to the client- side Javascript as a gettext() function, defined on the global window object. This allows apps to translate messages that are generated at runtime, not just messages in static HTML. Some often-used JavaScriptCore operations can be turned into separate functions, which we can put in a separate source file. This is in anticipation of the next commit where we will define another function property of the global object. [endlessm/eos-sdk#291]
Diffstat (limited to 'test')
-rw-r--r--test/smoke-tests/webhelper/webview2.js4
-rw-r--r--test/webhelper/testTranslate2.js16
2 files changed, 20 insertions, 0 deletions
diff --git a/test/smoke-tests/webhelper/webview2.js b/test/smoke-tests/webhelper/webview2.js
index ec029c9..03ed560 100644
--- a/test/smoke-tests/webhelper/webview2.js
+++ b/test/smoke-tests/webhelper/webview2.js
@@ -43,6 +43,10 @@ message from parameter in this URL</a></p> \
<p>This is text that will be italicized: <span name="translatable">Hello, \
world!</span></p> \
\
+<p><button onclick="alert(gettext(\'I came from gettext\'));"> \
+ Click me to use gettext \
+</button></p> \
+\
</body> \
</html>';
diff --git a/test/webhelper/testTranslate2.js b/test/webhelper/testTranslate2.js
index 67f7b1f..852c3a1 100644
--- a/test/webhelper/testTranslate2.js
+++ b/test/webhelper/testTranslate2.js
@@ -116,4 +116,20 @@ describe('WebHelper2 translator', function () {
webview.load_html('<html><body></body></html>', null);
});
});
+
+ describe('used from client-side Javascript', function () {
+ it('translates a string', function (done) {
+ let webview = new WebKit2.WebView();
+ let gettext_spy = jasmine.createSpy('gettext_spy').and.callFake((s) => {
+ Mainloop.quit('webhelper2');
+ return s;
+ });
+ webhelper.set_gettext(gettext_spy);
+ webview.load_html('<html><body><script type="text/javascript">gettext("Translate Me");</script></body></html>',
+ null);
+ Mainloop.run('webhelper2');
+ expect(gettext_spy).toHaveBeenCalledWith('Translate Me');
+ done();
+ });
+ });
});