From c23cfe5f9cf18f6aea1e4f7977b7b200b0d4df59 Mon Sep 17 00:00:00 2001 From: Lloyd Hilaiel <lloyd@hilaiel.com> Date: Fri, 13 Jul 2012 14:15:01 -0600 Subject: [PATCH] write a failing test for issue #2011 --- lib/static/views.js | 3 +++ resources/views/i18n_fallback_test.ejs | 1 + tests/i18n-tests.js | 14 ++++++++++++-- tests/i18n_test_files/bg/messages.json | 4 ++++ 4 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 resources/views/i18n_fallback_test.ejs diff --git a/lib/static/views.js b/lib/static/views.js index 608a2baf0..6bb135374 100644 --- a/lib/static/views.js +++ b/lib/static/views.js @@ -202,6 +202,9 @@ exports.setup = function(app) { app.get('/i18n_test', function(req, res) { renderCachableView(req, res, 'i18n_test.ejs', { layout: false, title: 'l10n testing title' }); }); + app.get('/i18n_fallback_test', function(req, res) { + renderCachableView(req, res, 'i18n_fallback_test.ejs', { layout: false, title: 'l10n testing title' }); + }); } else { // this is stage or production, explicitly disable all resources under /test app.get(/^\/test/, function(req, res) { diff --git a/resources/views/i18n_fallback_test.ejs b/resources/views/i18n_fallback_test.ejs new file mode 100644 index 000000000..10015bc61 --- /dev/null +++ b/resources/views/i18n_fallback_test.ejs @@ -0,0 +1 @@ +<%- gettext("This is not translated") %> diff --git a/tests/i18n-tests.js b/tests/i18n-tests.js index 50bb82dad..b2abd422e 100755 --- a/tests/i18n-tests.js +++ b/tests/i18n-tests.js @@ -111,13 +111,14 @@ process.env['SUPPORTED_LANGUAGES'] = 'en,bg,it-CH'; // now let's start up our servers start_stop.addStartupBatches(suite); -function getTestTemplate(langs) { +function getTestTemplate(langs, tp) { + tp = tp || '/i18n_test'; return function() { var self = this; var req = http.request({ host: '127.0.0.1', port: 10002, - path: '/i18n_test', + path: tp, method: "GET", headers: { 'Accept-Language': langs } }, function (res) { @@ -171,7 +172,16 @@ suite.addBatch({ assert.strictEqual(200, r.code); assert.strictEqual(r.body.trim(), "Прова? Прова? Четери, пет, шещ?"); } + }, + // test .json extraction fallback when translation is the empty string + "bulgarian accept headers without a translation": { + topic: getTestTemplate('bg', '/i18n_fallback_test'), + "return a non-translated string" : function(err, r) { + assert.strictEqual(200, r.code); + assert.strictEqual(r.body.trim(), "This is not translated"); + } } + }); // and let's stop them servers diff --git a/tests/i18n_test_files/bg/messages.json b/tests/i18n_test_files/bg/messages.json index 007689c41..95da66000 100644 --- a/tests/i18n_test_files/bg/messages.json +++ b/tests/i18n_test_files/bg/messages.json @@ -3,6 +3,10 @@ var json_locale_data = { "This is a translation <strong>test</strong> string.": [ null, "Прова? Прова? Четери, пет, шещ?" + ], + "This is not translated": [ + null, + "" ] } }; -- GitLab