ترجمہ فنکشن
بعض اوقات آپ کو ایسے مواد کا ترجمہ کرنے کی ضرورت ہوتی ہے جو آپ کے JSX کا حصہ نہیں ہے، مثال کے طور پر Next.js صفحے کا میٹا ڈیٹا میٹاڈا۔ createLocalizedT کے ذریعہ واپس کردہ t() فنکشن کسی بھی تار کا ترجمہ کرتا ہے۔
import type { Metadata } from 'next';import { createLocalizedT } from '@magic-translate/react-ssr';import { translate } from '@/lib/translate';export async function generateMetadata({params}: {params: Promise<{ locale: string }>;}): Promise<Metadata> {const { locale } = await params;const { t } = createLocalizedT(translate, locale);return {title: await t('This page title will be translated'),description: await t('And so will this description')};}
سیٹ اپ سے translate فنکشن کو براہ راست بھی کال کیا جاسکتا ہے۔ یہ ایک زبان، ایک متن اور اختیاری اختیارات لیتا ہے، اور ترجمہ کو حل کرتا ہے۔
import { Language } from '@magic-translate/react-ssr';const translation = await translate(Language.ZH,'This sentence will be translated to Chinese');