martinkr/next-export-i18n

Keep current lang value in the local storage or cookies instead of query param

cyntler opened this issue · 12 comments

Like in the title of this issue. Is it possible?

Hey,

The GET-Param is not the prettiest solution, I agree.
If we keep the language only in storage/cookie, we loose the ability to link into a specific language (sharing etc).
I was thinking how to solve, but I don't have a final solution yet.

Do you have any ideas?

Cheers!

Hey @martinkr, I see.

So here my first, initial idea is to use query param but only we want to use a link to some language.
What does it mean?

  1. When the user enters the page, we check if there is a key in query params with the name of one of the languages we have in i18n.translations:
    • If so, we save the currentLang cookie with the value of this language.
    • If not, we save the currentLang cookie with the value of defaultLang, but only if thecurrentLangcookie does not exist yet.
  2. All of hooks and components read the current lang from cookie.
  3. LanguageSwitcher updates the value in the cookie.
  4. The component doesn't need to use query.

Additionaly, the next thing to change in my opinion is changing the lang query param to a new form.
Instead of ?lang=en or ?lang=pl we can only use something like ?en or ?pl.

What do you think?
Then we will be able to close issue #10 also.

Really Appreciate your thoughts!
The outgoing links I'm mostly concerned with, someone copying from the address bar or opening in a new window (should be not a problem with the cookie) ... going to think about this tomorrow, it's late and I need to finish some papers :D

Hello!
I've created a tiny package that you might want to check.
@m0-0a/next-intl
@martinkr @cyntler
I preferred to create a separate package in case you don't like my implementation check source code, it might be something you would like to implement in this package.
Best regards.

Hi,
sounds interesting, can you post the link to the source code?
Cheers!

Sorry, I forgot to provide repo link.
https://github.com/m0-0a/next-intl

Hi, sounds interesting, can you post the link to the source code? Cheers!

Hi @martinkr !
Could you check the source code ?

@martinkr I was looking for a solution where language will be picked from preference instead of query param.
So basically, this lib is not capable of this.

@martinkr I was looking for a solution where language will be picked from preference instead of query param.
So basically, this lib is not capable of this.

Check this:
https://www.npmjs.com/package/@m0-0a/next-intl

Available since 2.3.0