//===========================================
// THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY UNLESS YOU ALSO EDIT THE CORRESPONDING FILE IN packages/template
//===========================================
import React from "react";
import { TranslationContext } from "../providers/translation-provider-client";
export function useTranslation() {
const translationContext = React.useContext(TranslationContext);
if (!translationContext) {
throw new Error("Translation context not found; did you forget to wrap your app in a ?");
}
return {
t: (str: string, templateVars?: Record) => {
const { quetzalKeys, quetzalLocale } = translationContext;
let translation = quetzalLocale.get(quetzalKeys.get(str) ?? (undefined as never)) ?? str;
for (const [key, value] of Object.entries(templateVars || {})) {
translation = translation.replace(`{${key}}`, value);
}
return translation;
},
};
}