fix: avoid Lingui uncompiled-message warnings in metadata ti
Authored via Sonarly Slack mention (run 42732).
This commit is contained in:
+16
@@ -53,6 +53,22 @@ describe('resolvePageLayoutTabTitle', () => {
|
||||
expect(result).toBe('My Custom Tab');
|
||||
});
|
||||
|
||||
it('should return original title without translating when message is not compiled', () => {
|
||||
mockGenerateMessageId.mockReturnValue('missing-translation');
|
||||
mockI18n.messages = {};
|
||||
|
||||
const result = resolvePageLayoutTabTitle({
|
||||
title: 'My Custom Tab',
|
||||
applicationId: STANDARD_APPLICATION_ID,
|
||||
twentyStandardApplicationId: STANDARD_APPLICATION_ID,
|
||||
i18nInstance: mockI18n,
|
||||
});
|
||||
|
||||
expect(mockGenerateMessageId).toHaveBeenCalledWith('My Custom Tab');
|
||||
expect(mockI18n._).not.toHaveBeenCalled();
|
||||
expect(result).toBe('My Custom Tab');
|
||||
});
|
||||
|
||||
it('should return original title for empty string', () => {
|
||||
mockGenerateMessageId.mockReturnValue('empty-hash');
|
||||
mockI18n._.mockReturnValue('empty-hash');
|
||||
|
||||
+9
@@ -27,6 +27,15 @@ export const resolvePageLayoutTabTitle = ({
|
||||
}
|
||||
|
||||
const messageId = generateMessageId(title);
|
||||
|
||||
const isMessageCompiled =
|
||||
!isDefined(i18nInstance.messages) ||
|
||||
isDefined(i18nInstance.messages[messageId]);
|
||||
|
||||
if (!isMessageCompiled) {
|
||||
return title;
|
||||
}
|
||||
|
||||
const translatedMessage = i18nInstance._(messageId);
|
||||
|
||||
if (translatedMessage === messageId) {
|
||||
|
||||
+16
@@ -53,6 +53,22 @@ describe('resolvePageLayoutWidgetTitle', () => {
|
||||
expect(result).toBe('My Custom Widget');
|
||||
});
|
||||
|
||||
it('should return original title without translating when message is not compiled', () => {
|
||||
mockGenerateMessageId.mockReturnValue('missing-translation');
|
||||
mockI18n.messages = {};
|
||||
|
||||
const result = resolvePageLayoutWidgetTitle({
|
||||
title: 'My Custom Widget',
|
||||
applicationId: STANDARD_APPLICATION_ID,
|
||||
twentyStandardApplicationId: STANDARD_APPLICATION_ID,
|
||||
i18nInstance: mockI18n,
|
||||
});
|
||||
|
||||
expect(mockGenerateMessageId).toHaveBeenCalledWith('My Custom Widget');
|
||||
expect(mockI18n._).not.toHaveBeenCalled();
|
||||
expect(result).toBe('My Custom Widget');
|
||||
});
|
||||
|
||||
it('should return original title for empty string', () => {
|
||||
mockGenerateMessageId.mockReturnValue('empty-hash');
|
||||
mockI18n._.mockReturnValue('empty-hash');
|
||||
|
||||
+9
@@ -27,6 +27,15 @@ export const resolvePageLayoutWidgetTitle = ({
|
||||
}
|
||||
|
||||
const messageId = generateMessageId(title);
|
||||
|
||||
const isMessageCompiled =
|
||||
!isDefined(i18nInstance.messages) ||
|
||||
isDefined(i18nInstance.messages[messageId]);
|
||||
|
||||
if (!isMessageCompiled) {
|
||||
return title;
|
||||
}
|
||||
|
||||
const translatedMessage = i18nInstance._(messageId);
|
||||
|
||||
if (translatedMessage === messageId) {
|
||||
|
||||
@@ -68,6 +68,18 @@ if (process.env.EXCEPTION_HANDLER_DRIVER === ExceptionHandlerDriver.SENTRY) {
|
||||
|
||||
return span;
|
||||
},
|
||||
beforeBreadcrumb: (breadcrumb) => {
|
||||
const isLinguiUncompiledWarning =
|
||||
breadcrumb.category === 'console' &&
|
||||
breadcrumb.level === 'warning' &&
|
||||
breadcrumb.message?.startsWith('Uncompiled message detected! Message:');
|
||||
|
||||
if (isLinguiUncompiledWarning) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return breadcrumb;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user