Open sudojunior opened 3 years ago
This is more so possible with navigator.language
, but should be used with care to make sure the page exists before running that kind of logic. Use of localStorage
as lastLanguage
may also be an option, but heed caution when a decision is made to move deployment provider. (Vercel, Netlify, GH Pages, etc.)
If a page is visited in a specific language, local storage could be used to store the language key itself to be redirected as a failsafe if accessing the root of the site or if the page doesn't exist in the target language, but does in the saved / default language.
May also want to consider the plausibility of using a settings page that would be using local storage to store and retrieve values (would allow the end-user to select a language themselves instead of having to visit the page for said language).