Skip to content

Commit

Permalink
chore(clerk-js,types,localizations): Add translation keys for organiz…
Browse files Browse the repository at this point in the history
…ations API errors (#4123)
  • Loading branch information
LauraBeatris authored Sep 11, 2024
1 parent 46fc758 commit 1189f71
Show file tree
Hide file tree
Showing 39 changed files with 2,148 additions and 76 deletions.
7 changes: 7 additions & 0 deletions .changeset/silly-carrots-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@clerk/localizations": patch
"@clerk/clerk-js": patch
"@clerk/types": patch
---

Adds translation keys for error messages from the [organizations API](https://clerk.com/docs/references/api/organizations#errors).
2 changes: 1 addition & 1 deletion packages/clerk-js/bundlewatch.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"files": [
{ "path": "./dist/clerk.browser.js", "maxSize": "64kB" },
{ "path": "./dist/clerk.headless.js", "maxSize": "43kB" },
{ "path": "./dist/ui-common*.js", "maxSize": "85KB" },
{ "path": "./dist/ui-common*.js", "maxSize": "86KB" },
{ "path": "./dist/vendors*.js", "maxSize": "70KB" },
{ "path": "./dist/coinbase*.js", "maxSize": "58KB" },
{ "path": "./dist/createorganization*.js", "maxSize": "5KB" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const InviteMembersForm = (props: InviteMembersFormProps) => {
},
});
const card = useCardState();
const { t, locale, translateError } = useLocalizations();
const { t, locale } = useLocalizations();
const [isValidUnsubmittedEmail, setIsValidUnsubmittedEmail] = useState(false);

const validateUnsubmittedEmail = (value: string) => setIsValidUnsubmittedEmail(isEmail(value));
Expand Down Expand Up @@ -85,24 +85,53 @@ export const InviteMembersForm = (props: InviteMembersFormProps) => {
return onSuccess?.();
})
.catch(err => {
if (isClerkAPIResponseError(err)) {
removeInvalidEmails(err.errors[0]);
if (!isClerkAPIResponseError(err)) {
handleError(err, [], card.setError);
return;
}

if (isClerkAPIResponseError(err) && err.errors?.[0]?.code === 'duplicate_record') {
const unlocalizedEmailsList = err.errors[0].meta?.emailAddresses || [];
card.setError(
t(
localizationKeys('organizationProfile.invitePage.detailsTitle__inviteFailed', {
// Create a localized list of email addresses
email_addresses: createListFormat(unlocalizedEmailsList, locale),
}),
),
);
} else if (isClerkAPIResponseError(err) && err.errors?.[0]?.code === 'form_param_format_invalid') {
card.setError(translateError(err.errors[0]));
} else {
handleError(err, [], card.setError);
removeInvalidEmails(err.errors[0]);

switch (err.errors?.[0]?.code) {
case 'duplicate_record': {
const unlocalizedEmailsList = err.errors[0].meta?.emailAddresses || [];
card.setError(
t(
localizationKeys('organizationProfile.invitePage.detailsTitle__inviteFailed', {
// Create a localized list of email addresses
email_addresses: createListFormat(unlocalizedEmailsList, locale),
}),
),
);
break;
}
case 'already_a_member_in_organization': {
/**
* Extracts email from the error message since it's not provided in the error response
*/
const longMessage = err.errors[0].longMessage ?? '';
const email = longMessage.match(/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/)?.[0];

handleError(err, [], err =>
email
? /**
* Fallbacks to original error message in case the email cannot be extracted
*/
card.setError(
t(
localizationKeys('unstable__errors.already_a_member_in_organization', {
email,
}),
),
)
: card.setError(err),
);

break;
}
default: {
handleError(err, [], card.setError);
}
}
});
};
Expand Down
8 changes: 8 additions & 0 deletions packages/clerk-js/src/ui/localization/makeLocalizable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ export const useLocalizations = () => {
return localizedStringFromKey(localizationKey, parsedResource, globalTokens);
};

/**
* Translates a Clerk error message based on its code.
*
* @remarks
* - For `ClerkRuntimeError`, it attempts to find a localized message using the error code.
* - For `ClerkAPIError`, it tries to find a localized message using the error code and parameter name.
* - If no localized message is found, it falls back to the original error message.
*/
const translateError = (error: ClerkRuntimeError | ClerkAPIError | string | undefined) => {
if (!error || typeof error === 'string') {
return t(error);
Expand Down
61 changes: 61 additions & 0 deletions packages/localizations/src/ar-SA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,61 @@ import type { LocalizationResource } from '@clerk/types';

export const arSA: LocalizationResource = {
locale: 'ar-SA',
__experimental_userVerification: {
alternativeMethods: {
actionLink: undefined,
actionText: undefined,
blockButton__backupCode: undefined,
blockButton__emailCode: undefined,
blockButton__password: undefined,
blockButton__phoneCode: undefined,
blockButton__totp: undefined,
getHelp: {
blockButton__emailSupport: undefined,
content: undefined,
title: undefined,
},
subtitle: undefined,
title: undefined,
},
backupCodeMfa: {
subtitle: undefined,
title: undefined,
},
emailCode: {
formTitle: undefined,
resendButton: undefined,
subtitle: undefined,
title: undefined,
},
noAvailableMethods: {
message: undefined,
subtitle: undefined,
title: undefined,
},
password: {
actionLink: undefined,
subtitle: undefined,
title: undefined,
},
phoneCode: {
formTitle: undefined,
resendButton: undefined,
subtitle: undefined,
title: undefined,
},
phoneCodeMfa: {
formTitle: undefined,
resendButton: undefined,
subtitle: undefined,
title: undefined,
},
totpMfa: {
formTitle: undefined,
subtitle: undefined,
title: undefined,
},
},
backButton: 'الرجوع',
badge__default: 'الأفتراضي',
badge__otherImpersonatorDevice: 'جهاز منتحل آخر',
Expand Down Expand Up @@ -466,6 +521,7 @@ export const arSA: LocalizationResource = {
socialButtonsBlockButton: 'للمتابعة مع {{provider|titleize}}',
socialButtonsBlockButtonManyInView: '{{provider|titleize}}',
unstable__errors: {
already_a_member_in_organization: undefined,
captcha_invalid:
'لا يمكن تسجيل الحساب بسبب مشاكل تحقق أمنية. الرجاء تحديث الصفحة للمحاولة مرة أخرى أو تواصل معنا للمزيد من المساعدة',
captcha_unavailable:
Expand Down Expand Up @@ -495,6 +551,10 @@ export const arSA: LocalizationResource = {
form_username_invalid_length: '',
identification_deletion_failed: 'لا يمكن حذف هويتك الآخيرة ',
not_allowed_access: '',
organization_domain_blocked: undefined,
organization_domain_common: undefined,
organization_membership_quota_exceeded: undefined,
organization_minimum_permissions_needed: undefined,
passkey_already_exists: 'تم تسجيل مفتاح المرور مسبقاً مع هذا الجهاز',
passkey_not_supported: 'مفاتيح المرور غير مدعومة على هذا الجهاز',
passkey_pa_not_supported: 'يتطلب التسجيل أداة مصادقة النظام الأساسي ولكن الجهاز لا يدعمها',
Expand Down Expand Up @@ -815,6 +875,7 @@ export const arSA: LocalizationResource = {
subtitle__unavailableWallets: 'لا توجد اي محفظة web3 متاحة',
successMessage: 'تمت إضافة المحفظة الى حسابك.',
title: 'إضافة محفظة web3',
web3WalletButtonsBlockButton: undefined,
},
},
} as const;
61 changes: 61 additions & 0 deletions packages/localizations/src/bg-BG.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,61 @@ import type { LocalizationResource } from '@clerk/types';

export const bgBG: LocalizationResource = {
locale: 'bg-BG',
__experimental_userVerification: {
alternativeMethods: {
actionLink: undefined,
actionText: undefined,
blockButton__backupCode: undefined,
blockButton__emailCode: undefined,
blockButton__password: undefined,
blockButton__phoneCode: undefined,
blockButton__totp: undefined,
getHelp: {
blockButton__emailSupport: undefined,
content: undefined,
title: undefined,
},
subtitle: undefined,
title: undefined,
},
backupCodeMfa: {
subtitle: undefined,
title: undefined,
},
emailCode: {
formTitle: undefined,
resendButton: undefined,
subtitle: undefined,
title: undefined,
},
noAvailableMethods: {
message: undefined,
subtitle: undefined,
title: undefined,
},
password: {
actionLink: undefined,
subtitle: undefined,
title: undefined,
},
phoneCode: {
formTitle: undefined,
resendButton: undefined,
subtitle: undefined,
title: undefined,
},
phoneCodeMfa: {
formTitle: undefined,
resendButton: undefined,
subtitle: undefined,
title: undefined,
},
totpMfa: {
formTitle: undefined,
subtitle: undefined,
title: undefined,
},
},
backButton: 'Назад',
badge__default: 'По подразбиране',
badge__otherImpersonatorDevice: 'Друго устройство за имитация',
Expand Down Expand Up @@ -467,6 +522,7 @@ export const bgBG: LocalizationResource = {
socialButtonsBlockButton: 'Продължи с {{provider|titleize}}',
socialButtonsBlockButtonManyInView: undefined,
unstable__errors: {
already_a_member_in_organization: undefined,
captcha_invalid:
'Регистрацията неуспешна поради неуспешни проверки за сигурност. Моля, презаредете страницата, за да опитате отново, или се свържете с поддръжката за повече помощ.',
captcha_unavailable:
Expand Down Expand Up @@ -496,6 +552,10 @@ export const bgBG: LocalizationResource = {
form_username_invalid_length: '',
identification_deletion_failed: 'Не можете да изтриете последната си идентификация.',
not_allowed_access: '',
organization_domain_blocked: undefined,
organization_domain_common: undefined,
organization_membership_quota_exceeded: undefined,
organization_minimum_permissions_needed: undefined,
passkey_already_exists: undefined,
passkey_not_supported: undefined,
passkey_pa_not_supported: undefined,
Expand Down Expand Up @@ -822,6 +882,7 @@ export const bgBG: LocalizationResource = {
subtitle__unavailableWallets: 'Няма налични web3 портфейли.',
successMessage: 'Портфейлът беше добавен към вашия профил.',
title: 'Добави web3 портфейл',
web3WalletButtonsBlockButton: undefined,
},
},
} as const;
61 changes: 61 additions & 0 deletions packages/localizations/src/cs-CZ.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,61 @@ import type { LocalizationResource } from '@clerk/types';

export const csCZ: LocalizationResource = {
locale: 'cs-CZ',
__experimental_userVerification: {
alternativeMethods: {
actionLink: undefined,
actionText: undefined,
blockButton__backupCode: undefined,
blockButton__emailCode: undefined,
blockButton__password: undefined,
blockButton__phoneCode: undefined,
blockButton__totp: undefined,
getHelp: {
blockButton__emailSupport: undefined,
content: undefined,
title: undefined,
},
subtitle: undefined,
title: undefined,
},
backupCodeMfa: {
subtitle: undefined,
title: undefined,
},
emailCode: {
formTitle: undefined,
resendButton: undefined,
subtitle: undefined,
title: undefined,
},
noAvailableMethods: {
message: undefined,
subtitle: undefined,
title: undefined,
},
password: {
actionLink: undefined,
subtitle: undefined,
title: undefined,
},
phoneCode: {
formTitle: undefined,
resendButton: undefined,
subtitle: undefined,
title: undefined,
},
phoneCodeMfa: {
formTitle: undefined,
resendButton: undefined,
subtitle: undefined,
title: undefined,
},
totpMfa: {
formTitle: undefined,
subtitle: undefined,
title: undefined,
},
},
backButton: 'Zpět',
badge__default: 'Výchozí',
badge__otherImpersonatorDevice: 'Jiné zařízení představitele',
Expand Down Expand Up @@ -465,6 +520,7 @@ export const csCZ: LocalizationResource = {
socialButtonsBlockButton: 'Pokračovat s {{provider|titleize}}',
socialButtonsBlockButtonManyInView: undefined,
unstable__errors: {
already_a_member_in_organization: undefined,
captcha_invalid:
'Sign up unsuccessful due to failed security validations. Please refresh the page to try again or reach out to support for more assistance.',
captcha_unavailable:
Expand Down Expand Up @@ -494,6 +550,10 @@ export const csCZ: LocalizationResource = {
form_username_invalid_length: '',
identification_deletion_failed: 'You cannot delete your last identification.',
not_allowed_access: '',
organization_domain_blocked: undefined,
organization_domain_common: undefined,
organization_membership_quota_exceeded: undefined,
organization_minimum_permissions_needed: undefined,
passkey_already_exists: undefined,
passkey_not_supported: undefined,
passkey_pa_not_supported: undefined,
Expand Down Expand Up @@ -818,6 +878,7 @@ export const csCZ: LocalizationResource = {
subtitle__unavailableWallets: 'Nejsou k dispozici žádné dostupné web3 peněženky.',
successMessage: 'Peněženka byla přidána k vašemu účtu.',
title: 'Přidat web3 peněženku',
web3WalletButtonsBlockButton: undefined,
},
},
} as const;
Loading

0 comments on commit 1189f71

Please sign in to comment.