diff --git a/src/parser.js b/src/parser.js index 28ee42a..b9f931b 100644 --- a/src/parser.js +++ b/src/parser.js @@ -80,7 +80,7 @@ function Parser(customKeywordSpec) { // literals). `(?:${stringPatternGroup})`, // Optional comma for multiple parameters. - '(?:\\s*,\\s*)?', + '(?:\\s*,\\s*)?((?:\\\\.|[^()\\\\])*)?', ')+', ')', ].join(''), 'g'); @@ -97,12 +97,13 @@ function Parser(customKeywordSpec) { Parser.prototype.parse = function parse(template) { const result = {}; let match; - // eslint-disable-next-line no-cond-assign while ((match = this.expressionPattern.exec(template)) !== null) { const keyword = match[1]; const params = match[2].match(this.stringPattern).map(trim).map(trimQuotes).map(unescapeQuotes); - + if(match[6]) { + params.push(match[6].trim()) + } const spec = this.keywordSpec[keyword]; const msgidIndex = spec.msgid; const msgid = params[msgidIndex]; diff --git a/test/fixtures/singular.vue b/test/fixtures/singular.vue index 526a752..4dddc31 100644 --- a/test/fixtures/singular.vue +++ b/test/fixtures/singular.vue @@ -6,6 +6,7 @@
{{ $t("\"double escape\"") }}
{{ $t("word \"escaped, word\", with comma") }}
{{ $t("ending with an escaped quote\"") }}
+{{ $ngettext('plural string', num) }}
@@ -15,8 +16,9 @@ return { t1: this.$t('data \'single escape\''), t2: this.$t("data \"double escape\""), - t3: this.$t("Description") + t3: this.$t("Description"), + num: 5 }; } } - \ No newline at end of file + diff --git a/test/test.js b/test/test.js index 50e6cd2..cb60123 100644 --- a/test/test.js +++ b/test/test.js @@ -3,26 +3,28 @@ const fs = require('fs'); const test = require('ava'); test('default', t => { - t.deepEqual((new Parser()).keywordSpec.$t, { msgid : 0 }, - 'should have default keyword spec when none is passed'); + t.deepEqual((new Parser()).keywordSpec.$t, { msgid: 0 }, + 'should have default keyword spec when none is passed'); }); test.cb('singular', t => { - fs.readFile(__dirname + '/fixtures/singular.vue', {encoding: 'utf8'}, (err, data) => { - if (err) throw err; + fs.readFile(__dirname + '/fixtures/singular.vue', { encoding: 'utf8' }, (err, data) => { + if (err) throw err; - const result = (new Parser()).parse(data); - t.is(typeof result, 'object'); - t.true('This is a title' in result); - t.true('This is wrapped in single quotes' in result); - t.true('\'single escape\'' in result); - t.true('"double escape"' in result); - t.true('word "escaped, word", with comma' in result); - t.true('ending with an escaped quote"' in result); - t.true('data \'single escape\'' in result); - t.true('data "double escape"' in result); - t.true('Description' in result); - t.is(result['Description'].line.length, 3); - t.end(); - }); + const result = (new Parser()).parse(data); + t.is(typeof result, 'object'); + t.true('This is a title' in result); + t.true('This is wrapped in single quotes' in result); + t.true('\'single escape\'' in result); + t.true('"double escape"' in result); + t.true('word "escaped, word", with comma' in result); + t.true('ending with an escaped quote"' in result); + t.true('data \'single escape\'' in result); + t.true('data "double escape"' in result); + t.true('Description' in result); + t.true('plural string' in result); + t.true(result['plural string'].plural==='num') + t.is(result['Description'].line.length, 3); + t.end(); + }); });