summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPhilip Chimento <philip@endlessm.com>2015-06-18 13:53:01 -0700
committerPhilip Chimento <philip@endlessm.com>2015-06-18 13:53:01 -0700
commit0e2e2b25766b33e98860b59d1363be528477519d (patch)
treefa2e6fea86af4db60c885433fd10cfb1d8466cdb /test
parentb290a1214d0e78fb0a613b232b15d3e423292e1e (diff)
Handle excess whitespace in strings
Whitespace between words and tags doesn't matter to HTML. Indeed, the text in a translatable element may be formatted any way over any number of lines, so we normalize all consecutive whitespace to be just one space character and strip whitespace from the beginning and end of the strings. This is so that translators are not confronted with strange newlines and whitespace on Transifex. [endlessm/eos-sdk#3291]
Diffstat (limited to 'test')
-rw-r--r--test/tools/test.html4
-rw-r--r--test/tools/testHtmlExtractor.js4
-rw-r--r--test/webhelper/testTranslate2.js19
3 files changed, 20 insertions, 7 deletions
diff --git a/test/tools/test.html b/test/tools/test.html
index 4dfda70..9f7e341 100644
--- a/test/tools/test.html
+++ b/test/tools/test.html
@@ -15,6 +15,10 @@
<nav id="finance-nav">
</nav>
</div>
+ <p name="translatable">
+ This is a string that is spread over multiple lines,
+ but that doesn't matter to HTML.
+ </p>
</section>
</body>
</html>
diff --git a/test/tools/testHtmlExtractor.js b/test/tools/testHtmlExtractor.js
index 4f46706..88215ef 100644
--- a/test/tools/testHtmlExtractor.js
+++ b/test/tools/testHtmlExtractor.js
@@ -7,7 +7,9 @@ _("Finance Builder");\n\
// TRANSLATORS: This is a test of UTF-8 encoded characters\n\
_("My Bü∂get");\n\
#line 13 "test/tools/test.html"\n\
-_("Choose a template");\n';
+_("Choose a template");\n\
+#line 21 "test/tools/test.html"\n\
+_("This is a string that is spread over multiple lines, but that doesn\'t matter to HTML.");\n'
describe('eos-html-extractor', function () {
it('works correctly at a minimum', function () {
diff --git a/test/webhelper/testTranslate2.js b/test/webhelper/testTranslate2.js
index b34c4cf..207f3b5 100644
--- a/test/webhelper/testTranslate2.js
+++ b/test/webhelper/testTranslate2.js
@@ -87,9 +87,10 @@ describe('WebHelper2 translator', function () {
});
describe('translating a page', function () {
- let webview;
+ let webview, gettext_spy;
+ const MINIMAL_HTML = '<p name="translatable">Translate Me</p>';
- function run_loop() {
+ function run_loop(html=MINIMAL_HTML) {
webview.connect('load-changed', (webview, event) => {
if (event === WebKit2.LoadEvent.FINISHED) {
webhelper.translate_html(webview, null, (obj, res) => {
@@ -98,18 +99,17 @@ describe('WebHelper2 translator', function () {
});
}
});
- webview.load_html('<html><body><p name="translatable">Translate Me</p></body></html>',
- null);
+ webview.load_html('<html><body>' + html + '</body></html>', null);
Mainloop.run('webhelper2');
}
beforeEach(function () {
webview = new WebKit2.WebView();
+ gettext_spy = jasmine.createSpy('gettext_spy').and.callFake((s) => s);
+ webhelper.set_gettext(gettext_spy);
});
it('translates a string', function () {
- let gettext_spy = jasmine.createSpy('gettext_spy').and.callFake((s) => s);
- webhelper.set_gettext(gettext_spy);
run_loop();
expect(gettext_spy).toHaveBeenCalledWith('Translate Me');
});
@@ -138,6 +138,13 @@ describe('WebHelper2 translator', function () {
});
webview.load_html('<html><body></body></html>', null);
});
+
+ it('normalizes a string before translating it', function () {
+ run_loop('<p name="translatable">\n\
+ Translate Me\n\
+ </p>');
+ expect(gettext_spy).toHaveBeenCalledWith('Translate Me');
+ });
});
describe('used from client-side Javascript', function () {