Super Sale Limited Time 50% OFF for All-Access Plans
Save 50% Now

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
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • 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
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(