TGRHavoc / live_map-interface

Web interface for the FiveM live_map addon
https://docs.tgrhavoc.co.uk/livemap-interface/
53 stars 30 forks source link

Language not being persisted #86

Closed TGRHavoc closed 3 years ago

TGRHavoc commented 3 years ago

Describe the bug Local storage key "lang" not being respected

To Reproduce Steps to reproduce the behavior:

  1. Open webpage
  2. Select a language
  3. Lang is set in localstorage
  4. Refresh page
  5. lang is reset back to "en"

Expected behavior The lang's value in localstorage should be respected so that users who have changed the language doesn't have to change the language every time the page is refreshed.

Screenshots 52d6737ed26b4fb061287f2c1312af6d297bd1b8aac7fd1fd752e51b8abf

Possible Solution Move the following code:

        if (!this.manifest[this._lang]) { // The user's language isn't in the manifest... Just fall back to English
            this._lang = "en";
        }

        //this.setLanguage(this._lang);
        localStorage.setItem("lang", this._lang);
        this.toggleLangTag();

into the fetch block

        fetch("translations/manifest.json").then(async resp => {
            let j = await resp.json();
            _.manifest = j;

            _.putLanguagesIntoNavbar(j);

This should ensure that the manifest exists and so does the languages.

Maybe actually call the getLanguage function..