diff --git a/.changeset/fuzzy-carrots-push.md b/.changeset/fuzzy-carrots-push.md new file mode 100644 index 00000000000..0ac96aa33b9 --- /dev/null +++ b/.changeset/fuzzy-carrots-push.md @@ -0,0 +1,5 @@ +--- +"@clerk/localizations": minor +--- + +Added support for en-GB localization diff --git a/packages/localizations/package.json b/packages/localizations/package.json index b17725588fd..1b1b0e73bcb 100644 --- a/packages/localizations/package.json +++ b/packages/localizations/package.json @@ -59,6 +59,7 @@ "da-DK", "de-DE", "el-GR", + "en-GB", "en-US", "es-ES", "fi-FI", diff --git a/packages/localizations/src/en-GB.ts b/packages/localizations/src/en-GB.ts new file mode 100644 index 00000000000..1c1b48e35f0 --- /dev/null +++ b/packages/localizations/src/en-GB.ts @@ -0,0 +1,58 @@ +/* + * ===================================================================================== + * DISCLAIMER: + * ===================================================================================== + * This localization file is a community contribution and is not officially maintained + * by Clerk. It has been provided by the community and may not be fully aligned + * with the current or future states of the main application. Clerk does not guarantee + * the accuracy, completeness, or timeliness of the translations in this file. + * Use of this file is at your own risk and discretion. + * ===================================================================================== + */ + +import type { LocalizationResource } from '@clerk/types'; + +import { enUS } from './en-US'; + +export const enGB = translateResource(enUS, { + 'en-US': 'en-GB', + authorize: 'authorise', + Authorize: 'Authorise', + organization: 'organisation', + Organization: 'Organisation', +}); + +type Dictionary = Record; + +function translateResource(resource: LocalizationResource, dict: Dictionary): typeof resource { + return Object.fromEntries(Object.entries(resource).map(([k, v]) => [k, translateResourceValue(v, dict)])); +} + +type ResourceValue = string | undefined | { [key: string]: ResourceValue }; + +function translateResourceValue(value: ResourceValue, dict: Dictionary): typeof value { + if (value === undefined || value === null) { + return value; + } + if (typeof value === 'string') { + return value + .split(' ') + .map(v => translateWord(v, dict)) + .join(' '); + } + return Object.fromEntries( + Object.entries(value).map(([k, v]) => { + return [k, translateResourceValue(v, dict)]; + }), + ); +} + +function translateWord(word: string, dict: Dictionary): typeof word { + return isTemplateVariable(word) + ? word + : Object.entries(dict).reduce((w, [from, to]) => w.replace(RegExp(from), to), word); +} + +function isTemplateVariable(s: string): boolean { + return /{{.+}}/.test(s); +}