merge: Refresh locales after any change, not just a version update (resolves #732) (!692)

View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/692

Closes #732

Approved-by: dakkar <dakkar@thenautilus.net>
Approved-by: Marie <github@yuugi.dev>
This commit is contained in:
Hazelnoot 2024-10-15 21:50:56 +00:00
commit 68b90df00b
8 changed files with 41 additions and 31 deletions

1
locales/version.d.ts vendored Normal file
View file

@ -0,0 +1 @@
export const localesVersion: string;

14
locales/version.js Normal file
View file

@ -0,0 +1,14 @@
import { createHash } from 'crypto';
import locales from './index.js';
// MD5 is acceptable because we don't need cryptographic security.
const hash = createHash('md5');
// Derive the version hash from locale content exclusively.
// This avoids the problem of "stuck" translations after modifying locale files.
const localesText = JSON.stringify(locales);
hash.update(localesText, 'utf8');
// We can't use regular base64 since this becomes part of a filename.
// Base64URL avoids special characters that would cause an issue.
export const localesVersion = hash.digest().toString('base64url');