vue-i18n
vue-i18n copied to clipboard
If $t params are undefined
trafficstars
Reporting a bug?
When using a variable as a param to the $t() function it works good until the variable is undefined. Then there is an error:
Uncaught (in promise) SyntaxError: Invalid argument
Expected behavior
In previous versions this was handled by the function.
Reproduction
I made a JSFiddle here https://jsfiddle.net/rxn13fa7/4/ Its the "undefined" on row 28 that creates the error. Remove it and it works fine.
System Info
See JSFiddle
Screenshot
No response
Additional context
The current solution I do is making a wrapping function like this
translate (key) { return key ? this.$t(key) : '' }
Validations
- [X] Read the Contributing Guidelines
- [X] Read the Documentation
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion
- [X] The provided reproduction is a minimal reproducible example of the bug.