Skip to content

Commit

Permalink
Merge 4c1849a into 2a96f26
Browse files Browse the repository at this point in the history
  • Loading branch information
emmerich committed Aug 3, 2016
2 parents 2a96f26 + 4c1849a commit ede75a5
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 2 deletions.
4 changes: 2 additions & 2 deletions i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ module.exports = (function() {
var mutator = localeMutator(locale, singular);

if (plural) {
if (!accessor()) {
if (accessor() == null) {
mutator({
'one': defaultSingular || singular,
'other': defaultPlural || plural
Expand All @@ -895,7 +895,7 @@ module.exports = (function() {
}
}

if (!accessor()) {
if (accessor() == null) {
mutator(defaultSingular || singular);
write(locale);
}
Expand Down
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"Empty": "",
"Hello": "Hello",
"Hello %s, how are you today?": "Hello %s, how are you today?",
"weekend": "weekend",
Expand Down
5 changes: 5 additions & 0 deletions test/i18n.api.global.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ describe('Module API', function() {
});

describe('i18nTranslate', function() {
it('should return an empty string if the translation is an empty string', function() {
i18n.setLocale('en');
should.equal(__('Empty'), '');
});

it('should return en translations as expected', function() {
i18n.setLocale('en');
should.equal(__('Hello'), 'Hello');
Expand Down
7 changes: 7 additions & 0 deletions test/i18n.api.local.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ describe('Module API', function () {
afterEach(function() {
i18n.setLocale('en');
});

it('should return an empty string if the translation is an empty string', function(done) {
i18n.setLocale(req, 'en').should.equal('en');
req.__('Empty').should.equal('');
done();
});

it('has to use local translation in en', function (done) {
i18n.setLocale(req, 'en').should.equal('en');
req.__('Hello').should.equal('Hello');
Expand Down
69 changes: 69 additions & 0 deletions test/i18n.missingPhrases.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*jslint nomen: true, undef: true, sloppy: true, white: true, stupid: true, passfail: false, node: true, plusplus: true, indent: 2 */

// now with coverage suport
var i18n = require('../i18n'),
should = require("should");

describe('Missing Phrases', function () {

beforeEach(function() {

i18n.configure({
locales: ['en', 'de'],
fallbacks: {'nl': 'de'},
directory: './locales',
updateFiles: false,
syncFiles: false
});

});

describe('Local Module API', function () {
var req = {
request: "GET /test",
__: i18n.__,
__n: i18n.__n,
locale: {},
headers: {}
};

beforeEach(function() {
i18n.configure({
locales: ['en', 'de', 'en-GB'],
defaultLocale: 'en',
directory: './locales',
register: req,
updateFiles: false,
syncFiles: false
});
});

describe('i18nTranslate', function () {
it('should return the key if the translation does not exist', function(done) {
i18n.setLocale(req, 'en').should.equal('en');
req.__('DoesNotExist').should.equal('DoesNotExist');
done();
});
});
});

describe('Global Module API', function () {
beforeEach(function() {
i18n.configure({
locales: ['en', 'de', 'en-GB'],
defaultLocale: 'en',
directory: './locales',
register: global,
updateFiles: false,
syncFiles: false
});
});

describe('i18nTranslate', function () {
it('should return the key if the translation does not exist', function() {
i18n.setLocale('en');
should.equal(__('DoesNotExist'), 'DoesNotExist');
});
});
});
});

0 comments on commit ede75a5

Please sign in to comment.