intlify/vue-i18n

A "localize" composable and directive would be useful

Opened this issue · 0 comments

Clear and concise description of the problem

A common pattern I have when using this fantastic package is:

		const key = 'key.path';
		const localized = te(key) ? t(key) : 'Fallback Translation';

This is cumbersome to do over and over again.

Suggested solution

It would be nice if a composable could be provided which did that by allowed me to do:

const localized = localize( 'key.path', 'Fallback Translation' );

localize would look like:

function localize( key, fallback ) {
    return te(key) ? t(key) : fallback;
}

Then, having a related v-localize directive would be useful....

<div v-localize="{ key: 'key.path', fallback: 'Fallback Translation' }" />

Alternative

No response

Additional context

No response

Validations