-
Is the I'm developing a desktop application using Tauri. All my On the frontend, I create a plugin instance with no bundles. // src/main.ts
const pinia = createPinia();
// Use empty bundles as we will load them in the preferences store dynamically.
const fluent = createFluentVue({ bundles: [], componentTag: false });
const app = createApp(App);
app.use(pinia);
app.use(fluent);
app.mount("#app"); I load the actual resources in my Pinia state like this: // src/store.ts
export const usePreferencesStore = defineStore("preferences", () => {
const fluent = useFluent();
const language = ref<Language>("en");
watch(
language,
async (code) => {
const bundle = new FluentBundle(code);
// here is a code to load fluent resources
const localesDirPath = await path.resolveResource(`resources/locales/${code}`);
for (const entry of await readDir(localesDirPath)) {
if (entry.isFile && entry.name.endsWith(".ftl")) {
const content = await readTextFile(await path.join(localesDirPath, entry.name));
bundle.addResource(new FluentResource(content));
}
}
fluent.bundles.value = [bundle]; // override bundles
},
{ immediate: true }, // load resources immedieatly
);
return { language };
}); I will receive many warning messages about missing translations, but this is okay for me. However, I expect that those missing keys will have been overridden when resources are loaded, but this is not happening. Here is an example of a component: <!-- src/App.vue -->
<template>
<!-- These ARE reactive -->
{{ $t("file") }} {{ fluent.$t("file") }}
<Menubar :model="menuOptions" class="rounded-none border-0" />
</template>
<script setup lang="ts">
const fluent = useFluent();
const menuOptions = ref<MenuItem[]>([
{
// These are NOT reactive.
label: fluent.$t("file"),
items: [
{ label: fluent.$t("open") },
{ label: fluent.$t("create") },
{ label: fluent.$t("save") },
{ label: fluent.$t("close") },
],
},
]);
</script> What is interesting is that, in the So, how can I achieve reactivity using |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I investigated that the UI framework I use supports getter functions in the const menuOptions = ref<MenuItem[]>([
{
label: () => fluent.$t("file"),
items: [
{ label: () => fluent.$t("open") },
{ label: () => fluent.$t("create") },
{ label: () => fluent.$t("save") },
{ label: () => fluent.$t("close") },
],
},
]); If this is the correct usege of |
Beta Was this translation helpful? Give feedback.
I investigated that the UI framework I use supports getter functions in the
label
definition that makes them reactive.If this is the correct usege of
useFluent()
, then I will close the discussion.Sorry for bothering you.