chore: improve i18n workflow to prevent stale compiled translations (#18850)

https://sonarly.com/issue/22697?type=bug

The Docker image build did not run `lingui compile` before building the server and frontend, causing missing translation entries at runtime that flood logs with "Uncompiled message detected" warnings.
This commit is contained in:
Sonarly Claude Code
2026-04-08 03:08:31 +00:00
parent af3423dc6f
commit fbc27623ef
@@ -1,4 +1,4 @@
import { Injectable, type OnModuleInit } from '@nestjs/common';
import { Injectable, Logger, type OnModuleInit } from '@nestjs/common';
import {
type I18n,
@@ -42,6 +42,9 @@ import { messages as zhHantMessages } from 'src/engine/core-modules/i18n/locales
@Injectable()
export class I18nService implements OnModuleInit {
private readonly logger = new Logger(I18nService.name);
private readonly loggedMissingIds = new Set<string>();
private i18nInstancesMap: Record<keyof typeof APP_LOCALES, I18n> =
{} as Record<keyof typeof APP_LOCALES, I18n>;
@@ -83,7 +86,19 @@ export class I18nService implements OnModuleInit {
(
Object.entries(messagesByLocale) as [keyof typeof APP_LOCALES, Messages][]
).forEach(([locale, messages]) => {
const localeI18n = setupI18n();
const localeI18n = setupI18n({
missing: (_locale, id) => {
if (!this.loggedMissingIds.has(id)) {
this.loggedMissingIds.add(id);
this.logger.warn(
`Missing translation for message "${id}" in locale "${_locale}". ` +
'Compiled catalogs may be stale — run lingui compile.',
);
}
return id;
},
});
localeI18n.load(locale, messages);
localeI18n.activate(locale);