From 4d6a7e8ba4660f8861de8c8b0f1b45a205b5c738 Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Thu, 29 Sep 2022 18:08:43 +0800 Subject: refactor: Transition back to non-namespaced i18n --- apps/kit/src/lib/i18n/en/index.ts | 8 + apps/kit/src/lib/i18n/en/reset-password/index.ts | 9 -- apps/kit/src/lib/i18n/en/sign-in/index.ts | 10 -- apps/kit/src/lib/i18n/en/sign-up/index.ts | 6 - apps/kit/src/lib/i18n/i18n-types.ts | 168 ++++++++------------- apps/kit/src/lib/i18n/i18n-util.async.ts | 5 +- apps/kit/src/lib/i18n/i18n-util.sync.ts | 8 +- apps/kit/src/lib/i18n/i18n-util.ts | 5 +- .../(main)/(public)/reset-password/+page.svelte | 11 +- .../routes/(main)/(public)/sign-in/+page.svelte | 10 +- .../routes/(main)/(public)/sign-up/+page.svelte | 61 +++++--- apps/kit/src/routes/(main)/+layout.ts | 14 +- 12 files changed, 126 insertions(+), 189 deletions(-) delete mode 100644 apps/kit/src/lib/i18n/en/reset-password/index.ts delete mode 100644 apps/kit/src/lib/i18n/en/sign-in/index.ts delete mode 100644 apps/kit/src/lib/i18n/en/sign-up/index.ts diff --git a/apps/kit/src/lib/i18n/en/index.ts b/apps/kit/src/lib/i18n/en/index.ts index 4c1ad04..5a3ccc8 100644 --- a/apps/kit/src/lib/i18n/en/index.ts +++ b/apps/kit/src/lib/i18n/en/index.ts @@ -13,6 +13,14 @@ const en: BaseTranslation = { success: "Success", tryAgainSoon: "Try again soon", unexpectedError: "An unexpected error occured", + requestAPasswordReset: "Request a password reset", + signIntoYourAccount: "sign into your account", + requestSentMessage: "If we find your email address in our systems, you will receive an email with instructions on how to set a new password for your account.", + signIn: "Sign In", + createANewAccount: "create a new account", + notMyComputer: "This is not my computer", + resetPassword: "Reset password", + createYourNewAccount: "Create your new account" }; export default en; diff --git a/apps/kit/src/lib/i18n/en/reset-password/index.ts b/apps/kit/src/lib/i18n/en/reset-password/index.ts deleted file mode 100644 index 00322cf..0000000 --- a/apps/kit/src/lib/i18n/en/reset-password/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -import type { BaseTranslation } from "../../i18n-types" - -const en_reset_password: BaseTranslation = { - requestAPasswordReset: "Request a password reset", - signIntoYourAccount: "sign into your account", - requestSentMessage: "If we find your email address in our systems, you will receive an email with instructions on how to set a new password for your account." -} - -export default en_reset_password \ No newline at end of file diff --git a/apps/kit/src/lib/i18n/en/sign-in/index.ts b/apps/kit/src/lib/i18n/en/sign-in/index.ts deleted file mode 100644 index 3c9c104..0000000 --- a/apps/kit/src/lib/i18n/en/sign-in/index.ts +++ /dev/null @@ -1,10 +0,0 @@ -import type { BaseTranslation } from "../../i18n-types" - -const en_sign_in: BaseTranslation = { - signIn: "Sign In", - createANewAccount: "create a new account", - notMyComputer: "This is not my computer", - resetPassword: "Reset password" -} - -export default en_sign_in \ No newline at end of file diff --git a/apps/kit/src/lib/i18n/en/sign-up/index.ts b/apps/kit/src/lib/i18n/en/sign-up/index.ts deleted file mode 100644 index fa0c3d5..0000000 --- a/apps/kit/src/lib/i18n/en/sign-up/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -import type { BaseTranslation } from "../../i18n-types" - -const en_sign_up: BaseTranslation = { -} - -export default en_sign_up \ No newline at end of file diff --git a/apps/kit/src/lib/i18n/i18n-types.ts b/apps/kit/src/lib/i18n/i18n-types.ts index 5139017..3ace345 100644 --- a/apps/kit/src/lib/i18n/i18n-types.ts +++ b/apps/kit/src/lib/i18n/i18n-types.ts @@ -12,10 +12,7 @@ export type Translation = RootTranslation & DisallowNamespaces export type Translations = RootTranslation & { - app: NamespaceAppTranslation, - 'reset-password': NamespaceResetPasswordTranslation, - 'sign-in': NamespaceSignInTranslation, - 'sign-up': NamespaceSignUpTranslation + app: NamespaceAppTranslation } type RootTranslation = { @@ -27,10 +24,6 @@ type RootTranslation = { * Email address */ emailAddress: string - /** - * Request - */ - request: string /** * Password */ @@ -74,6 +67,38 @@ type RootTranslation = { * An unexpected error occured */ unexpectedError: string + /** + * Request a password reset + */ + requestAPasswordReset: string + /** + * sign into your account + */ + signIntoYourAccount: string + /** + * If we find your email address in our systems, you will receive an email with instructions on how to set a new password for your account. + */ + requestSentMessage: string + /** + * Sign In + */ + signIn: string + /** + * create a new account + */ + createANewAccount: string + /** + * This is not my computer + */ + notMyComputer: string + /** + * Reset password + */ + resetPassword: string + /** + * Create your new account + */ + createYourNewAccount: string } export type NamespaceAppTranslation = { @@ -387,47 +412,8 @@ export type NamespaceAppTranslation = { } } -export type NamespaceResetPasswordTranslation = { - /** - * Request a password reset - */ - requestAPasswordReset: string - /** - * sign into your account - */ - signIntoYourAccount: string - /** - * If we find your email address in our systems, you will receive an email with instructions on how to set a new password for your account. - */ - requestSentMessage: string -} - -export type NamespaceSignInTranslation = { - /** - * Sign In - */ - signIn: string - /** - * create a new account - */ - createANewAccount: string - /** - * This is not my computer - */ - notMyComputer: string - /** - * Reset password - */ - resetPassword: string -} - -export type NamespaceSignUpTranslation = {} - export type Namespaces = | 'app' - | 'reset-password' - | 'sign-in' - | 'sign-up' type DisallowNamespaces = { /** @@ -435,24 +421,6 @@ type DisallowNamespaces = { * you need to use the `./app/index.ts` file instead */ app?: "[typesafe-i18n] reserved for 'app'-namespace. You need to use the `./app/index.ts` file instead." - - /** - * reserved for 'reset-password'-namespace\ - * you need to use the `./reset-password/index.ts` file instead - */ - 'reset-password'?: "[typesafe-i18n] reserved for 'reset-password'-namespace. You need to use the `./reset-password/index.ts` file instead." - - /** - * reserved for 'sign-in'-namespace\ - * you need to use the `./sign-in/index.ts` file instead - */ - 'sign-in'?: "[typesafe-i18n] reserved for 'sign-in'-namespace. You need to use the `./sign-in/index.ts` file instead." - - /** - * reserved for 'sign-up'-namespace\ - * you need to use the `./sign-up/index.ts` file instead - */ - 'sign-up'?: "[typesafe-i18n] reserved for 'sign-up'-namespace. You need to use the `./sign-up/index.ts` file instead." } export type TranslationFunctions = { @@ -464,10 +432,6 @@ export type TranslationFunctions = { * Email address */ emailAddress: () => LocalizedString - /** - * Request - */ - request: () => LocalizedString /** * Password */ @@ -508,6 +472,38 @@ export type TranslationFunctions = { * An unexpected error occured */ unexpectedError: () => LocalizedString + /** + * Request a password reset + */ + requestAPasswordReset: () => LocalizedString + /** + * sign into your account + */ + signIntoYourAccount: () => LocalizedString + /** + * If we find your email address in our systems, you will receive an email with instructions on how to set a new password for your account. + */ + requestSentMessage: () => LocalizedString + /** + * Sign In + */ + signIn: () => LocalizedString + /** + * create a new account + */ + createANewAccount: () => LocalizedString + /** + * This is not my computer + */ + notMyComputer: () => LocalizedString + /** + * Reset password + */ + resetPassword: () => LocalizedString + /** + * Create your new account + */ + createYourNewAccount: () => LocalizedString app: { nav: { /** @@ -814,40 +810,6 @@ export type TranslationFunctions = { timespan: () => LocalizedString } } - 'reset-password': { - /** - * Request a password reset - */ - requestAPasswordReset: () => LocalizedString - /** - * sign into your account - */ - signIntoYourAccount: () => LocalizedString - /** - * If we find your email address in our systems, you will receive an email with instructions on how to set a new password for your account. - */ - requestSentMessage: () => LocalizedString - } - 'sign-in': { - /** - * Sign In - */ - signIn: () => LocalizedString - /** - * create a new account - */ - createANewAccount: () => LocalizedString - /** - * This is not my computer - */ - notMyComputer: () => LocalizedString - /** - * Reset password - */ - resetPassword: () => LocalizedString - } - 'sign-up': { - } } export type Formatters = {} diff --git a/apps/kit/src/lib/i18n/i18n-util.async.ts b/apps/kit/src/lib/i18n/i18n-util.async.ts index a114495..3e8fa1b 100644 --- a/apps/kit/src/lib/i18n/i18n-util.async.ts +++ b/apps/kit/src/lib/i18n/i18n-util.async.ts @@ -11,10 +11,7 @@ const localeTranslationLoaders = { const localeNamespaceLoaders = { en: { - app: () => import('./en/app'), - 'reset-password': () => import('./en/reset-password'), - 'sign-in': () => import('./en/sign-in'), - 'sign-up': () => import('./en/sign-up') + app: () => import('./en/app') } } diff --git a/apps/kit/src/lib/i18n/i18n-util.sync.ts b/apps/kit/src/lib/i18n/i18n-util.sync.ts index 15ae633..8f749c7 100644 --- a/apps/kit/src/lib/i18n/i18n-util.sync.ts +++ b/apps/kit/src/lib/i18n/i18n-util.sync.ts @@ -8,17 +8,11 @@ import { loadedFormatters, loadedLocales, locales } from './i18n-util' import en from './en' import en_app from './en/app' -import en_reset_password from './en/reset-password' -import en_sign_in from './en/sign-in' -import en_sign_up from './en/sign-up' const localeTranslations = { en: { ...en, - app: en_app, - 'reset-password': en_reset_password, - 'sign-in': en_sign_in, - 'sign-up': en_sign_up + app: en_app }, } diff --git a/apps/kit/src/lib/i18n/i18n-util.ts b/apps/kit/src/lib/i18n/i18n-util.ts index c4f5c32..09b0155 100644 --- a/apps/kit/src/lib/i18n/i18n-util.ts +++ b/apps/kit/src/lib/i18n/i18n-util.ts @@ -13,10 +13,7 @@ export const locales: Locales[] = [ ] export const namespaces: Namespaces[] = [ - 'app', - 'reset-password', - 'sign-in', - 'sign-up' + 'app' ] export const isLocale = (locale: string) => locales.includes(locale as Locales) diff --git a/apps/kit/src/routes/(main)/(public)/reset-password/+page.svelte b/apps/kit/src/routes/(main)/(public)/reset-password/+page.svelte index 865be10..9ee4a83 100644 --- a/apps/kit/src/routes/(main)/(public)/reset-password/+page.svelte +++ b/apps/kit/src/routes/(main)/(public)/reset-password/+page.svelte @@ -17,13 +17,16 @@ title: "", } as ErrorResult; + let loading = false; let showSuccessAlert = false; async function submitFormAsync() { errorData.text = ""; errorData.title = ""; showSuccessAlert = false; + loading = true; const request = await create_forgot_password_request(formData.email); + loading = false; if (!request.ok) { errorData.text = request.data.text ?? $LL.tryAgainSoon(); errorData.title = request.data.title ?? $LL.unexpectedError(); @@ -38,12 +41,12 @@

- {$LL["reset-password"].requestAPasswordReset()} + {$LL.requestAPasswordReset()}

- {$LL.or()} + {$LL.or().toLowerCase()} - {$LL["reset-password"].signIntoYourAccount()} + {$LL.signIntoYourAccount()}

@@ -61,7 +64,7 @@ diff --git a/apps/kit/src/routes/(main)/(public)/sign-in/+page.svelte b/apps/kit/src/routes/(main)/(public)/sign-in/+page.svelte index d47f924..16d8c3a 100644 --- a/apps/kit/src/routes/(main)/(public)/sign-in/+page.svelte +++ b/apps/kit/src/routes/(main)/(public)/sign-in/+page.svelte @@ -39,12 +39,12 @@

- {$LL["sign-in"].signIn()} + {$LL.signIn()}

{$LL.or().toLowerCase()} {$LL["sign-in"].createANewAccount()}{$LL.createANewAccount()}

@@ -88,17 +88,17 @@ - + +