#Scoped localization-agnostic cookies?

1 messages · Page 1 of 1 (latest)

signal bison
#

I am using a path parameter to get the user locale, and I did not anticipate that it would prevent me from setting cookies scoped to a specific path, while enabling the user to change their locale.

I am using cookies for speed and ease of use when storing user preferences related to forms in specific routes (for example pre-selecting options based of the latest choice made by the user). The user may want to change locale to visualize localized content in context when making changes.

It is easy enough to set multiple cookies, one per possible locale, and the payload is not that big but it adds up, especially with the options (Expires, SameSite, Secure, HttpOnly), and it sounds a bit hacky.

Is there a better way that would be comparably easy to implement?

lean bane
#

I think you can

  1. Set one cookie per locale as you said
  2. Allow cookies to work on every path (set path to /)
  3. Remove the locale from the URL (you can store the locale in a cookie, your DB, etc.)