Skip to content
This repository has been archived by the owner on May 10, 2019. It is now read-only.

Commit

Permalink
write a failing test for issue #2011
Browse files Browse the repository at this point in the history
  • Loading branch information
lloyd committed Jul 13, 2012
1 parent 12cd056 commit c23cfe5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/static/views.js
Expand Up @@ -202,6 +202,9 @@ exports.setup = function(app) {
app.get('/i18n_test', function(req, res) { app.get('/i18n_test', function(req, res) {
renderCachableView(req, res, 'i18n_test.ejs', { layout: false, title: 'l10n testing title' }); 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 { } else {
// this is stage or production, explicitly disable all resources under /test // this is stage or production, explicitly disable all resources under /test
app.get(/^\/test/, function(req, res) { app.get(/^\/test/, function(req, res) {
Expand Down
1 change: 1 addition & 0 deletions resources/views/i18n_fallback_test.ejs
@@ -0,0 +1 @@
<%- gettext("This is not translated") %>
14 changes: 12 additions & 2 deletions tests/i18n-tests.js
Expand Up @@ -111,13 +111,14 @@ process.env['SUPPORTED_LANGUAGES'] = 'en,bg,it-CH';
// now let's start up our servers // now let's start up our servers
start_stop.addStartupBatches(suite); start_stop.addStartupBatches(suite);


function getTestTemplate(langs) { function getTestTemplate(langs, tp) {
tp = tp || '/i18n_test';
return function() { return function() {
var self = this; var self = this;
var req = http.request({ var req = http.request({
host: '127.0.0.1', host: '127.0.0.1',
port: 10002, port: 10002,
path: '/i18n_test', path: tp,
method: "GET", method: "GET",
headers: { 'Accept-Language': langs } headers: { 'Accept-Language': langs }
}, function (res) { }, function (res) {
Expand Down Expand Up @@ -171,7 +172,16 @@ suite.addBatch({
assert.strictEqual(200, r.code); assert.strictEqual(200, r.code);
assert.strictEqual(r.body.trim(), "Прова? Прова? Четери, пет, шещ?"); 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 // and let's stop them servers
Expand Down
4 changes: 4 additions & 0 deletions tests/i18n_test_files/bg/messages.json
Expand Up @@ -3,6 +3,10 @@ var json_locale_data = {
"This is a translation <strong>test</strong> string.": [ "This is a translation <strong>test</strong> string.": [
null, null,
"Прова? Прова? Четери, пет, шещ?" "Прова? Прова? Четери, пет, шещ?"
],
"This is not translated": [
null,
""
] ]
} }
}; };

0 comments on commit c23cfe5

Please sign in to comment.