Skip to content

Commit

Permalink
fix: translation not working when using __ with a single parameter (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jjoselv authored and bcoe committed Aug 11, 2018
1 parent 664b265 commit f449aea
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -5,3 +5,4 @@ node_modules/
test.js
coverage
package-lock.json
.npmrc
2 changes: 1 addition & 1 deletion lib/validation.js
Expand Up @@ -292,7 +292,7 @@ module.exports = function validation (yargs, usage, y18n) {
// we default keys to 'undefined' that have been configured, we should not
// apply conflicting check unless they are a value other than 'undefined'.
if (value && argv[key] !== undefined && argv[value] !== undefined) {
usage.fail(__(`Arguments ${key} and ${value} are mutually exclusive`))
usage.fail(__('Arguments %s and %s are mutually exclusive', key, value))
}
})
}
Expand Down
3 changes: 2 additions & 1 deletion locales/pirate.json
Expand Up @@ -8,5 +8,6 @@
"other": "Ye be havin' to set the followin' arguments land lubber: %s"
},
"Show help": "Parlay this here code of conduct",
"Show version number": "'Tis the version ye be askin' fer"
"Show version number": "'Tis the version ye be askin' fer",
"Arguments %s and %s are mutually exclusive" : "Yon scurvy dogs %s and %s be as bad as rum and a prudish wench"
}
24 changes: 23 additions & 1 deletion test/validation.js
Expand Up @@ -3,7 +3,7 @@

const checkUsage = require('./helpers/utils').checkOutput
const expect = require('chai').expect
const yargs = require('../')
let yargs = require('../')

require('chai').should()

Expand Down Expand Up @@ -285,6 +285,28 @@ describe('validation tests', () => {
})
.parse()
})

function loadLocale (locale) {
delete require.cache[require.resolve('../')]
delete require.cache[require.resolve('os-locale')]
yargs = require('../')
process.env.LC_ALL = locale
}

it('should use appropriate translation', done => {
loadLocale('pirate')
try {
yargs(['-f', '-b'])
.conflicts('f', 'b')
.fail(msg => {
msg.should.equal('Yon scurvy dogs f and b be as bad as rum and a prudish wench')
return done()
})
.parse()
} finally {
loadLocale('en_US.UTF-8')
}
})
})

describe('demand', () => {
Expand Down

0 comments on commit f449aea

Please sign in to comment.