Skip to content

Fix stale translations on locale change #836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix stale translations on locale change
  • Loading branch information
Demivan committed Sep 6, 2023
commit c8b7ddecb42982a8f68f6e58adf7feccbf7f976d
2 changes: 1 addition & 1 deletion src/composition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ export function useFluent(): TranslationContext {
const rootContext = inject(RootContextSymbol)
assert(rootContext != null, 'useFluent called without installing plugin')

return getContext(rootContext, instance.proxy)
return getContext(rootContext, instance.proxy, true)
}
6 changes: 5 additions & 1 deletion src/getContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function * flatMap<T, TR>(iterable: Iterable<T>, mapper: (element: T) => TR[]):
export function getContext(
rootContext: TranslationContext,
instance: VueComponent | null | undefined,
fromSetup = false,
): TranslationContext {
if (instance == null)
return rootContext
Expand Down Expand Up @@ -50,7 +51,10 @@ export function getContext(

const context = new TranslationContext(overriddenBundles, rootContext.options)

options._fluent = context
// If we are in script setup, we cannot cache the context
// because after component is unmounted, computed will not be updated
if (!fromSetup)
options._fluent = context

return context
}
7 changes: 5 additions & 2 deletions src/types/vue.d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import type Vue from 'vue-2'
import type { FluentResource } from '@fluent/bundle'
import type { FluentVue } from '../index'
import type { TranslationContext } from '../TranslationContext'

declare module 'vue-2/types/options' {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface ComponentOptions<V extends Vue> {
fluent?: Record<string, FluentResource>

/** @private */
_fluent?: FluentVue
_fluent?: TranslationContext

/** @private */
_fluentSetup?: TranslationContext
}
}

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy