Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

The default value of interpolation.skipOnVariables is falsy if other interpolation option is specified #1711

Closed
ishikawa opened this issue Dec 28, 2021 · 3 comments

Comments

@ishikawa
Copy link

@ishikawa ishikawa commented Dec 28, 2021

馃悰 Bug Report

According to the documentation, the default value of interpolation.skipOnVariables is true since v21.0.0. However, even in v21.6.3, interpolation.skipOnVariables seems to be set to falsy if other interpolation options are specified.

To Reproduce

Without any interporation options, the default values are provided by expected.

import i18n from 'i18next';

i18n
  .use(initReactI18next) // passes i18n down to react-i18next
  .init({ lng: 'en-US' });

console.log('>>> interpolation =', i18n.options.interpolation);
>>> interpolation = Object {
  "escapeValue": true,
  "format": [Function bound format],
  "formatSeparator": ",",
  "maxReplaces": 1000,
  "nestingOptionsSeparator": ",",
  "nestingPrefix": "$t(",
  "nestingSuffix": ")",
  "prefix": "{{",
  "skipOnVariables": true,
  "suffix": "}}",
  "unescapePrefix": "-",
}

But if other interporation option (I chose escapeValue option here) is specified, skipOnVariables is set to undefined and it doesn't seem to work.

i18n
  .use(initReactI18next) // passes i18n down to react-i18next
  .init({
    lng: 'en-US',
    interpolation: {
      escapeValue: false, // react already safes from xss => https://www.i18next.com/translation-function/interpolation#unescape
    },
  });

console.log('>>> interpolation =', i18n.options.interpolation);
>>> interpolation = Object {
  "escapeValue": false,
  "format": [Function bound format],
}

Expected behavior

Regardless of other options, the default value of skipOnVariables should be true.

i18n
  .use(initReactI18next) // passes i18n down to react-i18next
  .init({
    lng: 'en-US',
    interpolation: {
      escapeValue: false, // react already safes from xss => https://www.i18next.com/translation-function/interpolation#unescape
    },
  });

console.log('>>> interpolation =', i18n.options.interpolation);
>>> interpolation = Object {
  "escapeValue": false,
  "skipOnVariables": true,
  "format": [Function bound format],
}

Your Environment

  • runtime version: 16.13.1
  • i18next version: 21.6.3
  • os: Mac
  • any other relevant information
@adrai
Copy link
Member

@adrai adrai commented Dec 28, 2021

v21.6.4 should be better

@ishikawa
Copy link
Author

@ishikawa ishikawa commented Dec 28, 2021

@adrai Thanks for hot fix v21.6.4. I updated and checked the expected result. 馃槃

>>> interpolation Object {
  "escapeValue": false,
  "format": [Function bound format],
  "formatSeparator": ",",
  "maxReplaces": 1000,
  "nestingOptionsSeparator": ",",
  "nestingPrefix": "$t(",
  "nestingSuffix": ")",
  "prefix": "{{",
  "skipOnVariables": true,
  "suffix": "}}",
  "unescapePrefix": "-",
}

@mrlubos
Copy link

@mrlubos mrlubos commented Jan 18, 2022

Hey @adrai @ishikawa, v21.6.4 might've fixed one issue, but it introduced another problem, see #1721 please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants