How can I simplify this code?
<script setup>
import { useI18n } from 'vue-i18n'
const { t, te } = useI18n()
const message = te('key1') ? t('key1') : ( te('key2') ? t('key2') : t('key3') )
</script>
This code basically intends to provide an alternative translation key if translation is missing. It is like a same-language fallback.
Is there way to do something similar to this?
t('key1') || t('key2') || t('key3')
Or similar to this?
t('key1', 'key2', 'key3')
Rails Ii18n uses a similar functionality: The key for the error message in this case is :blank. Active Record will look up this key in the namespaces:
activerecord.errors.models.[model_name].attributes.[attribute_name]
activerecord.errors.models.[model_name]
activerecord.errors.messages
errors.attributes.[attribute_name]
errors.messages
Rails I18n example