Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add translations (#1054)

Leendert de Borst59b118b35d31
diff --git a/apps/browser-extension/src/entrypoints/contentScript/Popup.ts b/apps/browser-extension/src/entrypoints/contentScript/Popup.ts
index ca48981cb..eb1acb192 100644
--- a/apps/browser-extension/src/entrypoints/contentScript/Popup.ts
+++ b/apps/browser-extension/src/entrypoints/contentScript/Popup.ts
@@ -804,6 +804,8 @@ export async function createAliasCreationPopup(suggestedNames: string[], rootCon
const passwordLengthText = await t('credentials.passwordLength');
const changePasswordComplexityText = await t('credentials.changePasswordComplexity');
+ const suggestedNamesHtml = await getSuggestedNamesHtml(suggestedNames, suggestedNames[0] ?? '');
+
// Create the main content
popup.innerHTML = `
<div class="av-create-popup-header">
@@ -853,11 +855,7 @@ export async function createAliasCreationPopup(suggestedNames: string[], rootCon
class="av-create-popup-input"
placeholder="${enterServiceNameText}"
>
- ${suggestedNames.length > 1 ? `
- <div class="av-suggested-names">
- ${getSuggestedNamesHtml(suggestedNames, suggestedNames[0] ?? '')}
- </div>
- ` : ''}
+ ${suggestedNames.length > 1 ? `<div class="av-suggested-names">${suggestedNamesHtml}</div>` : ''}
</div>
<div class="av-create-popup-mode av-create-popup-random-mode">
@@ -1475,7 +1473,7 @@ export async function createAliasCreationPopup(suggestedNames: string[], rootCon
/**
* Handle suggested name click.
*/
- const handleSuggestedNameClick = (e: Event) : void => {
+ const handleSuggestedNameClick = async (e: Event) : Promise<void> => {
const target = e.target as HTMLElement;
if (target.classList.contains('av-suggested-name')) {
const name = target.dataset.name;
@@ -1488,7 +1486,7 @@ export async function createAliasCreationPopup(suggestedNames: string[], rootCon
const suggestedNamesContainer = target.closest('.av-suggested-names');
if (suggestedNamesContainer) {
// Update the suggestions HTML using the helper function
- suggestedNamesContainer.innerHTML = getSuggestedNamesHtml(suggestedNames, name);
+ suggestedNamesContainer.innerHTML = await getSuggestedNamesHtml(suggestedNames, name);
}
}
}
@@ -1505,7 +1503,7 @@ export async function createAliasCreationPopup(suggestedNames: string[], rootCon
/**
* Get suggested names HTML with current input value excluded
*/
-function getSuggestedNamesHtml(suggestedNames: string[], currentValue: string): string {
+async function getSuggestedNamesHtml(suggestedNames: string[], currentValue: string): Promise<string> {
// Filter out the current value and create unique set of remaining suggestions
const filteredSuggestions = [...new Set(suggestedNames.filter(n => n !== currentValue))];
@@ -1513,7 +1511,9 @@ function getSuggestedNamesHtml(suggestedNames: string[], currentValue: string):
return '';
}
- return `or ${filteredSuggestions.map((name, index) =>
+ const orLabel = await t('content.or');
+
+ return `${orLabel} ${filteredSuggestions.map((name, index) =>
`<span class="av-suggested-name" data-name="${name}">${name}</span>${index < filteredSuggestions.length - 1 ? ', ' : ''}`
).join('')}?`;
}
diff --git a/apps/browser-extension/src/entrypoints/popup/pages/CredentialAddEdit.tsx b/apps/browser-extension/src/entrypoints/popup/pages/CredentialAddEdit.tsx
index b05bc3798..e8c266cf2 100644
--- a/apps/browser-extension/src/entrypoints/popup/pages/CredentialAddEdit.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/pages/CredentialAddEdit.tsx
@@ -35,38 +35,6 @@ type PersistedFormData = {
formValues: Omit<Credential, 'Logo'> & { Logo?: string | null };
}
-/**
- * Validation schema for the credential form.
- */
-const credentialSchema = Yup.object().shape({
- Id: Yup.string(),
- ServiceName: Yup.string().required('Service name is required'),
- ServiceUrl: Yup.string().url('Invalid URL format').nullable().optional(),
- Alias: Yup.object().shape({
- FirstName: Yup.string().nullable().optional(),
- LastName: Yup.string().nullable().optional(),
- NickName: Yup.string().nullable().optional(),
- BirthDate: Yup.string()
- .nullable()
- .optional()
- .test(
- 'is-valid-date-format',
- 'Date must be in YYYY-MM-DD format',
- value => {
- if (!value) {
- return true;
- }
- return /^\d{4}-\d{2}-\d{2}$/.test(value);
- },
- ),
- Gender: Yup.string().nullable().optional(),
- Email: Yup.string().email('Invalid email format').nullable().optional()
- }),
- Username: Yup.string().nullable().optional(),
- Password: Yup.string().nullable().optional(),
- Notes: Yup.string().nullable().optional()
-});
-
/**
* Add or edit credential page.
*/
@@ -78,6 +46,38 @@ const CredentialAddEdit: React.FC = () => {
// If we received an ID, we're in edit mode
const isEditMode = id !== undefined && id.length > 0;
+ /**
+ * Validation schema for the credential form with translatable messages.
+ */
+ const credentialSchema = useMemo(() => Yup.object().shape({
+ Id: Yup.string(),
+ ServiceName: Yup.string().required(t('credentials.validation.serviceNameRequired')),
+ ServiceUrl: Yup.string().url(t('credentials.validation.invalidUrl')).nullable().optional(),
+ Alias: Yup.object().shape({
+ FirstName: Yup.string().nullable().optional(),
+ LastName: Yup.string().nullable().optional(),
+ NickName: Yup.string().nullable().optional(),
+ BirthDate: Yup.string()
+ .nullable()
+ .optional()
+ .test(
+ 'is-valid-date-format',
+ t('credentials.validation.invalidDateFormat'),
+ value => {
+ if (!value) {
+ return true;
+ }
+ return /^\d{4}-\d{2}-\d{2}$/.test(value);
+ },
+ ),
+ Gender: Yup.string().nullable().optional(),
+ Email: Yup.string().email(t('credentials.validation.invalidEmail')).nullable().optional()
+ }),
+ Username: Yup.string().nullable().optional(),
+ Password: Yup.string().nullable().optional(),
+ Notes: Yup.string().nullable().optional()
+ }), [t]);
+
const { executeVaultMutation, isLoading, syncStatus } = useVaultMutate();
const [mode, setMode] = useState<CredentialMode>('random');
const { setHeaderButtons } = useHeaderButtons();
diff --git a/apps/browser-extension/src/entrypoints/popup/pages/EmailsList.tsx b/apps/browser-extension/src/entrypoints/popup/pages/EmailsList.tsx
index 7fb116c1e..c8ec59929 100644
--- a/apps/browser-extension/src/entrypoints/popup/pages/EmailsList.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/pages/EmailsList.tsx
@@ -1,4 +1,5 @@
import React, { useEffect, useState, useCallback } from 'react';
+import { useTranslation } from 'react-i18next';
import { Link } from 'react-router-dom';
import HeaderButton from '@/entrypoints/popup/components/HeaderButton';
@@ -20,6 +21,7 @@ import { useMinDurationLoading } from '@/hooks/useMinDurationLoading';
* Emails list page.
*/
const EmailsList: React.FC = () => {
+ const { t } = useTranslation();
const dbContext = useDb();
const webApi = useWebApi();
const { setHeaderButtons } = useHeaderButtons();
@@ -64,15 +66,15 @@ const EmailsList: React.FC = () => {
setEmails(decryptedEmails);
} catch (error) {
console.error(error);
- throw new Error('Failed to load emails');
+ throw new Error(t('emails.errors.emailLoadError'));
}
} catch (err) {
- setError(err instanceof Error ? err.message : 'An error occurred');
+ setError(err instanceof Error ? err.message : t('common.errors.unknownError'));
} finally {
setIsLoading(false);
setIsInitialLoading(false);
}
- }, [dbContext?.sqliteClient, webApi, setIsLoading, setIsInitialLoading]);
+ }, [dbContext?.sqliteClient, webApi, setIsLoading, setIsInitialLoading, t]);
useEffect(() => {
loadEmails();
@@ -83,7 +85,7 @@ const EmailsList: React.FC = () => {
const headerButtonsJSX = !PopoutUtility.isPopup() ? (
<HeaderButton
onClick={() => PopoutUtility.openInNewPopup()}
- title="Open in new window"
+ title={t('common.openInNewWindow')}
iconType={HeaderIconType.EXPAND}
/>
) : null;
@@ -93,7 +95,7 @@ const EmailsList: React.FC = () => {
return () => {
setHeaderButtons(null);
};
- }, [setHeaderButtons]);
+ }, [setHeaderButtons, t]);
/**
* Formats the date display for emails
@@ -104,18 +106,18 @@ const EmailsList: React.FC = () => {
const secondsAgo = Math.floor((now.getTime() - emailDate.getTime()) / 1000);
if (secondsAgo < 60) {
- return 'just now';
+ return t('emails.dateFormat.justNow');
} else if (secondsAgo < 3600) {
// Less than 1 hour ago
const minutes = Math.floor(secondsAgo / 60);
- return `${minutes} ${minutes === 1 ? 'min' : 'mins'} ago`;
+ return t('emails.dateFormat.minutesAgo', { count: minutes });
} else if (secondsAgo < 86400) {
// Less than 24 hours ago
const hours = Math.floor(secondsAgo / 3600);
- return `${hours} ${hours === 1 ? 'hr' : 'hrs'} ago`;
+ return t('emails.dateFormat.hoursAgo', { count: hours });
} else if (secondsAgo < 172800) {
// Less than 48 hours ago
- return 'yesterday';
+ return t('emails.dateFormat.yesterday');
} else {
// Older than 48 hours
return emailDate.toLocaleDateString('en-GB', {
@@ -134,19 +136,19 @@ const EmailsList: React.FC = () => {
}
if (error) {
- return <div className="text-red-500">Error: {error}</div>;
+ return <div className="text-red-500">{t('common.error')}: {error}</div>;
}
if (emails.length === 0) {
return (
<div>
<div className="flex justify-between items-center mb-4">
- <h2 className="text-gray-900 dark:text-white text-xl">Emails</h2>
+ <h2 className="text-gray-900 dark:text-white text-xl">{t('emails.title')}</h2>
<ReloadButton onClick={loadEmails} />
</div>
<div className="text-gray-500 dark:text-gray-400 space-y-2">
<p className="text-sm">
- You have not received any emails at your private email addresses yet. When you receive a new email, it will appear here.
+ {t('emails.noEmailsDescription')}
</p>
</div>
</div>
@@ -156,7 +158,7 @@ const EmailsList: React.FC = () => {
return (
<div>
<div className="flex justify-between items-center mb-4">
- <h2 className="text-gray-900 dark:text-white text-xl">Emails</h2>
+ <h2 className="text-gray-900 dark:text-white text-xl">{t('emails.title')}</h2>
<ReloadButton onClick={loadEmails} />
</div>
<div className="space-y-2">
diff --git a/apps/browser-extension/src/i18n/locales/en.json b/apps/browser-extension/src/i18n/locales/en.json
index e3442d2fb..594c45673 100644
--- a/apps/browser-extension/src/i18n/locales/en.json
+++ b/apps/browser-extension/src/i18n/locales/en.json
@@ -140,6 +140,7 @@
}
},
"content": {
+ "or": "or",
"new": "New",
"cancel": "Cancel",
"search": "Search",
@@ -256,16 +257,22 @@
"birthDatePlaceholder": "YYYY-MM-DD",
"metadata": "Metadata",
"errors": {
- "serviceNameRequired": "Service name is required",
"invalidUrl": "Please enter a valid URL",
"saveError": "Failed to save credential",
"loadError": "Failed to load credentials",
"deleteError": "Failed to delete credential",
"copyError": "Failed to copy to clipboard"
+ },
+ "validation": {
+ "required": "This field is required",
+ "serviceNameRequired": "Service name is required",
+ "invalidUrl": "Invalid URL format",
+ "invalidEmail": "Invalid email format",
+ "invalidDateFormat": "Date must be in YYYY-MM-DD format"
}
},
"emails": {
- "title": "Email Details",
+ "title": "Emails",
"deleteEmailTitle": "Delete Email",
"deleteEmailConfirm": "Are you sure you want to permanently delete this email?",
"from": "From",
@@ -275,6 +282,15 @@
"attachments": "Attachments",
"emailNotFound": "Email not found",
"noEmails": "No emails found",
+ "noEmailsDescription": "You have not received any emails at your private email addresses yet. When you receive a new email, it will appear here.",
+ "dateFormat": {
+ "justNow": "just now",
+ "minutesAgo_one": "{{count}} min ago",
+ "minutesAgo_other": "{{count}} mins ago",
+ "hoursAgo_one": "{{count}} hr ago",
+ "hoursAgo_other": "{{count}} hrs ago",
+ "yesterday": "yesterday"
+ },
"errors": {
"emailLoadError": "An error occurred while loading emails. Please try again later.",
"emailUnexpectedError": "An unexpected error occurred while loading emails. Please try again later."
diff --git a/apps/mobile-app/app/(tabs)/credentials/add-edit.tsx b/apps/mobile-app/app/(tabs)/credentials/add-edit.tsx
index 191734587..44b7045bc 100644
--- a/apps/mobile-app/app/(tabs)/credentials/add-edit.tsx
+++ b/apps/mobile-app/app/(tabs)/credentials/add-edit.tsx
@@ -15,7 +15,7 @@ import type { FaviconExtractModel } from '@/utils/dist/shared/models/webapi';
import { CreatePasswordGenerator, PasswordGenerator } from '@/utils/dist/shared/password-generator';
import emitter from '@/utils/EventEmitter';
import { extractServiceNameFromUrl } from '@/utils/UrlUtility';
-import { credentialSchema } from '@/utils/ValidationSchema';
+import { createCredentialSchema } from '@/utils/ValidationSchema';
import { useColors } from '@/hooks/useColorScheme';
import { useVaultMutate } from '@/hooks/useVaultMutate';
@@ -56,7 +56,7 @@ export default function AddEditCredentialScreen() : React.ReactNode {
const { t } = useTranslation();
const { control, handleSubmit, setValue, watch } = useForm<Credential>({
- resolver: yupResolver(credentialSchema) as Resolver<Credential>,
+ resolver: yupResolver(createCredentialSchema(t)) as Resolver<Credential>,
defaultValues: {
Id: "",
Username: "",
diff --git a/apps/mobile-app/components/EmailCard.tsx b/apps/mobile-app/components/EmailCard.tsx
index 00cf294ef..1693705af 100644
--- a/apps/mobile-app/components/EmailCard.tsx
+++ b/apps/mobile-app/components/EmailCard.tsx
@@ -6,6 +6,7 @@ import type { Credential } from '@/utils/dist/shared/models/vault';
import type { MailboxEmail } from '@/utils/dist/shared/models/webapi';
import { useColors } from '@/hooks/useColorScheme';
+import { useTranslation } from '@/hooks/useTranslation';
import { ThemedText } from '@/components/themed/ThemedText';
import { IconSymbol } from '@/components/ui/IconSymbol';
@@ -21,6 +22,7 @@ type EmailCardProps = {
*/
export function EmailCard({ email }: EmailCardProps) : React.ReactNode {
const colors = useColors();
+ const { t } = useTranslation();
const dbContext = useDb();
const [associatedCredential, setAssociatedCredential] = useState<Credential | null>(null);
@@ -53,15 +55,15 @@ export function EmailCard({ email }: EmailCardProps) : React.ReactNode {
const secondsAgo = Math.floor((now.getTime() - emailDate.getTime()) / 1000);
if (secondsAgo < 60) {
- return 'just now';
+ return t('emails.time.justNow');
} else if (secondsAgo < 3600) {
const minutes = Math.floor(secondsAgo / 60);
- return `${minutes} ${minutes === 1 ? 'min' : 'mins'} ago`;
+ return t('emails.time.minutesAgo', { count: minutes });
} else if (secondsAgo < 86400) {
const hours = Math.floor(secondsAgo / 3600);
- return `${hours} ${hours === 1 ? 'hr' : 'hrs'} ago`;
+ return t('emails.time.hoursAgo', { count: hours });
} else if (secondsAgo < 172800) {
- return 'yesterday';
+ return t('emails.time.yesterday');
} else {
return emailDate.toLocaleDateString('en-GB', {
day: '2-digit',
diff --git a/apps/mobile-app/i18n/locales/en.json b/apps/mobile-app/i18n/locales/en.json
index 7225ea44f..f7245fa5b 100644
--- a/apps/mobile-app/i18n/locales/en.json
+++ b/apps/mobile-app/i18n/locales/en.json
@@ -301,6 +301,12 @@
"sizeKB": "KB",
"offlineMessage": "You are offline. Please connect to the internet to load your emails.",
"emptyMessage": "You have not received any emails at your private email addresses yet. When you receive a new email, it will appear here.",
+ "time": {
+ "justNow": "just now",
+ "minutesAgo": "{{count}} {{count, plural, one {min} other {mins}}} ago",
+ "hoursAgo": "{{count}} {{count, plural, one {hr} other {hrs}}} ago",
+ "yesterday": "yesterday"
+ },
"errors": {
"generic": "An error occurred",
"loadFailed": "Failed to load emails",
@@ -310,6 +316,13 @@
"downloadFailed": "Failed to download attachment"
}
},
+ "validation": {
+ "required": "This field is required",
+ "serviceNameRequired": "Service name is required",
+ "invalidUrlFormat": "Invalid URL format",
+ "invalidDateFormat": "Date must be in YYYY-MM-DD format",
+ "invalidEmailFormat": "Invalid email format"
+ },
"apiErrors": {
"CLAIM_DOES_NOT_MATCH_USER": "The current chosen email address is already in use. Please change the email address by editing this credential.",
"CLAIM_DOES_NOT_EXIST": "An error occurred while trying to load the emails. Please try to edit and save the credential entry to synchronize the database, then try again.",
diff --git a/apps/mobile-app/utils/ValidationSchema.ts b/apps/mobile-app/utils/ValidationSchema.ts
index f7aa72bcf..54bf265d6 100644
--- a/apps/mobile-app/utils/ValidationSchema.ts
+++ b/apps/mobile-app/utils/ValidationSchema.ts
@@ -2,11 +2,13 @@ import * as Yup from 'yup';
/**
* Credential add/edit form validation schema used by react-hook-form.
+ * @param t - Translation function
*/
-export const credentialSchema = Yup.object().shape({
+// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
+export const createCredentialSchema = (t: (key: string) => string) => Yup.object().shape({
Id: Yup.string().optional(),
- ServiceName: Yup.string().required('Service name is required'),
- ServiceUrl: Yup.string().url('Invalid URL format').nullable().notRequired(),
+ ServiceName: Yup.string().required(t('validation.serviceNameRequired')),
+ ServiceUrl: Yup.string().url(t('validation.invalidUrlFormat')).nullable().notRequired(),
Alias: Yup.object().shape({
FirstName: Yup.string().nullable().notRequired(),
LastName: Yup.string().nullable().notRequired(),
@@ -16,7 +18,7 @@ export const credentialSchema = Yup.object().shape({
.notRequired()
.test(
'is-valid-date-format',
- 'Date must be in YYYY-MM-DD format',
+ t('validation.invalidDateFormat'),
value => {
if (!value) {
return true;
@@ -25,7 +27,7 @@ export const credentialSchema = Yup.object().shape({
},
),
Gender: Yup.string().nullable().notRequired(),
- Email: Yup.string().email('Invalid email format').nullable().notRequired()
+ Email: Yup.string().email(t('validation.invalidEmailFormat')).nullable().notRequired()
}),
Username: Yup.string().nullable().notRequired(),
Password: Yup.string().nullable().notRequired(),