-
-
Notifications
You must be signed in to change notification settings - Fork 380
Open
Labels
🔨 p3-minor-bugPriority 3: a bug in an edge case that only affects very specific usagePriority 3: a bug in an edge case that only affects very specific usage
Description
Clear and concise description of the problem
In my current project, I use component specific message files in local i18n scopes which works amazing!:
// component.vue
<script setup lang="ts">
// Imports
import { useI18n } from "vue-i18n";
import i18nMessages from "./component.i18n";
// I18n
const { t } = useI18n({ messages: i18nMessages });
const projectStatus = getProjectStatus(project);
</script>
{{ t("component.message") }}
{{ projectStatus }}But if I want to do the same for a composable:
// composable.ts
// Imports
import { useI18n } from "vue-i18n";
import i18nMessages from "./component.i18n";
export function getProjectStatus(project) {
const { t } = useI18n({ messages: i18nMessages });
if(project.problem)
return t("status.problem");
else
return t("status.noProblem");
}It doesn't work, because both calls of useI18n will execute on the same component. And the result will be:
Important Component Message // From the component.i18n messages
status.problem
Suggested solution
- I missed something and it's already possible => I'll improve the docu
- Allow stacking of useI18n by calling useI18n to create new scope on top of the "current one"
Alternative
Merge messages into the existing i18n instance:
const { t, locale, mergeLocaleMessage } = useI18n();
mergeLocaleMessage(locale.value, i18nMessages[locale.value]);
But then the composable directly affects the messages of the component, which can lead to undesired side effects, when both use the same key.
Additional context
No response
Validations
- Read the Contributing Guidelines
- Read the Documentation
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
core01
Metadata
Metadata
Assignees
Labels
🔨 p3-minor-bugPriority 3: a bug in an edge case that only affects very specific usagePriority 3: a bug in an edge case that only affects very specific usage