Skip to content

The Open Source DocuSign Alternative.

fix(i18n): mark supported languages for translation (#2377)

Konrad92d82c042381
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<TConfigureEmbedFormSchema>();
const { features } = useConfigureDocument();
@@ -93,7 +95,7 @@ export const ConfigureDocumentAdvancedSettings = ({
<FormControl>
<MultiSelectCombobox
options={Object.values(DOCUMENT_SIGNATURE_TYPES).map((option) => ({
- label: t(option.label),
+ label: _(option.label),
value: option.value,
}))}
selectedValues={field.value}
@@ -125,7 +127,7 @@ export const ConfigureDocumentAdvancedSettings = ({
<SelectContent>
{Object.entries(SUPPORTED_LANGUAGES).map(([code, language]) => (
<SelectItem key={code} value={code}>
- {language.full}
+ {_(language.full)}
</SelectItem>
))}
</SelectContent>
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 = ({
<SelectContent>
{Object.entries(SUPPORTED_LANGUAGES).map(([code, language]) => (
<SelectItem key={code} value={code}>
- {language.full}
+ {_(language.full)}
</SelectItem>
))}
@@ -342,7 +342,7 @@ export const DocumentPreferencesForm = ({
<FormControl>
<MultiSelectCombobox
options={Object.values(DOCUMENT_SIGNATURE_TYPES).map((option) => ({
- 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) {
<CommandGroup className="mx-2 p-0 pb-2" heading={_(msg`Preferences`)}>
<CommandItem className="-mx-2 -my-1 rounded-lg" onSelect={() => addPage('language')}>
- Change language
+ {_(msg`Change language`)}
</CommandItem>
<CommandItem className="-mx-2 -my-1 rounded-lg" onSelect={() => addPage('theme')}>
- Change theme
+ {_(msg`Change theme`)}
</CommandItem>
</CommandGroup>
@@ -367,15 +367,14 @@ const LanguageCommands = () => {
return Object.values(SUPPORTED_LANGUAGES).map((language) => (
<CommandItem
disabled={isLoading}
- key={language.full}
+ key={language.short}
onSelect={async () => setLanguage(language.short)}
className="-my-1 mx-2 rounded-lg first:mt-2 last:mb-2"
>
<CheckIcon
className={cn('mr-2 h-4 w-4', i18n.locale === language.short ? 'opacity-100' : 'opacity-0')}
/>
-
- {language.full}
+ {_(language.full)}
</CommandItem>
));
};
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 = ({
})}
>
<tab.icon className="mr-2 h-5 w-5" />
- {t(tab.title)}
+ {_(tab.title)}
</Button>
))}
</nav>
@@ -372,8 +373,8 @@ export const EnvelopeEditorSettingsDialog = ({
{/* Content. */}
<div className="flex w-full flex-col">
<CardHeader className="border-b pb-4">
- <CardTitle>{t(selectedTab?.title ?? '')}</CardTitle>
- <CardDescription>{t(selectedTab?.description ?? '')}</CardDescription>
+ <CardTitle>{selectedTab ? _(selectedTab.title) : ''}</CardTitle>
+ <CardDescription>{selectedTab ? _(selectedTab.description) : ''}</CardDescription>
</CardHeader>
<Form {...form}>
@@ -421,7 +422,7 @@ export const EnvelopeEditorSettingsDialog = ({
<SelectContent>
{Object.entries(SUPPORTED_LANGUAGES).map(([code, language]) => (
<SelectItem key={code} value={code}>
- {language.full}
+ {_(language.full)}
</SelectItem>
))}
</SelectContent>
@@ -444,7 +445,7 @@ export const EnvelopeEditorSettingsDialog = ({
<FormControl>
<MultiSelectCombobox
options={Object.values(DOCUMENT_SIGNATURE_TYPES).map((option) => ({
- 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 }) => (
<SelectItem key={value} value={value}>
- {i18n._(description)}
+ {_(description)}
</SelectItem>
),
)}
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,22 +1,12 @@
+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 const ZSupportedLanguageCodeSchema = z.enum(SUPPORTED_LANGUAGE_CODES).catch('en');
+export * from './locales';
-export type SupportedLanguageCodes = (typeof SUPPORTED_LANGUAGE_CODES)[number];
+export const ZSupportedLanguageCodeSchema = z.enum(SUPPORTED_LANGUAGE_CODES).catch('en');
export type I18nLocaleData = {
/**
@@ -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<string, SupportedLanguage> = {
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<SupportedLanguageCodes, SupportedLanguage>;
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) => (
<CommandItem
key={language.short}
- value={language.full}
+ value={_(language.full)}
onSelect={async () => setLanguage(language.short)}
>
<CheckIcon
@@ -54,7 +54,7 @@ export const LanguageSwitcherDialog = ({ open, setOpen }: LanguageSwitcherDialog
i18n.locale === language.short ? 'opacity-100' : 'opacity-0',
)}
/>
- {SUPPORTED_LANGUAGES[language.short].full}
+ {_(language.full)}
</CommandItem>
))}
</CommandGroup>
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 = ({
<SelectContent>
{Object.entries(SUPPORTED_LANGUAGES).map(([code, language]) => (
<SelectItem key={code} value={code}>
- {language.full}
+ {t(language.full)}
</SelectItem>
))}
</SelectContent>
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 = ({
<SelectContent>
{Object.entries(SUPPORTED_LANGUAGES).map(([code, language]) => (
<SelectItem key={code} value={code}>
- {language.full}
+ {t(language.full)}
</SelectItem>
))}
</SelectContent>
@@ -391,7 +391,7 @@ export const AddTemplateSettingsFormPartial = ({
{Object.values(DOCUMENT_DISTRIBUTION_METHODS).map(
({ value, description }) => (
<SelectItem key={value} value={value}>
- {i18n._(description)}
+ {t(description)}
</SelectItem>
),
)}