Skip to content

fix: persist user's locale#527

Merged
danielroe merged 3 commits intonpmx-dev:mainfrom
DDeenis:fix/locale-persistence
Feb 1, 2026
Merged

fix: persist user's locale#527
danielroe merged 3 commits intonpmx-dev:mainfrom
DDeenis:fix/locale-persistence

Conversation

@DDeenis
Copy link
Copy Markdown
Contributor

@DDeenis DDeenis commented Jan 31, 2026

Resolves #509

Haven't worked with @nuxt/i18n before, feedback welcome 🙏

@vercel
Copy link
Copy Markdown

vercel Bot commented Jan 31, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
npmx.dev Ready Ready Preview, Comment Jan 31, 2026 7:32pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
npmx-lunaria Ignored Ignored Jan 31, 2026 7:32pm
docs.npmx.dev Skipped Skipped Jan 31, 2026 7:32pm

Request Review

Comment thread nuxt.config.ts Outdated
strategy: 'no_prefix',
detectBrowserLanguage: false,
detectBrowserLanguage: {
useCookie: true,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the app generally seems to utilise localStorage to persist user settings, it could be an idea to store the currently selected lang in useSettings alongside it instead of using cookies? That would allow for using the settings object to get the language in the app, whenever it's needed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's try that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my first thought, but after reading docs and asking AI I decided to go with the cookie solution because:

  1. Cookies are available server-side (attached to requests). Thought it was important, since the app uses SSR.
  2. This is the built-in persistence method, so I guess it's encouraged?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't you have hydration issues using localstorage?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useLocalStorage I think only hydrates itself after mounted, meaning there shouldn't be a hydration mismatch

cookie is worse because we actually statically render much of the site, so we can't SSR based on a user's cookie

Copy link
Copy Markdown
Contributor

@wojtekmaj wojtekmaj Jan 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least having locale in a cookie would allow us to maybe, one day, fix that and SSR the correct locale. Why close the doors that could stay open 🤷🏻‍♂️

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tbh considering that setting up cookie-based persistence is just a matter of changing the config, it shouldn't be too hard to switch between localStorage and cookies. If the localStorage is the best option at this time, and we can tolerate the one time language settings reset in case of switching to cookies, I'm happy to go with the localStorage.

Copy link
Copy Markdown
Member

@danielroe danielroe Jan 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wojtekmaj even so, I have a plan to fix the rendering of a SSG site... I just need to create the PR...

thanks @DDeenis - let's do localStorage for now

@vercel vercel Bot temporarily deployed to Preview – docs.npmx.dev January 31, 2026 19:30 Inactive
@DDeenis
Copy link
Copy Markdown
Contributor Author

DDeenis commented Jan 31, 2026

Updated to use settings (localStorage) instead of cookies.
Used plugin to cleanly separate this functionality from the rest of the code. Would be happy to receive a code review!

@DDeenis DDeenis changed the title fix: persist user's locale in a cookie fix: persist user's locale Jan 31, 2026
Copy link
Copy Markdown
Contributor

@wojtekmaj wojtekmaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me

@danielroe danielroe enabled auto-merge February 1, 2026 00:28
@danielroe danielroe added this pull request to the merge queue Feb 1, 2026
Merged via the queue into npmx-dev:main with commit 700cf22 Feb 1, 2026
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Language selection doesn't persist after refresh

5 participants