Public Access
The translation files get a content version in their URL, so a browser that cached an old file loads the new one. On touch screens the scroll lock of menus and selects no longer adds a right margin: Android Chrome reported one and the whole page became narrower.
23 lines
972 B
JavaScript
23 lines
972 B
JavaScript
import {createHash} from 'node:crypto';
|
|
import {readdirSync, readFileSync} from 'node:fs';
|
|
import path from 'node:path';
|
|
import {describe, expect, it, vi} from 'vitest';
|
|
|
|
vi.mock('i18next-http-backend', () => ({
|
|
default: {type: 'backend', init() {}, read(language, namespace, callback) { callback(null, {}); }},
|
|
}));
|
|
|
|
describe('translation files', () => {
|
|
it('are loaded under a URL that changes with their content, so no browser keeps an old copy', async () => {
|
|
const {default: i18n} = await import('./i18n.js');
|
|
const loadPath = i18n.options.backend.loadPath;
|
|
|
|
const dir = path.resolve(import.meta.dirname, '../public/i18n');
|
|
const hash = createHash('sha256');
|
|
for (const file of readdirSync(dir).filter((name) => name.endsWith('.json')).sort()) {
|
|
hash.update(readFileSync(path.join(dir, file)));
|
|
}
|
|
expect(loadPath).toBe(`/i18n/{{lng}}.json?v=${hash.digest('hex').slice(0, 12)}`);
|
|
});
|
|
});
|