From 2deb3064196b74cd7f4ad27690d1effc722b979a Mon Sep 17 00:00:00 2001 From: Admin Date: Mon, 30 Mar 2026 19:05:14 +0500 Subject: [PATCH] =?UTF-8?q?fix(i18n+settings):=20rename=20pt-BR=E2=86=92pt?= =?UTF-8?q?,=20fix=20theme/locale=20persistence?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Root cause: user_settings table was missing theme, locale, font_family, font_size columns — PocketBase silently dropped them on every save. Added the four columns via PocketBase API. Also: - listOne now sorts by -updated so the most-recent settings record wins - PARAGLIDE_LOCALE cookie is now cleared when switching back to English - pt-BR renamed to pt throughout (messages, inlang settings, validLocales) Co-Authored-By: Claude Sonnet 4.6 --- ui/messages/{pt-BR.json => pt.json} | 0 ui/project.inlang/settings.json | 2 +- ui/src/hooks.server.ts | 2 +- ui/src/lib/server/pocketbase.ts | 4 ++-- ui/src/routes/+layout.server.ts | 25 ++++++++++++++----------- ui/src/routes/api/settings/+server.ts | 2 +- 6 files changed, 19 insertions(+), 16 deletions(-) rename ui/messages/{pt-BR.json => pt.json} (100%) diff --git a/ui/messages/pt-BR.json b/ui/messages/pt.json similarity index 100% rename from ui/messages/pt-BR.json rename to ui/messages/pt.json diff --git a/ui/project.inlang/settings.json b/ui/project.inlang/settings.json index e79a8d1..b64fca7 100644 --- a/ui/project.inlang/settings.json +++ b/ui/project.inlang/settings.json @@ -1,7 +1,7 @@ { "$schema": "https://inlang.com/schema/project-settings", "baseLocale": "en", - "locales": ["en", "ru", "id", "pt-BR", "fr"], + "locales": ["en", "ru", "id", "pt", "fr"], "modules": [ "https://cdn.jsdelivr.net/npm/@inlang/plugin-message-format/dist/index.js" ], diff --git a/ui/src/hooks.server.ts b/ui/src/hooks.server.ts index 38999a1..8885353 100644 --- a/ui/src/hooks.server.ts +++ b/ui/src/hooks.server.ts @@ -141,7 +141,7 @@ export function parseAuthToken(token: string): { id: string; username: string; r // ─── Hook ───────────────────────────────────────────────────────────────────── function getTextDirection(locale: string): string { - // All supported locales (en, ru, id, pt-BR, fr) are LTR + // All supported locales (en, ru, id, pt, fr) are LTR return 'ltr'; } diff --git a/ui/src/lib/server/pocketbase.ts b/ui/src/lib/server/pocketbase.ts index 403305c..ed59e88 100644 --- a/ui/src/lib/server/pocketbase.ts +++ b/ui/src/lib/server/pocketbase.ts @@ -197,8 +197,8 @@ async function countCollection(collection: string, filter = ''): Promise return (data as { totalItems: number }).totalItems ?? 0; } -async function listOne(collection: string, filter: string): Promise { - const params = new URLSearchParams({ perPage: '1', filter }); +async function listOne(collection: string, filter: string, sort = '-updated'): Promise { + const params = new URLSearchParams({ perPage: '1', filter, sort }); const data = await pbGet>( `/api/collections/${collection}/records?${params.toString()}` ); diff --git a/ui/src/routes/+layout.server.ts b/ui/src/routes/+layout.server.ts index df26747..d08b713 100644 --- a/ui/src/routes/+layout.server.ts +++ b/ui/src/routes/+layout.server.ts @@ -35,20 +35,23 @@ export const load: LayoutServerLoad = async ({ locals, url, cookies }) => { log.warn('layout', 'failed to load settings', { err: String(e) }); } - // If user is logged in and has a non-English locale saved, ensure the - // PARAGLIDE_LOCALE cookie is set so the locale persists after refresh. + // If user is logged in, keep the PARAGLIDE_LOCALE cookie in sync with + // the saved locale so it persists across page loads and navigations. if (locals.user) { const savedLocale = settings.locale ?? 'en'; - if (savedLocale !== 'en') { - const currentCookieLocale = cookies.get('PARAGLIDE_LOCALE'); - if (currentCookieLocale !== savedLocale) { - cookies.set('PARAGLIDE_LOCALE', savedLocale, { - path: '/', - maxAge: 34560000, - sameSite: 'lax', - httpOnly: false - }); + const currentCookieLocale = cookies.get('PARAGLIDE_LOCALE'); + if (savedLocale === 'en') { + // Clear the cookie when the user's locale is English (the default) + if (currentCookieLocale) { + cookies.delete('PARAGLIDE_LOCALE', { path: '/' }); } + } else if (currentCookieLocale !== savedLocale) { + cookies.set('PARAGLIDE_LOCALE', savedLocale, { + path: '/', + maxAge: 34560000, + sameSite: 'lax', + httpOnly: false + }); } } diff --git a/ui/src/routes/api/settings/+server.ts b/ui/src/routes/api/settings/+server.ts index 6f9e747..bdafdbd 100644 --- a/ui/src/routes/api/settings/+server.ts +++ b/ui/src/routes/api/settings/+server.ts @@ -50,7 +50,7 @@ export const PUT: RequestHandler = async ({ request, locals }) => { } // locale is optional — if provided it must be a known value - const validLocales = ['en', 'ru', 'id', 'pt-BR', 'fr']; + const validLocales = ['en', 'ru', 'id', 'pt', 'fr']; if (body.locale !== undefined && !validLocales.includes(body.locale)) { error(400, `Invalid locale — must be one of: ${validLocales.join(', ')}`); }