Get 2024 Templates Mega Bundle!14 Bootstrap, Vue & React Templates + 3 Vector Sets
Get for 99$

Language selector: when reload it selects other language


When i pick a language in the language selector in Demo 1 Metronic 8 project, it sets the language correct, in my case to 'dk', and when it reloads the page it is set to 'en' again as it was before. The language is stored in localstorage. I set the new language as the localstorage value before reload, but at every reload it resets it to 'en'.

Is there anybody who can help?

(This is the first time i post a question on a support group, so please ask for more information if needed)


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (3)


Hi,

Hard to help you with this, the main setup works fine (https://preview.keenthemes.com/metronic8/react/demo1/dashboard.
Try to debug the place: 'how it's reading the initial language' (first, it should get from localStorage, if it's here). Maybe you have different localStorage keys for 'read/write' the language.

Regards,
Keenthemes support



Hello,

It is really wierd, but i changed the i18Config key name, so now there are two keys in my localstorage but i'm only looking at the new one. This fixed the functionality. I'm still not sure where the original key is set though.
Thanks for a quick response.

Regards
Mia



Hi,

Check the src/app/modules/i18n/translation.service.ts you will see the const LOCALIZATION_LOCAL_STORAGE_KEY.
If the localStorage with this key is empty it returns the default language ('en').
If you want to deep dive into the localization theme, check the library documentation: https://github.com/ngx-translate/core, it's well documented and good configurable.

Regards,
Keenthemes support


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(