Skip to content

Commit

Permalink
Merge b778af2 into ed635a1
Browse files Browse the repository at this point in the history
  • Loading branch information
daliusd committed Feb 26, 2019
2 parents ed635a1 + b778af2 commit 9bee5fe
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
11 changes: 5 additions & 6 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,17 +368,16 @@ class Parser {
// `\s` matches a single whitespace character, which includes spaces, tabs, form feeds, line feeds and other unicode spaces.
const matchSpecialCharacters = '[\\r\\n\\s]*';
const stringGroup =
'(' +
matchSpecialCharacters + '(' +
// backtick (``)
matchSpecialCharacters + '`(?:[^`\\\\]|\\\\(?:.|$))*`' +
'`(?:[^`\\\\]|\\\\(?:.|$))*`' +
'|' +
// double quotes ("")
matchSpecialCharacters + '"(?:[^"\\\\]|\\\\(?:.|$))*"' +
'"(?:[^"\\\\]|\\\\(?:.|$))*"' +
'|' +
// single quote ('')
matchSpecialCharacters + '\'(?:[^\'\\\\]|\\\\(?:.|$))*\'' +
matchSpecialCharacters +
')';
'\'(?:[^\'\\\\]|\\\\(?:.|$))*\'' +
')' + matchSpecialCharacters;
const pattern = '(?:(?:^\\s*)|[^a-zA-Z0-9_])' +
'(?:' + matchFuncs + ')' +
'\\(' + stringGroup +
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/default-values.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
i18next.t('product.milk', { defaultValue: 'Milk' }); // output: 'Milk'
i18next.t('product.bread', 'Bread'); // output: 'Bread'
i18next.t('product.boiledEgg', 'Boiled Egg'); // output: 'Boiled Egg'
i18next.t(
'product.cheese',
'Cheese'
); // output: 'Cheese'
i18next.t('product.potato', '{{color}} potato', { color: 'white' }); // output: '{{color}} potato'
i18next.t(
'product.carrot',
'{{size}} carrot',
{ size: 'big' }
); // output: '{{size}} potato'
4 changes: 3 additions & 1 deletion test/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,9 @@ test('Default values test', (t) => {
'bread': 'Bread',
'milk': 'Milk',
'boiledEgg': 'Boiled Egg',
'potato': '{{color}} potato'
'cheese': 'Cheese',
'potato': '{{color}} potato',
'carrot': '{{size}} carrot',
}
}
}
Expand Down

0 comments on commit 9bee5fe

Please sign in to comment.