Direct API Call:
// Translate single text
const response = await fetch('/api/translate', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
text: 'Hello world',
targetLanguage: 'ar',
sourceLanguage: 'en'
})
});
const result = await response.json();
console.log(result.result); // Translated textUsing the Hook:
// In your component
const { translateText, isLoading } = useTranslation();
const handleTranslate = async () => {
const translated = await translateText('Hello world');
console.log(translated);
};Using the Component:
// Automatic translation based on locale
<TranslatedContent content="Your text here" />