diff --git a/apps/remix/app/components/embed/authoring/configure-document-advanced-settings.tsx b/apps/remix/app/components/embed/authoring/configure-document-advanced-settings.tsx index 3e720f6d9..658b10b44 100644 --- a/apps/remix/app/components/embed/authoring/configure-document-advanced-settings.tsx +++ b/apps/remix/app/components/embed/authoring/configure-document-advanced-settings.tsx @@ -1,4 +1,6 @@ -import { Trans, useLingui } from '@lingui/react/macro'; +import { t } from '@lingui/core/macro'; +import { useLingui } from '@lingui/react'; +import { Trans } from '@lingui/react/macro'; import { DocumentDistributionMethod } from '@prisma/client'; import { InfoIcon } from 'lucide-react'; import type { Control } from 'react-hook-form'; @@ -44,7 +46,7 @@ export const ConfigureDocumentAdvancedSettings = ({ control, isSubmitting, }: ConfigureDocumentAdvancedSettingsProps) => { - const { t } = useLingui(); + const { _ } = useLingui(); const form = useFormContext(); const { features } = useConfigureDocument(); @@ -93,7 +95,7 @@ export const ConfigureDocumentAdvancedSettings = ({ ({ - label: t(option.label), + label: _(option.label), value: option.value, }))} selectedValues={field.value} @@ -125,7 +127,7 @@ export const ConfigureDocumentAdvancedSettings = ({ {Object.entries(SUPPORTED_LANGUAGES).map(([code, language]) => ( - {language.full} + {_(language.full)} ))} diff --git a/apps/remix/app/components/forms/document-preferences-form.tsx b/apps/remix/app/components/forms/document-preferences-form.tsx index c3d425abb..953136223 100644 --- a/apps/remix/app/components/forms/document-preferences-form.tsx +++ b/apps/remix/app/components/forms/document-preferences-form.tsx @@ -1,6 +1,6 @@ import { zodResolver } from '@hookform/resolvers/zod'; -import { msg } from '@lingui/core/macro'; -import { useLingui } from '@lingui/react/macro'; +import { msg, t } from '@lingui/core/macro'; +import { useLingui } from '@lingui/react'; import { Trans } from '@lingui/react/macro'; import type { TeamGlobalSettings } from '@prisma/client'; import { DocumentVisibility, OrganisationType, type RecipientRole } from '@prisma/client'; @@ -109,7 +109,7 @@ export const DocumentPreferencesForm = ({ canInherit, isAiFeaturesConfigured = false, }: DocumentPreferencesFormProps) => { - const { t } = useLingui(); + const { _ } = useLingui(); const { user, organisations } = useSession(); const currentOrganisation = useCurrentOrganisation(); const optionalTeam = useOptionalCurrentTeam(); @@ -242,7 +242,7 @@ export const DocumentPreferencesForm = ({ {Object.entries(SUPPORTED_LANGUAGES).map(([code, language]) => ( - {language.full} + {_(language.full)} ))} @@ -342,7 +342,7 @@ export const DocumentPreferencesForm = ({ ({ - label: t(option.label), + label: _(option.label), value: option.value, }))} selectedValues={field.value} diff --git a/apps/remix/app/components/general/app-command-menu.tsx b/apps/remix/app/components/general/app-command-menu.tsx index 9c86d6911..47fcb884c 100644 --- a/apps/remix/app/components/general/app-command-menu.tsx +++ b/apps/remix/app/components/general/app-command-menu.tsx @@ -256,10 +256,10 @@ export function AppCommandMenu({ open, onOpenChange }: AppCommandMenuProps) { addPage('language')}> - Change language + {_(msg`Change language`)} addPage('theme')}> - Change theme + {_(msg`Change theme`)} @@ -367,15 +367,14 @@ const LanguageCommands = () => { return Object.values(SUPPORTED_LANGUAGES).map((language) => ( setLanguage(language.short)} className="-my-1 mx-2 rounded-lg first:mt-2 last:mb-2" > - - {language.full} + {_(language.full)} )); }; diff --git a/apps/remix/app/components/general/envelope-editor/envelope-editor-settings-dialog.tsx b/apps/remix/app/components/general/envelope-editor/envelope-editor-settings-dialog.tsx index 4e6373825..c0bc0be45 100644 --- a/apps/remix/app/components/general/envelope-editor/envelope-editor-settings-dialog.tsx +++ b/apps/remix/app/components/general/envelope-editor/envelope-editor-settings-dialog.tsx @@ -1,8 +1,9 @@ import { useEffect, useState } from 'react'; import { zodResolver } from '@hookform/resolvers/zod'; -import { msg } from '@lingui/core/macro'; -import { Trans, useLingui } from '@lingui/react/macro'; +import { msg, t } from '@lingui/core/macro'; +import { useLingui } from '@lingui/react'; +import { Trans } from '@lingui/react/macro'; import { DocumentDistributionMethod, DocumentVisibility, @@ -154,13 +155,13 @@ const tabs = [ id: 'email', title: msg`Email`, icon: MailIcon, - description: msg`Configure email settings for the document`, + description: msg`Configure email settings for the document.`, }, { id: 'security', title: msg`Security`, icon: ShieldIcon, - description: msg`Configure security settings for the document`, + description: msg`Configure security settings for the document.`, }, ] as const; @@ -174,7 +175,7 @@ export const EnvelopeEditorSettingsDialog = ({ trigger, ...props }: EnvelopeEditorSettingsDialogProps) => { - const { t, i18n } = useLingui(); + const { _ } = useLingui(); const { toast } = useToast(); const { envelope, updateEnvelopeAsync } = useCurrentEnvelopeEditor(); @@ -363,7 +364,7 @@ export const EnvelopeEditorSettingsDialog = ({ })} > - {t(tab.title)} + {_(tab.title)} ))} @@ -372,8 +373,8 @@ export const EnvelopeEditorSettingsDialog = ({ {/* Content. */}
- {t(selectedTab?.title ?? '')} - {t(selectedTab?.description ?? '')} + {selectedTab ? _(selectedTab.title) : ''} + {selectedTab ? _(selectedTab.description) : ''}
@@ -421,7 +422,7 @@ export const EnvelopeEditorSettingsDialog = ({ {Object.entries(SUPPORTED_LANGUAGES).map(([code, language]) => ( - {language.full} + {_(language.full)} ))} @@ -444,7 +445,7 @@ export const EnvelopeEditorSettingsDialog = ({ ({ - label: t(option.label), + label: _(option.label), value: option.value, }))} selectedValues={field.value} @@ -632,7 +633,7 @@ export const EnvelopeEditorSettingsDialog = ({ {Object.values(DOCUMENT_DISTRIBUTION_METHODS).map( ({ value, description }) => ( - {i18n._(description)} + {_(description)} ), )} diff --git a/lingui.config.ts b/lingui.config.ts index d7fae242e..668db0870 100644 --- a/lingui.config.ts +++ b/lingui.config.ts @@ -2,7 +2,7 @@ import { defineConfig } from '@lingui/cli'; import type { LinguiConfig } from '@lingui/conf'; import { formatter } from '@lingui/format-po'; -import { APP_I18N_OPTIONS } from '@documenso/lib/constants/i18n'; +import { APP_I18N_OPTIONS } from '@documenso/lib/constants/locales'; const config: LinguiConfig = { sourceLocale: APP_I18N_OPTIONS.sourceLang, diff --git a/packages/lib/constants/i18n.ts b/packages/lib/constants/i18n.ts index 49fbaee84..42c9cdd94 100644 --- a/packages/lib/constants/i18n.ts +++ b/packages/lib/constants/i18n.ts @@ -1,23 +1,13 @@ +import type { MessageDescriptor } from '@lingui/core'; +import { msg } from '@lingui/core/macro'; import { z } from 'zod'; -export const SUPPORTED_LANGUAGE_CODES = [ - 'de', - 'en', - 'fr', - 'es', - 'it', - 'nl', - 'pl', - 'pt-BR', - 'ja', - 'ko', - 'zh', -] as const; +import { SUPPORTED_LANGUAGE_CODES, type SupportedLanguageCodes } from './locales'; + +export * from './locales'; export const ZSupportedLanguageCodeSchema = z.enum(SUPPORTED_LANGUAGE_CODES).catch('en'); -export type SupportedLanguageCodes = (typeof SUPPORTED_LANGUAGE_CODES)[number]; - export type I18nLocaleData = { /** * The supported language extracted from the locale. @@ -30,61 +20,55 @@ export type I18nLocaleData = { locales: string[]; }; -export const APP_I18N_OPTIONS = { - supportedLangs: SUPPORTED_LANGUAGE_CODES, - sourceLang: 'en', - defaultLocale: 'en-US', -} as const; - type SupportedLanguage = { - full: string; short: string; + full: MessageDescriptor; }; export const SUPPORTED_LANGUAGES: Record = { de: { - full: 'German', short: 'de', + full: msg`German`, }, en: { - full: 'English', short: 'en', + full: msg`English`, }, fr: { - full: 'French', short: 'fr', + full: msg`French`, }, es: { - full: 'Spanish', short: 'es', + full: msg`Spanish`, }, it: { - full: 'Italian', short: 'it', + full: msg`Italian`, }, nl: { short: 'nl', - full: 'Dutch', + full: msg`Dutch`, }, pl: { short: 'pl', - full: 'Polish', + full: msg`Polish`, }, 'pt-BR': { short: 'pt-BR', - full: 'Portuguese (Brazil)', + full: msg`Portuguese (Brazil)`, }, ja: { short: 'ja', - full: 'Japanese', + full: msg`Japanese`, }, ko: { short: 'ko', - full: 'Korean', + full: msg`Korean`, }, zh: { short: 'zh', - full: 'Chinese', + full: msg`Chinese`, }, } satisfies Record; diff --git a/packages/lib/constants/locales.ts b/packages/lib/constants/locales.ts new file mode 100644 index 000000000..22c85a68e --- /dev/null +++ b/packages/lib/constants/locales.ts @@ -0,0 +1,21 @@ +export const SUPPORTED_LANGUAGE_CODES = [ + 'de', + 'en', + 'fr', + 'es', + 'it', + 'nl', + 'pl', + 'pt-BR', + 'ja', + 'ko', + 'zh', +] as const; + +export type SupportedLanguageCodes = (typeof SUPPORTED_LANGUAGE_CODES)[number]; + +export const APP_I18N_OPTIONS = { + supportedLangs: SUPPORTED_LANGUAGE_CODES, + sourceLang: 'en', + defaultLocale: 'en-US', +} as const; diff --git a/packages/ui/components/common/language-switcher-dialog.tsx b/packages/ui/components/common/language-switcher-dialog.tsx index 6cc67cc0c..a0b7e434f 100644 --- a/packages/ui/components/common/language-switcher-dialog.tsx +++ b/packages/ui/components/common/language-switcher-dialog.tsx @@ -45,7 +45,7 @@ export const LanguageSwitcherDialog = ({ open, setOpen }: LanguageSwitcherDialog {Object.values(SUPPORTED_LANGUAGES).map((language) => ( setLanguage(language.short)} > - {SUPPORTED_LANGUAGES[language.short].full} + {_(language.full)} ))} diff --git a/packages/ui/primitives/document-flow/add-settings.tsx b/packages/ui/primitives/document-flow/add-settings.tsx index badd8fb90..95cfa7df6 100644 --- a/packages/ui/primitives/document-flow/add-settings.tsx +++ b/packages/ui/primitives/document-flow/add-settings.tsx @@ -269,7 +269,7 @@ export const AddSettingsFormPartial = ({ {Object.entries(SUPPORTED_LANGUAGES).map(([code, language]) => ( - {language.full} + {t(language.full)} ))} diff --git a/packages/ui/primitives/template-flow/add-template-settings.tsx b/packages/ui/primitives/template-flow/add-template-settings.tsx index ce2a26f99..1a2fd341d 100644 --- a/packages/ui/primitives/template-flow/add-template-settings.tsx +++ b/packages/ui/primitives/template-flow/add-template-settings.tsx @@ -96,7 +96,7 @@ export const AddTemplateSettingsFormPartial = ({ onSubmit, onAutoSave, }: AddTemplateSettingsFormProps) => { - const { t, i18n } = useLingui(); + const { t } = useLingui(); const organisation = useCurrentOrganisation(); @@ -262,7 +262,7 @@ export const AddTemplateSettingsFormPartial = ({ {Object.entries(SUPPORTED_LANGUAGES).map(([code, language]) => ( - {language.full} + {t(language.full)} ))} @@ -391,7 +391,7 @@ export const AddTemplateSettingsFormPartial = ({ {Object.values(DOCUMENT_DISTRIBUTION_METHODS).map( ({ value, description }) => ( - {i18n._(description)} + {t(description)} ), )}