Reactive Translation (i18n) and hardcoded text standards for Smart Recipe Planner.
Smart Recipe Planner supports multiple languages and uses a reactive t object provided by a Zustand store via React Context.
SettingsContext.jsx file rather than hardcoding it in the component.useSettings hook to load translations.SettingsContext.jsx immediately.context/SettingsContext.jsx.S object).es (Spanish), en (English), and fr (French), add the new translation key logically grouped (e.g., inside common, auth, feed, settings, etc.).import { useSettings } from '@context/SettingsContext';
export function ExampleComponent() {
const { t } = useSettings();
// GOOD: Reactive and safe fallback
return (
<button>{t.common?.save || 'Guardar'}</button>
);
// BAD: Hardcoded text
// return <button>Guardar</button>;
}
Astro files .astro run on the server and do not directly subscribe to the client-side Zustand store.
If an Astro page must display reactive translation strings (e.g., the 404 page or Policy pages), extract the translated elements into a React Client Component ("use client") and inject it into the Astro page using the client:load directive.
---
import { TranslatedComponent } from '@components/TranslatedComponent';
---
<!-- Ensure it runs reactively on the client -->
<TranslatedComponent client:load />
Toast notifications must also be translated:
import { useSettings } from '@context/SettingsContext';
import { useToast } from '@context/ToastContext';
export function useExampleHook() {
const { t } = useSettings();
const { showToast } = useToast();
const doAction = () => {
showToast(t.common?.success || 'Operación exitosa', 'success');
};
}
Edit PDFs with natural-language instructions using the nano-pdf CLI.