vue-i18n
vue-i18n copied to clipboard
Usage of `n()` and `$n()` with `undefined` should not throw errors
trafficstars
Clear and concise description of the problem
Sometimes values are undefined within an application, unfortunately this will throw a 500 error (at least in Nuxt) so the whole page is unavailable just because one variable is undefined:
<script setup lang="ts">
const props = defineProps<{price: number}>();
</script>
<template>
{{ $n(props.price, 'currency') }}
</template>
Another example are inputs:
<script setup lang="ts">
const price = ref(10);
</script>
<template>
<input v-model="price" type="number">
{{ $n(price, 'currency') }}
</template>
These can get undefined while the user is editing the input value which will also throw errors:
Incaught (in promise) SyntaxError: Invalid arguments (at message-compiler.mjs:77:19)
Suggested solution
It would be great if the function n() and $n() would instead just return an empty string '' without the whole page crashing or throwing any errors.
Alternative
No response
Additional context
No response
Validations
- [X] Read the Contributing Guidelines
- [X] Read the Documentation
- [X] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.