import { register, init, getLocaleFromNavigator, locale } from "svelte-i18n";

function setupI18n() {
  register("en", () => import("../locales/en.js"));
  register("de", () => import("../locales/de.js"));

  init({
    fallbackLocale: "de",
    initialLocale: getLocaleFromNavigator(),
  });
}

setupI18n();

/**
 * @param {string} newLocale - The new locale to set
 */
export const changeLocale = (newLocale) => {
  locale.set(newLocale);
};
