Develop ultra fast with Prismane 🎉

useLocalization

useLocalization hook provides a simple way to handle localization and dynamic translation.

Import

import { useLocalization } from "@prismane/core/hooks";

Usage

function Demo() {
  const [registered, setRegistered] = useState(false);

  const { locale, text, changeLocale } = useLocalization("en", {
    en: "Hello from Bulgaria!",
    de: "Hallo aus Bulgarien!",
  });

  return (
    <Flex direction="column" gap={fr(2)}>
      <Text
        cl={(theme) => (theme.mode === "dark" ? ["base", 200] : ["base", 700])}
      >
        Locale: {locale}
      </Text>
      <Text
        cl={(theme) => (theme.mode === "dark" ? ["base", 200] : ["base", 700])}
      >
        {text}
      </Text>
      <Button onClick={() => changeLocale("de")}>Change Locale</Button>
    </Flex>
  );
}

API

Parameters

NameTypeDescriptionDefault
defaultLocalestringThe default locale.-
translationsanyThe translations object with all of the translated texts.-

Return Value

NameTypeDescription
localestringThe current locale.
textanyThe translated text or texts.
changeLocale() => voidFunction that changes the locale to a different one.