I have the following piece of code (+layout.svelte):
import { getLang } from "$lib/locale";
import { browser } from "$app/environment";
const loadLang = async () => {
if (browser) {
// return await getLang(document.documentElement.lang, "home").then( function (data: any) {
// const nav = JSON.stringify(data.nav);
// console.log(nav)
// return nav;
// });
const initLocale= await getLang(document.documentElement.lang, "home");
return initLocale.json();
}
};
const a = loadLang();
console.log(a);
What this snippet does is detect the browser language, the route requested and then searches for the correct JSON file corresponding to the language and the page. But there is a problem, I am unable access the language data of the async loadLang()
to use it in the component's HTML elements and there is no way for me to actually do that other than what many answers here stated (which is not what i'm looking for), What I want is a way to access the returned value of the aforementioned function and use it in the HTML elements?