ال useT hook
تحتاج أحيانًا إلى ترجمة شيء آخر غير محتوى HTML العادي. لهذا الغرض، تقدم Magic Translate useT hook. يمكنك استخدامه، على سبيل المثال، لترجمة props.
import { useT } from '@magic-translate/react';const MyComponent = () => {const t = useT();return (<button aria-label={t('Main menu')}><HamburgerIcon /></button>);};
يمكنك استخدام وظيفة t() في أي مكان داخل المكون الخاص بك. يمكنك أيضًا استخدامه في الترميز بدلاً من المكون <T> إذا كنت تفضل ذلك.
const MyComponent = () => {const t = useT();return <p>{t('This will be translated')}</p>;};
خيارات
يمكنك تمرير نفس الخيارات إلى t() بالنسبة لمكون <T>، على سبيل المثال formality.
const MyComponent = () => {const t = useT();return <button>{t('Please click here', { formality: 'formal' })}</button>;};