api strings

This commit is contained in:
tresabhi committed 2026-09-22 16:38:30 -05:00
1 parent 99317c2075
commit 5f24887535
23 files changed
+132 -118

No files matched your search

+3 -11
View File
@@ -1,11 +1,8 @@
import { unwrapper } from "@blitzkit/i18n";
import locales from "@blitzkit/i18n/locales.json";
import { createContext, useContext, type ReactNode } from "react";
import { getStrings } from "../core/i18n/getStrings";
const LocaleContext = createContext<{
locale: string;
localeRaw: string | undefined;
} | null>(null);
interface LocaleProviderProps extends LocaleAcceptorProps {
@@ -14,9 +11,7 @@ interface LocaleProviderProps extends LocaleAcceptorProps {
export function LocaleProvider({ locale, children }: LocaleProviderProps) {
return (
<LocaleContext.Provider
value={{ locale: locale ?? locales.default, localeRaw: locale }}
>
<LocaleContext.Provider value={{ locale: locale ?? locales.default }}>
{children}
</LocaleContext.Provider>
);
@@ -29,12 +24,9 @@ export function useLocale() {
throw new Error("useLocale must be used within a LocaleProvider");
}
const strings = getStrings(context.locale);
const unwrap = unwrapper(context.locale);
return { locale: context.locale, strings, unwrap };
return context.locale;
}
export interface LocaleAcceptorProps {
locale: string | undefined;
locale: string;
}
+9
View File
@@ -0,0 +1,9 @@
import { api } from "../blitzkit/api";
import { useAwait } from "./useAwait";
import { useLocale } from "./useLocale";
export function useStrings() {
const locale = useLocale();
const strings = useAwait(() => api.strings(locale), `strings-${locale}`);
return strings;
}