import { usePage } from '@inertiajs/react';

export default function useTranslation() {
    const { translations } = usePage().props;

    /**
     * Translate a key.
     * @param {string} key - The key in the JSON file (e.g. "_hello")
     * @param {string} defaultText - Fallback text if key not found (e.g. "Hello")
     */
    const t = (key, defaultText = '') => {
        return translations[key] || defaultText || key;
    };

    return { t };
}