Email for professionals and teams
Translate mailbox import
Hieu Nguyen (Jack)bcf17d07f958
diff --git a/src/app/(settings)/settings/import/page.tsx b/src/app/(settings)/settings/import/page.tsxindex e793c77..268e4be 100644--- a/src/app/(settings)/settings/import/page.tsx+++ b/src/app/(settings)/settings/import/page.tsx@@ -3,6 +3,8 @@import type { FormEvent } from "react";import { useMemo, useState } from "react";import { Folder, Server, Upload } from "lucide-react";+import { useLanguage } from "@/components/language-provider";+import type { TranslationKey } from "@/lib/i18n/types";import { useSelectedMailbox } from "@/components/mailbox-provider";import { Button } from "@/components/ui/button";import { Checkbox } from "@/components/ui/checkbox";@@ -51,7 +53,20 @@ const initialImapForm: ImapFormState = {const defaultSections = importSourceOptions.map((option) => option.value);+const SECTION_LABEL_KEYS: Record<ImportSourceSection, TranslationKey> = {+ inbox: "navigation.inbox",+ sent: "navigation.sent",+ drafts: "navigation.drafts",+ archived: "navigation.archived",+ spam: "navigation.spam",+ trash: "navigation.trash",+ others: "importPage.others",+};+export default function SettingsImportPage() {+ const { t } = useLanguage();+ // System sections are translated; folders discovered on the source keep their own names.+ const sourceLabel = (source: ImportSourceItem) => source.sourceSection ? t(SECTION_LABEL_KEYS[source.sourceSection]) : source.label;const { selectedMailbox } = useSelectedMailbox();const [activeTab, setActiveTab] = useState<ImportTab>("file");const [selectedSections, setSelectedSections] =@@ -74,8 +89,8 @@ export default function SettingsImportPage() {const fileImportSource = getFileImportSource(selectedSources);const sourceSummary =selectedSources.length > 0- ? selectedSources.map((source) => source.label).join(", ")- : "Select source sections";+ ? selectedSources.map(sourceLabel).join(", ")+ : t("importPage.selectSections");function toggleSection(section: ImportSourceSection, checked: boolean) {setSelectedSections((current) => {@@ -86,7 +101,7 @@ export default function SettingsImportPage() {}async function getDestination(source: ImportSourceItem): Promise<string> {- if (!selectedMailbox?.id) throw new Error("Select a mailbox first");+ if (!selectedMailbox?.id) throw new Error(t("importPage.selectMailboxFirst"));return ensureImportDestination(selectedMailbox.id, source);}@@ -97,7 +112,7 @@ export default function SettingsImportPage() {setFileLoading(true);setFileError(null);setFileResult(null);- setFileProgress({ completed: 0, total: 100, label: "Preparing files" });+ setFileProgress({ completed: 0, total: 100, label: t("importPage.preparing") });try {const destination = await getDestination(fileImportSource);const result = await importMessageFiles(@@ -108,14 +123,14 @@ export default function SettingsImportPage() {setFileProgress({completed: percentage,total: 100,- label: percentage < 70 ? "Uploading files" : "Importing messages",+ label: percentage < 70 ? t("importPage.uploading") : t("importPage.importingMessages"),}),);setFileResult(result);window.dispatchEvent(new Event("mailflare:messages-changed"));} catch (error) {setFileError(- error instanceof Error ? error.message : "File import failed",+ error instanceof Error ? error.message : t("importPage.fileFailed"),);} finally {setFileLoading(false);@@ -131,7 +146,7 @@ export default function SettingsImportPage() {setImapProgress({completed: 0,total: 1,- label: "Discovering IMAP folders",+ label: t("importPage.discovering"),});try {const total: ImportResult = { imported: 0, skipped: 0, errors: [] };@@ -153,7 +168,7 @@ export default function SettingsImportPage() {setImapProgress({completed: index,total: expandedSources.length,- label: `Importing ${source.label}`,+ label: t("importPage.importingSource", { source: sourceLabel(source) }),});const destination = await getDestination(source);const folder = resolveImapSourceFolder(source, discoveredFolders);@@ -186,13 +201,13 @@ export default function SettingsImportPage() {setImapProgress({completed: index,total: expandedSources.length,- label: `Importing ${source.label} (${processed}/${result.total ?? "?"} messages)`,+ label: t("importPage.importingSourceProgress", { source: sourceLabel(source), processed, total: result.total ?? "?" }),});}setImapProgress({completed: index + 1,total: expandedSources.length,- label: `Imported ${source.label}`,+ label: t("importPage.importedSource", { source: sourceLabel(source) }),});}setImapResult(total);@@ -200,7 +215,7 @@ export default function SettingsImportPage() {window.dispatchEvent(new Event("mailflare:messages-changed"));} catch (error) {setImapError(- error instanceof Error ? error.message : "IMAP import failed",+ error instanceof Error ? error.message : t("importPage.imapFailed"),);} finally {setImapLoading(false);@@ -220,16 +235,16 @@ export default function SettingsImportPage() {<section className="space-y-4"><div><h2 className="text-xl font-semibold text-neutral-900">- Import mailbox+ {t("importPage.title")}</h2><p className="mt-1 text-sm text-neutral-500">- Choose what to import and how Mailflare should receive it.+ {t("importPage.description")}</p></div><div className="space-y-1 overflow-hidden rounded-3xl"><CardContent className="space-y-6 rounded-b-lg rounded-t-3xl bg-white p-6"><div className="flex flex-col gap-2">- <Label htmlFor="import-source">Import source</Label>+ <Label htmlFor="import-source">{t("importPage.source")}</Label><Selectid="import-source"value={activeTab}@@ -239,12 +254,12 @@ export default function SettingsImportPage() {className="text-sm w-full py-2"// className="h-10 w-full rounded-md border border-neutral-200 bg-white px-3 text-sm text-neutral-900 shadow-sm shadow-neutral-200/50 outline-none focus:border-blue-500 focus:ring-2 focus:ring-blue-100">- <option value="file">Backup File</option>- <option value="imap">IMAP</option>+ <option value="file">{t("importPage.backupFile")}</option>+ <option value="imap">{t("importPage.imap")}</option></Select></div><div className="space-y-2">- <Label>Choose import sections</Label>+ <Label>{t("importPage.chooseSections")}</Label><div className="relative"><button@@ -252,7 +267,7 @@ export default function SettingsImportPage() {onClick={() => setSourceDropdownOpen((open) => !open)}className="flex w-full items-center justify-between rounded-md border border-neutral-200 bg-white px-3 py-2 text-left text-sm shadow-sm shadow-neutral-200/50">- <label className="flex-1">Selected</label>+ <label className="flex-1">{t("importPage.selected")}</label><span className="truncate">{sourceSummary}</span><span className="text-neutral-400 px-2">▾</span></button>@@ -269,7 +284,7 @@ export default function SettingsImportPage() {toggleSection(option.value, event.target.checked)}/>- {option.label}+ {t(SECTION_LABEL_KEYS[option.value])}</label>))}</div>@@ -285,7 +300,7 @@ export default function SettingsImportPage() {<><form onSubmit={onFileSubmit} className="space-y-4"><div className="space-y-2">- <Label>Select Backup File</Label>+ <Label>{t("importPage.selectFile")}</Label><Inputid="import-files"type="file"@@ -297,16 +312,12 @@ export default function SettingsImportPage() {className="block w-full rounded-md border border-neutral-200 bg-white px-3 py-1 text-sm shadow-sm shadow-neutral-200/50 file:mr-3 file:rounded-md file:border-0 file:bg-neutral-100 file:px-3 file:py-1.5 file:text-sm file:font-medium"/><p className="text-xs leading-5 text-neutral-500">- Upload exported .eml or .mbox files. File exports do not- reliably include source section metadata, so files are- imported once into {fileImportSource.label}+ {t("importPage.fileHint", { section: sourceLabel(fileImportSource) })}</p></div>{selectedSections.includes("others") && (<p className="rounded-lg border border-amber-100 bg-amber-50 px-4 py-3 text-sm text-amber-700">- Other folders can be imported automatically from IMAP.- File import cannot discover which section a message- belongs to.+ {t("importPage.othersNote")}</p>)}<Button@@ -318,7 +329,7 @@ export default function SettingsImportPage() {fileLoading}>- {fileLoading ? "Importing..." : "Import selected files"}+ {fileLoading ? t("import.importing") : t("importPage.importFiles")}</Button>{fileProgress && (<div@@ -339,7 +350,7 @@ export default function SettingsImportPage() {)}{fileResult && (<p className="rounded-lg border border-green-100 bg-green-50 px-4 py-3 text-sm text-green-700">- {formatImportResult(fileResult)}+ {formatImportResult(fileResult, t)}</p>)}{fileError && (@@ -354,7 +365,7 @@ export default function SettingsImportPage() {<form onSubmit={onImapSubmit} className="space-y-4"><div className="grid gap-3 md:grid-cols-[1fr_110px]"><div className="space-y-2">- <Label htmlFor="imap-host">Host</Label>+ <Label htmlFor="imap-host">{t("importPage.host")}</Label><Inputid="imap-host"value={imapForm.host}@@ -365,7 +376,7 @@ export default function SettingsImportPage() {/></div><div className="space-y-2">- <Label htmlFor="imap-port">Port</Label>+ <Label htmlFor="imap-port">{t("importPage.port")}</Label><Inputid="imap-port"type="number"@@ -378,7 +389,7 @@ export default function SettingsImportPage() {</div><div className="grid gap-3 md:grid-cols-2"><div className="space-y-2">- <Label htmlFor="imap-username">Username</Label>+ <Label htmlFor="imap-username">{t("importPage.username")}</Label><Inputid="imap-username"value={imapForm.username}@@ -393,7 +404,7 @@ export default function SettingsImportPage() {</div><div className="space-y-2"><Label htmlFor="imap-password">- Password or app password+ {t("importPage.passwordOrApp")}</Label><Inputid="imap-password"@@ -413,8 +424,8 @@ export default function SettingsImportPage() {<div className="space-y-2"><Label htmlFor="imap-limit">{imapForm.importAll- ? "Messages per batch"- : "Message limit per source"}+ ? t("importPage.perBatch")+ : t("importPage.perSource")}</Label><Inputid="imap-limit"@@ -440,7 +451,7 @@ export default function SettingsImportPage() {})}/>- Import all messages (newest first, in batches)+ {t("importPage.importAll")}</label><label className="flex items-end gap-2 pb-2 text-sm text-neutral-700"><Checkbox@@ -452,13 +463,11 @@ export default function SettingsImportPage() {})}/>- Use TLS+ {t("importPage.useTls")}</label></div><p className="rounded-lg border border-neutral-200 bg-neutral-50 px-4 py-3 text-xs leading-5 text-neutral-500">- IMAP imports selected source sections automatically. Folders- are discovered from the source account and imported into- matching new or existing Mailflare folders.+ {t("importPage.imapNote")}</p><Buttontype="submit"@@ -472,7 +481,7 @@ export default function SettingsImportPage() {}><Upload className="h-4 w-4" />- {imapLoading ? "Importing..." : "Import selected sources"}+ {imapLoading ? t("import.importing") : t("importPage.importSources")}</Button>{imapProgress && (<div@@ -497,7 +506,7 @@ export default function SettingsImportPage() {)}{imapResult && (<p className="rounded-lg border border-green-100 bg-green-50 px-4 py-3 text-sm text-green-700">- {formatImportResult(imapResult)}+ {formatImportResult(imapResult, t)}</p>)}{imapError && (diff --git a/src/app/(settings)/settings/import/utils.ts b/src/app/(settings)/settings/import/utils.tsindex 7df7307..a848c58 100644--- a/src/app/(settings)/settings/import/utils.ts+++ b/src/app/(settings)/settings/import/utils.ts@@ -1,3 +1,4 @@+import { defaultTranslator, type Translator } from "@/lib/i18n/utils";import { authFetch } from "@/lib/auth/client";import type {ImapFormState,@@ -139,9 +140,9 @@ export async function fetchImapFolders(form: ImapFormState): Promise<string[]> {return data.folders ?? [];}-export function formatImportResult(result: ImportResult | null): string {+export function formatImportResult(result: ImportResult | null, t: Translator = defaultTranslator): string {if (!result) return "";- return `${result.imported ?? 0} imported, ${result.skipped ?? 0} skipped`;+ return t("import.summary", { imported: result.imported ?? 0, skipped: result.skipped ?? 0 });}function findFolderMatch(folders: string[], aliases: string[]): string | null {diff --git a/src/lib/i18n/en.json b/src/lib/i18n/en.jsonindex 0561199..b116b72 100644--- a/src/lib/i18n/en.json+++ b/src/lib/i18n/en.json@@ -1825,5 +1825,38 @@"agent.queue.sendNow": "Send now","agent.queue.remove": "Remove queued message","agent.loadingConversation": "Loading conversation",- "agent.duration.lessThanSecond": "<1s"+ "agent.duration.lessThanSecond": "<1s",+ "importPage.others": "Others",+ "importPage.selectSections": "Select source sections",+ "importPage.selectMailboxFirst": "Select a mailbox first",+ "importPage.preparing": "Preparing files",+ "importPage.uploading": "Uploading files",+ "importPage.importingMessages": "Importing messages",+ "importPage.fileFailed": "File import failed",+ "importPage.discovering": "Discovering IMAP folders",+ "importPage.importingSource": "Importing {source}",+ "importPage.importingSourceProgress": "Importing {source} ({processed}/{total} messages)",+ "importPage.importedSource": "Imported {source}",+ "importPage.imapFailed": "IMAP import failed",+ "importPage.title": "Import mailbox",+ "importPage.description": "Choose what to import and how Mailflare should receive it.",+ "importPage.source": "Import source",+ "importPage.backupFile": "Backup File",+ "importPage.imap": "IMAP",+ "importPage.chooseSections": "Choose import sections",+ "importPage.selected": "Selected",+ "importPage.selectFile": "Select Backup File",+ "importPage.fileHint": "Upload exported .eml or .mbox files. File exports do not reliably include source section metadata, so files are imported once into {section}",+ "importPage.othersNote": "Other folders can be imported automatically from IMAP. File import cannot discover which section a message belongs to.",+ "importPage.importFiles": "Import selected files",+ "importPage.host": "Host",+ "importPage.port": "Port",+ "importPage.username": "Username",+ "importPage.passwordOrApp": "Password or app password",+ "importPage.perBatch": "Messages per batch",+ "importPage.perSource": "Message limit per source",+ "importPage.importAll": "Import all messages (newest first, in batches)",+ "importPage.useTls": "Use TLS",+ "importPage.imapNote": "IMAP imports selected source sections automatically. Folders are discovered from the source account and imported into matching new or existing Mailflare folders.",+ "importPage.importSources": "Import selected sources"}diff --git a/src/lib/i18n/pt-BR.json b/src/lib/i18n/pt-BR.jsonindex 936871a..cba552b 100644--- a/src/lib/i18n/pt-BR.json+++ b/src/lib/i18n/pt-BR.json@@ -1825,5 +1825,38 @@"agent.queue.sendNow": "Enviar agora","agent.queue.remove": "Remover mensagem da fila","agent.loadingConversation": "Carregando conversa",- "agent.duration.lessThanSecond": "<1s"+ "agent.duration.lessThanSecond": "<1s",+ "importPage.others": "Outras",+ "importPage.selectSections": "Selecione as seções de origem",+ "importPage.selectMailboxFirst": "Selecione uma caixa de correio primeiro",+ "importPage.preparing": "Preparando arquivos",+ "importPage.uploading": "Enviando arquivos",+ "importPage.importingMessages": "Importando mensagens",+ "importPage.fileFailed": "Falha na importação do arquivo",+ "importPage.discovering": "Descobrindo pastas IMAP",+ "importPage.importingSource": "Importando {source}",+ "importPage.importingSourceProgress": "Importando {source} ({processed}/{total} mensagens)",+ "importPage.importedSource": "{source} importado",+ "importPage.imapFailed": "Falha na importação IMAP",+ "importPage.title": "Importar caixa de correio",+ "importPage.description": "Escolha o que importar e como o Mailflare deve recebê-lo.",+ "importPage.source": "Origem da importação",+ "importPage.backupFile": "Arquivo de backup",+ "importPage.imap": "IMAP",+ "importPage.chooseSections": "Escolha as seções a importar",+ "importPage.selected": "Selecionadas",+ "importPage.selectFile": "Selecione o arquivo de backup",+ "importPage.fileHint": "Envie arquivos .eml ou .mbox exportados. Exportações em arquivo não incluem de forma confiável os metadados da seção de origem, então os arquivos são importados uma única vez para {section}",+ "importPage.othersNote": "As outras pastas podem ser importadas automaticamente do IMAP. A importação de arquivo não consegue descobrir a qual seção uma mensagem pertence.",+ "importPage.importFiles": "Importar os arquivos selecionados",+ "importPage.host": "Host",+ "importPage.port": "Porta",+ "importPage.username": "Nome de usuário",+ "importPage.passwordOrApp": "Senha ou senha de aplicativo",+ "importPage.perBatch": "Mensagens por lote",+ "importPage.perSource": "Limite de mensagens por origem",+ "importPage.importAll": "Importar todas as mensagens (as mais recentes primeiro, em lotes)",+ "importPage.useTls": "Usar TLS",+ "importPage.imapNote": "O IMAP importa automaticamente as seções de origem selecionadas. As pastas são descobertas na conta de origem e importadas para pastas novas ou existentes do Mailflare.",+ "importPage.importSources": "Importar as origens selecionadas"}