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

Having a boolean as a value gives a "TypeError: res.match is not a function" (from v20 to v21) #1702

Closed
afv opened this issue Dec 7, 2021 · 2 comments

Comments

@afv
Copy link

@afv afv commented Dec 7, 2021

馃悰 Bug Report

From v20 (20.6.1) to v21 (21.0.0) having a boolean as a value gives a TypeError: res.match is not a function at Translator.extendTranslation (webpack-internal:///./node_modules/i18next/dist/esm/i18next.js:835:24), as res is a boolean and not a String.

Part of extendTranslation:

if (skipOnVariables) {
  var nb = res.match(this.interpolator.nestingRegexp);
  nestBef = nb && nb.length;
}

To Reproduce

"paragraphs": {
  "paragraphOne": {
    "text": "some example text to be highlighted",
    "highlight": true
  },
  "paragraphTwo": {
    "text": "text not highlighted",
    "highlight": false
  },
}

I'm using returnObjects: true to get the paragraphs object (from the example) and iterate through the results (paragraphOne and paragraphTwo) in the template (Vue). I then use the highlight boolean to know if a CSS class should be applied to that text or not (is there a better way?).

Expected behavior

No error. res typeof should be checked and if it is not a String it should not call match.

To "fix" it I just replaced true by "true" and will check for that string instead of expecting a boolean, but I'm opening this issue anyway as it might be a bug.

Your Environment

  • i18next version: 21.5.4
@adrai
Copy link
Member

@adrai adrai commented Dec 7, 2021

should be fixed with v21.5.5

@afv
Copy link
Author

@afv afv commented Dec 7, 2021

Confirmed. Thanks for the quick fix! 馃槂

@afv afv closed this as completed Dec 7, 2021
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

2 participants