The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Close the silent gaps around adding a locale, and stop an email shipping its message ids (#25851)
Félix Malfaitc1b5b7a69f83
diff --git a/packages/twenty-emails/src/emails/server-admin-access-changed.email.tsx b/packages/twenty-emails/src/emails/server-admin-access-changed.email.tsxindex 7334b1aac73..00c94cee38b 100644--- a/packages/twenty-emails/src/emails/server-admin-access-changed.email.tsx+++ b/packages/twenty-emails/src/emails/server-admin-access-changed.email.tsx@@ -35,29 +35,23 @@ export const ServerAdminAccessChangedEmail = ({<Title value={i18n._('Server administrator access changed')} /><MainText><Trans- id="serverAdminAccessChanged.summary"- message="{actorName} updated server administrator access for {targetName} ({targetEmail})."+ id="{actorName} updated server administrator access for {targetName} ({targetEmail})."values={{ actorName, targetName, targetEmail }}/><br /><br /><Trans- id="serverAdminAccessChanged.fullAdmin"- message="Full admin panel access: {fullAdminStatus}"+ id="Full admin panel access: {fullAdminStatus}"values={{ fullAdminStatus }}/><br /><Trans- id="serverAdminAccessChanged.impersonation"- message="Impersonation: {impersonateStatus}"+ id="Impersonation: {impersonateStatus}"values={{ impersonateStatus }}/><br /><br />- <Trans- id="serverAdminAccessChanged.warning"- message="If you did not expect this change, review your server administrators immediately."- />+ <Trans id="If you did not expect this change, review your server administrators immediately." /><br /></MainText><br />diff --git a/packages/twenty-front/src/localization/hooks/useLocaleOptions.ts b/packages/twenty-front/src/localization/hooks/useLocaleOptions.tsindex bb183650061..d7ba21f3d42 100644--- a/packages/twenty-front/src/localization/hooks/useLocaleOptions.ts+++ b/packages/twenty-front/src/localization/hooks/useLocaleOptions.ts@@ -36,53 +36,56 @@ const LOCALE_SEARCH_KEYWORDS: Record<string, string> = Object.fromEntries(export const useLocaleOptions = (): LocaleOption[] => {const { t } = useLingui();- const unsortedLocaleOptions: Array<Omit<LocaleOption, 'searchKeywords'>> = [- { label: t`Afrikaans`, value: APP_LOCALES['af-ZA'] },- { label: t`Arabic`, value: APP_LOCALES['ar-SA'] },- { label: t`Armenian`, value: APP_LOCALES['hy-AM'] },- { label: t`Catalan`, value: APP_LOCALES['ca-ES'] },- { label: t`Chinese — Simplified`, value: APP_LOCALES['zh-CN'] },- { label: t`Chinese — Traditional`, value: APP_LOCALES['zh-TW'] },- { label: t`Czech`, value: APP_LOCALES['cs-CZ'] },- { label: t`Danish`, value: APP_LOCALES['da-DK'] },- { label: t`Dutch`, value: APP_LOCALES['nl-NL'] },- { label: t`English`, value: APP_LOCALES.en },- { label: t`Finnish`, value: APP_LOCALES['fi-FI'] },- { label: t`French`, value: APP_LOCALES['fr-FR'] },- { label: t`German`, value: APP_LOCALES['de-DE'] },- { label: t`Greek`, value: APP_LOCALES['el-GR'] },- { label: t`Hebrew`, value: APP_LOCALES['he-IL'] },- { label: t`Hungarian`, value: APP_LOCALES['hu-HU'] },- { label: t`Italian`, value: APP_LOCALES['it-IT'] },- { label: t`Japanese`, value: APP_LOCALES['ja-JP'] },- { label: t`Korean`, value: APP_LOCALES['ko-KR'] },- { label: t`Norwegian`, value: APP_LOCALES['no-NO'] },- { label: t`Polish`, value: APP_LOCALES['pl-PL'] },- { label: t`Portuguese — Portugal`, value: APP_LOCALES['pt-PT'] },- { label: t`Portuguese — Brazil`, value: APP_LOCALES['pt-BR'] },- { label: t`Romanian`, value: APP_LOCALES['ro-RO'] },- { label: t`Russian`, value: APP_LOCALES['ru-RU'] },- { label: t`Serbian (Cyrillic)`, value: APP_LOCALES['sr-Cyrl'] },- { label: t`Serbian (Latin)`, value: APP_LOCALES['sr-Latn'] },- { label: t`Spanish`, value: APP_LOCALES['es-ES'] },- { label: t`Swedish`, value: APP_LOCALES['sv-SE'] },- { label: t`Turkish`, value: APP_LOCALES['tr-TR'] },- { label: t`Ukrainian`, value: APP_LOCALES['uk-UA'] },- { label: t`Uzbek`, value: APP_LOCALES['uz-UZ'] },- { label: t`Vietnamese`, value: APP_LOCALES['vi-VN'] },- ];+ // Keyed by locale rather than listed, so a locale added to APP_LOCALES+ // without a label here fails the typecheck. Listed, it would ship its+ // translations and simply never appear in the picker, with no error.+ const labelByLocale: Record<keyof typeof APP_LOCALES, string> = {+ 'af-ZA': t`Afrikaans`,+ 'ar-SA': t`Arabic`,+ 'hy-AM': t`Armenian`,+ 'ca-ES': t`Catalan`,+ 'zh-CN': t`Chinese — Simplified`,+ 'zh-TW': t`Chinese — Traditional`,+ 'cs-CZ': t`Czech`,+ 'da-DK': t`Danish`,+ 'nl-NL': t`Dutch`,+ en: t`English`,+ 'fi-FI': t`Finnish`,+ 'fr-FR': t`French`,+ 'de-DE': t`German`,+ 'el-GR': t`Greek`,+ 'he-IL': t`Hebrew`,+ 'hu-HU': t`Hungarian`,+ 'it-IT': t`Italian`,+ 'ja-JP': t`Japanese`,+ 'ko-KR': t`Korean`,+ 'no-NO': t`Norwegian`,+ 'pl-PL': t`Polish`,+ 'pt-PT': t`Portuguese — Portugal`,+ 'pt-BR': t`Portuguese — Brazil`,+ 'ro-RO': t`Romanian`,+ 'ru-RU': t`Russian`,+ 'sr-Cyrl': t`Serbian (Cyrillic)`,+ 'sr-Latn': t`Serbian (Latin)`,+ 'es-ES': t`Spanish`,+ 'sv-SE': t`Swedish`,+ 'tr-TR': t`Turkish`,+ 'uk-UA': t`Ukrainian`,+ 'uz-UZ': t`Uzbek`,+ 'vi-VN': t`Vietnamese`,+ 'pseudo-en': t`Pseudo-English`,+ };- if (process.env.NODE_ENV === 'development') {- unsortedLocaleOptions.push({- label: t`Pseudo-English`,- value: APP_LOCALES['pseudo-en'],- });- }-- return [...unsortedLocaleOptions]- .sort((a, b) => a.label.localeCompare(b.label))- .map((option) => ({- ...option,- searchKeywords: LOCALE_SEARCH_KEYWORDS[option.value] ?? '',- }));+ return Object.entries(labelByLocale)+ .filter(+ ([locale]) =>+ locale !== APP_LOCALES['pseudo-en'] ||+ process.env.NODE_ENV === 'development',+ )+ .map(([locale, label]) => ({+ label,+ value: locale as LocaleOption['value'],+ searchKeywords: LOCALE_SEARCH_KEYWORDS[locale] ?? '',+ }))+ .sort((a, b) => a.label.localeCompare(b.label));};diff --git a/packages/twenty-front/src/modules/ui/field/display/utils/__tests__/getDateFnsLocale.test.ts b/packages/twenty-front/src/modules/ui/field/display/utils/__tests__/getDateFnsLocale.test.tsindex a2a9dbf285f..0eeeccc4e7b 100644--- a/packages/twenty-front/src/modules/ui/field/display/utils/__tests__/getDateFnsLocale.test.ts+++ b/packages/twenty-front/src/modules/ui/field/display/utils/__tests__/getDateFnsLocale.test.ts@@ -16,6 +16,18 @@ describe('getDateFnsLocale', () => {expect(locale?.code).toBe('fr');});+ // The switch has an en-US default, so a case pointing at a module path that+ // does not exist fails the same silent way a missing case would.+ it.each([+ ['hy-AM', 'hy'],+ ['sr-Latn', 'sr-Latn'],+ ['uz-UZ', 'uz'],+ ])('should load %s from date-fns', async (appLocale, dateFnsCode) => {+ const locale = await getDateFnsLocale(appLocale);++ expect(locale?.code).toBe(dateFnsCode);+ });+it('should fall back to en-US for an unknown locale', async () => {const locale = await getDateFnsLocale('zz-ZZ');diff --git a/packages/twenty-front/src/modules/ui/field/display/utils/getDateFnsLocale.ts b/packages/twenty-front/src/modules/ui/field/display/utils/getDateFnsLocale.tsindex 3a437e6a510..34414d1893a 100644--- a/packages/twenty-front/src/modules/ui/field/display/utils/getDateFnsLocale.ts+++ b/packages/twenty-front/src/modules/ui/field/display/utils/getDateFnsLocale.ts@@ -32,6 +32,8 @@ export const getDateFnsLocaleImport = (locale: AppLocale) => {return import('date-fns/locale/he');case 'hu-HU':return import('date-fns/locale/hu');+ case 'hy-AM':+ return import('date-fns/locale/hy');case 'it-IT':return import('date-fns/locale/it');case 'ja-JP':@@ -53,12 +55,16 @@ export const getDateFnsLocaleImport = (locale: AppLocale) => {return import('date-fns/locale/ru');case 'sr-Cyrl':return import('date-fns/locale/sr');+ case 'sr-Latn':+ return import('date-fns/locale/sr-Latn');case 'sv-SE':return import('date-fns/locale/sv');case 'tr-TR':return import('date-fns/locale/tr');case 'uk-UA':return import('date-fns/locale/uk');+ case 'uz-UZ':+ return import('date-fns/locale/uz');case 'vi-VN':return import('date-fns/locale/vi');case 'zh-CN':@@ -66,6 +72,12 @@ export const getDateFnsLocaleImport = (locale: AppLocale) => {case 'zh-TW':return import('date-fns/locale/zh-TW');default: {+ // getDateFnsLocale passes an arbitrary string, so unknown input still+ // lands here at runtime. A locale in APP_LOCALES must not: without this+ // the switch would silently format its dates in US English, and nothing+ // - not a type, not a test, not a lint rule - would say so.+ locale satisfies never;+return import('date-fns/locale/en-US');}}