Skip to content

Commit

Permalink
fix interpolation with option skipOnVariables when there are multiple…
Browse files Browse the repository at this point in the history
… placeholders #1490
  • Loading branch information
adrai committed Jul 16, 2020
1 parent 7826260 commit 7b57445
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
### 19.6.2

- fix interpolation with option skipOnVariables when there are multiple placeholders [1490](https://github.com/i18next/i18next/issues/1490)

### 19.6.1

- extend interpolation option skipOnVariables [1488](https://github.com/i18next/i18next/pull/1488)
Expand Down
1 change: 1 addition & 0 deletions i18next.js
Expand Up @@ -1458,6 +1458,7 @@
value = typeof temp === 'string' ? temp : '';
} else if (skipOnVariables) {
value = match[0];
continue;
} else {
_this.logger.warn("missed to pass in variable ".concat(match[1], " for interpolating ").concat(str));

Expand Down
2 changes: 1 addition & 1 deletion i18next.min.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions index.d.ts
Expand Up @@ -99,6 +99,12 @@ export interface InterpolationOptions {
* @default 1000
*/
maxReplaces?: number;

/**
* If true, it will skip to interpolate the variables
* @default false
*/
skipOnVariables?: boolean;
}

export interface ReactOptions {
Expand Down
1 change: 1 addition & 0 deletions src/Interpolator.js
Expand Up @@ -126,6 +126,7 @@ class Interpolator {
value = typeof temp === 'string' ? temp : '';
} else if (skipOnVariables) {
value = match[0];
continue; // this makes sure it continues to detect others
} else {
this.logger.warn(`missed to pass in variable ${match[1]} for interpolating ${str}`);
value = '';
Expand Down
5 changes: 5 additions & 0 deletions test/i18next.interpolation.skipOnVariables.spec.js
Expand Up @@ -14,6 +14,7 @@ describe('i18next.interpolation.nesting', () => {
en: {
translation: {
key: 'value {{a}}',
key2: 'value {{a}} {{b}}',
keyWithoutVar: 'value',
nested: 'nested stuff',
keyWithNest: '$t(nested2) value',
Expand Down Expand Up @@ -51,6 +52,10 @@ describe('i18next.interpolation.nesting', () => {
args: ['key', { a: '{{nested}}' }],
expected: 'value {{nested}}',
},
{
args: ['key2', { a: '{{nested}}', b: 'something' }],
expected: 'value {{nested}} something',
},
];

tests.forEach(test => {
Expand Down

0 comments on commit 7b57445

Please sign in to comment.