From f449aead59f44f826cbcf570cf849c4a59c79c81 Mon Sep 17 00:00:00 2001 From: Juanjo Lopez Date: Sun, 12 Aug 2018 00:27:15 +0200 Subject: [PATCH] fix: translation not working when using __ with a single parameter (#1183) --- .gitignore | 1 + lib/validation.js | 2 +- locales/pirate.json | 3 ++- test/validation.js | 24 +++++++++++++++++++++++- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 3e4ea0eb4..f8a81bebc 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ node_modules/ test.js coverage package-lock.json +.npmrc diff --git a/lib/validation.js b/lib/validation.js index d72ad5270..e9bbb12bc 100644 --- a/lib/validation.js +++ b/lib/validation.js @@ -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)) } }) } diff --git a/locales/pirate.json b/locales/pirate.json index 1f4e19e65..dcb5cb753 100644 --- a/locales/pirate.json +++ b/locales/pirate.json @@ -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" } diff --git a/test/validation.js b/test/validation.js index c9d0593e6..788ca70f3 100644 --- a/test/validation.js +++ b/test/validation.js @@ -3,7 +3,7 @@ const checkUsage = require('./helpers/utils').checkOutput const expect = require('chai').expect -const yargs = require('../') +let yargs = require('../') require('chai').should() @@ -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', () => {