how to set default lng in i18next but it needs await and i am getting Exception

24 Views Asked by At

I am using react native expo router everything was great until i decided to get the language i saved in AsyncStorage which needs await to get the value but i am getting the exception saying exception in HostFunction: Compiling JS failed: 44:16:'}' expected at end of object literal '{...' Buffer size 2579 starts with: 5f5f642866756e6374696f6e2028676c and has protection mode(s): rw-p]

my code is here:

import { mainJsonEn } from "./translations/en.js";
import { mainJsonAr } from "./translations/ar.js";

import { initReactI18next } from "react-i18next";
import i18next from "i18next";
import { getLocales, getCalendars } from "expo-localization";
import AsyncStorage from "@react-native-async-storage/async-storage";



const resources = {
  en: {
    translation: mainJsonEn,
  },
  ar: {
    translation: mainJsonAr,
  },
};

const getLang = async () => {
  const selectedLang = await AsyncStorage.getItem("lng");
  if (selectedLang) {
    return selectedLang;
  } else {
    const locals = getLocales();
    if (locals == "ar" || locals == "en") {
      return locals;
    } else {
      return "ar";
    }
  }
};

i18next.use(initReactI18next).init({
  debug: false,
  lng: await getLang(), // Set the default language
  fallbackLng: "ar", // Use the default language if the translation is missing
  compatibilityJSON: "v3",
  resources,
});



export default i18next;

i tried putting it above it and call it as a normal variable but it didnt work too with same error

0

There are 0 best solutions below