fix: reload template workflows when locale changes (#8963)

## Summary
- Templates were fetched once with the initial locale and cached behind
an `isLoaded` guard. Changing language updated i18n UI strings but never
re-fetched locale-specific template data (names, descriptions) from the
server.
- Extracts core template fetching into `fetchCoreTemplates()` and adds a
`watch` on `i18n.global.locale` to re-fetch when the language changes.

## Test plan
- [ ] Open the templates panel
- [ ] Change language in settings (e.g. English -> French)
- [ ] Verify template names and descriptions update without a page
refresh
- [ ] Verify initial load still works correctly

┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-8963-fix-reload-template-workflows-when-locale-changes-30b6d73d36508178a2f8c2c8947b5955)
by [Unito](https://www.unito.io)
This commit is contained in:
Johnpaul Chiwetelu
2026-02-19 00:59:37 +01:00
committed by GitHub
parent 44dc208339
commit aff0ebad50

View File

@@ -1,5 +1,5 @@
import { defineStore } from 'pinia'
import { computed, ref, shallowRef } from 'vue'
import { computed, ref, shallowRef, watch } from 'vue'
import { i18n, st } from '@/i18n'
import { isCloud } from '@/platform/distribution/types'
@@ -472,31 +472,32 @@ export const useWorkflowTemplatesStore = defineStore(
return items
})
async function fetchCoreTemplates() {
const locale = i18n.global.locale.value
const [coreResult, englishResult, logoIndexResult] = await Promise.all([
api.getCoreWorkflowTemplates(locale),
isCloud && locale !== 'en'
? api.getCoreWorkflowTemplates('en')
: Promise.resolve([]),
fetchLogoIndex()
])
coreTemplates.value = coreResult
englishTemplates.value = englishResult
logoIndex.value = logoIndexResult
const coreNames = coreTemplates.value.flatMap((category) =>
category.templates.map((template) => template.name)
)
const customNames = Object.values(customTemplates.value).flat()
knownTemplateNames.value = new Set([...coreNames, ...customNames])
}
async function loadWorkflowTemplates() {
try {
if (!isLoaded.value) {
customTemplates.value = await api.getWorkflowTemplates()
const locale = i18n.global.locale.value
const [coreResult, englishResult, logoIndexResult] =
await Promise.all([
api.getCoreWorkflowTemplates(locale),
isCloud && locale !== 'en'
? api.getCoreWorkflowTemplates('en')
: Promise.resolve([]),
fetchLogoIndex()
])
coreTemplates.value = coreResult
englishTemplates.value = englishResult
logoIndex.value = logoIndexResult
const coreNames = coreTemplates.value.flatMap((category) =>
category.templates.map((template) => template.name)
)
const customNames = Object.values(customTemplates.value).flat()
knownTemplateNames.value = new Set([...coreNames, ...customNames])
await fetchCoreTemplates()
isLoaded.value = true
}
} catch (error) {
@@ -504,6 +505,18 @@ export const useWorkflowTemplatesStore = defineStore(
}
}
watch(
() => i18n.global.locale.value,
async () => {
if (!isLoaded.value) return
try {
await fetchCoreTemplates()
} catch (error) {
console.error('Error reloading templates for new locale:', error)
}
}
)
async function fetchLogoIndex(): Promise<LogoIndex> {
try {
const response = await fetch(api.fileURL('/templates/index_logo.json'))