mirror of
https://github.com/pterodactyl/panel.git
synced 2026-12-02 12:25:44 -05:00
Fix extension translations staying cached after an extension update
Fixes #7245
This commit is contained in:
@@ -371,6 +371,8 @@ export interface SiteExtensionEntry {
|
||||
entry: string;
|
||||
/** The Tailwind prefix declared as `ui.prefix`: the extension writes `<prefix>:flex`. */
|
||||
prefix?: string | null;
|
||||
/** Changes with the extension's translation files, and is sent when loading them. */
|
||||
translations?: string | null;
|
||||
config?: ExtensionConfig;
|
||||
screens?: ExtensionScreenDefinition[];
|
||||
components?: ComponentName[];
|
||||
|
||||
@@ -65,3 +65,21 @@ it('follows language changes of the cached current user', async () => {
|
||||
expect(instance.language).toBe('nl');
|
||||
client.clear();
|
||||
});
|
||||
|
||||
it('adds the revision of an extension to the URL of its translations only', async () => {
|
||||
(window as BootstrapWindow).SiteConfiguration = {
|
||||
extensions: [
|
||||
{ id: 'notes', entry: '/notes.js', translations: 'a1b2' },
|
||||
{ id: 'plain', entry: '/plain.js', translations: null },
|
||||
],
|
||||
};
|
||||
const { localeLoadPath } = await import('@/i18n');
|
||||
const core = '/locales/locale.json?locale={{lng}}&namespace={{ns}}';
|
||||
|
||||
expect(localeLoadPath(['ext-notes::messages'])).toBe(`${core}&revision=a1b2`);
|
||||
expect(localeLoadPath(['strings'])).toBe(core);
|
||||
expect(localeLoadPath(['ext-plain::messages'])).toBe(core);
|
||||
expect(localeLoadPath(['ext-missing::messages'])).toBe(core);
|
||||
// One request for several namespaces has no single revision to carry.
|
||||
expect(localeLoadPath(['ext-notes::messages', 'strings'])).toBe(core);
|
||||
});
|
||||
|
||||
@@ -6,7 +6,7 @@ import I18NextHttpBackend from 'i18next-http-backend';
|
||||
import I18NextMultiloadBackendAdapter from 'i18next-multiload-backend-adapter';
|
||||
import { currentUserQueryKey } from '@/api/account/queries';
|
||||
import type { UserData } from '@/api/account/types';
|
||||
import { getBootstrapSiteSettings, getBootstrapUser } from '@/bootstrap';
|
||||
import { getBootstrapExtensions, getBootstrapSiteSettings, getBootstrapUser } from '@/bootstrap';
|
||||
|
||||
interface MultiloadHttpBackendOptions extends HttpBackendOptions {
|
||||
allowMultiLoading: boolean;
|
||||
@@ -15,6 +15,21 @@ interface MultiloadHttpBackendOptions extends HttpBackendOptions {
|
||||
// Busts the locale cache on every reload under HMR, otherwise once per build.
|
||||
const hash = import.meta.hot ? Date.now().toString(16) : import.meta.env.WEBPACK_BUILD_HASH;
|
||||
|
||||
const localePath = '/locales/locale.json?locale={{lng}}&namespace={{ns}}';
|
||||
|
||||
/**
|
||||
* Extension translations change when the extension is upgraded, not with the panel build,
|
||||
* so their URL also carries the revision the panel reported for that extension.
|
||||
*/
|
||||
export function localeLoadPath(namespaces: string[]): string {
|
||||
const extensionId = namespaces.length === 1 ? /^ext-(.+)::/.exec(namespaces[0]!)?.[1] : undefined;
|
||||
const revision = extensionId
|
||||
? getBootstrapExtensions().find((extension) => extension.id === extensionId)?.translations
|
||||
: undefined;
|
||||
|
||||
return revision ? `${localePath}&revision=${revision}` : localePath;
|
||||
}
|
||||
|
||||
export const initialLanguage = (): string => getBootstrapUser()?.language || getBootstrapSiteSettings()?.locale || 'en';
|
||||
|
||||
export function followCurrentUserLanguage(queryClient: QueryClient, instance: I18n = i18n): () => void {
|
||||
@@ -41,7 +56,7 @@ i18n.use(I18NextMultiloadBackendAdapter)
|
||||
backend: {
|
||||
backend: I18NextHttpBackend,
|
||||
backendOption: {
|
||||
loadPath: '/locales/locale.json?locale={{lng}}&namespace={{ns}}',
|
||||
loadPath: (_languages, namespaces) => localeLoadPath(namespaces),
|
||||
queryStringParams: { hash },
|
||||
allowMultiLoading: true,
|
||||
} satisfies MultiloadHttpBackendOptions,
|
||||
|
||||
Reference in New Issue
Block a user