From cf7fdf198d61388ca7a43156a64f5017490084aa Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 21 Apr 2022 14:57:52 +0200 Subject: [PATCH] fix: locales --- src/hooks.ts | 15 +------- src/lib/locales/en.json | 1 + src/lib/translations.ts | 3 +- src/routes/__layout.svelte | 57 ++++++++++++++-------------- src/routes/iam/index.svelte | 15 ++++++++ src/routes/new/team/index.svelte | 4 +- src/routes/settings/_Language.svelte | 22 +++++++++++ src/routes/settings/index.json.ts | 2 +- src/routes/settings/index.svelte | 9 +++++ 9 files changed, 81 insertions(+), 47 deletions(-) create mode 100644 src/routes/settings/_Language.svelte diff --git a/src/hooks.ts b/src/hooks.ts index 33774922a..50624b22f 100644 --- a/src/hooks.ts +++ b/src/hooks.ts @@ -48,8 +48,7 @@ export const handle = handleSession( teamId, permission, isAdmin: permission === 'admin' || permission === 'owner', - expires: event.locals.session.data.expires, - lang: locale + expires: event.locals.session.data.expires }; if (JSON.stringify(event.locals.session.data) !== JSON.stringify(newSession)) { @@ -105,18 +104,8 @@ export const handle = handleSession( ); export const getSession: GetSession = function ({ locals }) { - // Get defined locales - const supportedLocales = locales.get(); - let locale; - - if (locals.cookies) { - locale = supportedLocales.find( - (l) => `${l}`.toLowerCase() === `${locals.cookies['lang']}`.toLowerCase() - ); - } - return { - lang: locale, + lang: locals.cookies.lang, version, whiteLabeled, whiteLabelDetails, diff --git a/src/lib/locales/en.json b/src/lib/locales/en.json index 20baecc8a..dc98ab2c3 100644 --- a/src/lib/locales/en.json +++ b/src/lib/locales/en.json @@ -294,6 +294,7 @@ "no_service": "No services found" }, "setting": { + "change_language": "Change Language", "permission_denied": "You do not have permission to do this. \\nAsk an admin to modify your permissions.", "domain_removed": "Domain removed", "ssl_explainer": "If you specify https, Coolify will be accessible only over https. SSL certificate will be generated for you.
If you specify www, Coolify will be redirected (302) from non-www and vice versa.", diff --git a/src/lib/translations.ts b/src/lib/translations.ts index dcda99dcb..3ead4e1ec 100644 --- a/src/lib/translations.ts +++ b/src/lib/translations.ts @@ -22,5 +22,4 @@ export const config = { ] }; -export const { t, loading, locales, locale, loadTranslations } = new i18n(config); -loading.subscribe(($loading) => $loading && console.log('Loading translations...')); +export const { t, locales, locale, loadTranslations } = new i18n(config); diff --git a/src/routes/__layout.svelte b/src/routes/__layout.svelte index 910cb765e..8fdcdb273 100644 --- a/src/routes/__layout.svelte +++ b/src/routes/__layout.svelte @@ -4,8 +4,10 @@ import { locale, loadTranslations } from '$lib/translations'; export const load: Load = async ({ fetch, url, session }) => { const { pathname } = url; + const defaultLocale = 'en'; - const initLocale = locale.get() || defaultLocale; + const sessionLocale = session.lang; + const initLocale = sessionLocale || locale.get() || defaultLocale; await loadTranslations(initLocale, pathname); if (!session.userId && !publicPaths.includes(url.pathname)) { @@ -44,7 +46,7 @@ import { asyncSleep } from '$lib/components/common'; import { del, get, post } from '$lib/api'; import { browser, dev } from '$app/env'; - + import Select from 'svelte-select'; let isUpdateAvailable = false; let updateStatus = { @@ -461,34 +463,31 @@ - - {#if $session.teamId === '0'} - + - - - - - - - {/if} + + + + +
Identity and Access Management
+ + +
{#if invitations.length > 0} diff --git a/src/routes/new/team/index.svelte b/src/routes/new/team/index.svelte index 75c75ced2..aadf35d65 100644 --- a/src/routes/new/team/index.svelte +++ b/src/routes/new/team/index.svelte @@ -34,7 +34,7 @@ if (name) { try { const { id } = await post('/new/team.json', { name }); - return await goto(`/teams/${id}`); + return await goto(`/iam/team/${id}`); } catch ({ error }) { return errorNotification(error); } @@ -50,7 +50,7 @@
- +
diff --git a/src/routes/settings/_Language.svelte b/src/routes/settings/_Language.svelte new file mode 100644 index 000000000..566e9c1d1 --- /dev/null +++ b/src/routes/settings/_Language.svelte @@ -0,0 +1,22 @@ + + +
+
+
+ {$t('setting.change_language')} +
+
+
+ {#each Object.entries(langs) as [lang, name]} + + {/each} +
+
diff --git a/src/routes/settings/index.json.ts b/src/routes/settings/index.json.ts index 7adf5431b..2f15c5066 100644 --- a/src/routes/settings/index.json.ts +++ b/src/routes/settings/index.json.ts @@ -8,7 +8,7 @@ import { promises as dns } from 'dns'; export const get: RequestHandler = async (event) => { const { teamId, status, body } = await getUserDetails(event); if (status === 401) return { status, body }; - if (teamId !== '0') return { status: 401, body: { message: 'You are not an admin.' } }; + if (teamId !== '0') return { status: 200, body: { settings: {} } }; try { const settings = await listSettings(); return { diff --git a/src/routes/settings/index.svelte b/src/routes/settings/index.svelte index ca5f645d3..53606aced 100644 --- a/src/routes/settings/index.svelte +++ b/src/routes/settings/index.svelte @@ -28,6 +28,8 @@ import { session } from '$app/stores'; export let settings; + import Cookies from 'js-cookie'; + import langs from '$lib/lang.json'; import Setting from '$lib/components/Setting.svelte'; import Explainer from '$lib/components/Explainer.svelte'; import { errorNotification } from '$lib/form'; @@ -38,6 +40,8 @@ import { toast } from '@zerodevx/svelte-toast'; import { t } from '$lib/translations'; + import Language from './_Language.svelte'; + let isRegistrationEnabled = settings.isRegistrationEnabled; let dualCerts = settings.dualCerts; @@ -125,6 +129,7 @@ {/if}
+
@@ -226,4 +231,8 @@
+{:else} +
+ +
{/if}