import en from "@/locales/en.json";
import vi from "@/locales/vi.json";
import { getLocales } from "expo-localization";
import { I18n } from "i18n-js";

// Set the key-value pairs for the different languages you want to support
const translations = {
  en,
  vi,
};

const i18n = new I18n(translations);

// Set the locale once at the beginning of your app
// This will be set from storage in the useI18n hook, default to device language or 'en'
i18n.locale = getLocales()[0].languageCode ?? "vi";

// Enable fallback mechanism - if a key is missing in the current language, it will use the key from English
i18n.enableFallback = true;

// Set default locale to English if no locale is available
i18n.defaultLocale = "vi";

// Storage key for locale preference
export const LOCALE_STORAGE_KEY = "app_locale_preference";

export default i18n;
