ఉత్తమ ఆచారాలు
URLలను వేరియబుల్లలో పెట్టండి
URLs లేదా ఇలాంటి డేటా కలిగిన స్ట్రింగ్స్ అనువదించే సమయంలో, ఈ URLs ని వేరియబుల్స్ లో ఉంచి, తర్వాత వాటిని మీ టెంప్లేట్స్ లో సూచించడం మంచి పద్ధతి గా భావించబడుతుంది.
<Translate
string={`Click <a href="{{url}}">here</a>`}
variables={{url: 'https://tacotranslate.com'}}
/>
ARIA లేబుళ్లు ఉపయోగించండి
ఇంటరాక్టివ్ ఎలిమెంట్స్ వంటి బటన్ల టেক্স్ట్ను అనువదించేటప్పుడు, సంక్రమణతకు ఇస్తుందని నిర్ధారించడానికి ARIA లేబుల్స్ను చేర్పడం అవసరం. ARIA లేబుల్స్ స్క్రీన్ రీడర్లకు ఆ ఎలిమెంట్ యొక్క ఫంక్షన్ గురించి వివరణాత్మక సమాచారం అందించడంలో సహాయపడతాయి.
ఉదాహరణకు, మీకు కోడ్ బ్లాక్ నుంచి టెక్స్ట్ కాపీ చేయించే ఒక బటన్ ఉంటే, మీరు aria-label
గుణాన్ని ఉపయోగించి స్పష్టమైన వివరణ ఇవ్వవచ్చు:
<Translate
aria-label={useTranslation('Copy to clipboard')}
string="Copy"
/>
ఇదిలో ఏదో ఒకటి చాలా మెటా అనిపిస్తోంది.
గ్లోబల్ మూలాలు అర్యే మరియు బహుళ భాగం మూలాలు
ఈ నమూనా Next.js Pages Router ఉపయోగించే సమయంలో మాత్రమే పనిచేస్తుంది.
పెద్ద అప్లికేషన్లతో పని చేయినప్పుడు, స్ట్రింగ్స్ మరియు అనువాదాలను బహుళ, చిన్న origins గా విభజించడం ఉపయోగకరం. ఈ విధానం బండిల్ పరిమాణాలు మరియు ట్రాన్స్ఫర్ సమయాలను తగ్గిస్తుంది, సమర్థవంతమైన మరియు వ్యాప్తి చెందగల స్థానీకరణను నిర్ధారిస్తుంది.
క్లయింట్ వైపు మాత్రమే రూపొందించేప్పుడు ఇది సులభమే అయినప్పటికీ, సర్వర్-సైడ్ రెండరింగ్ కోసం అనువాదాలను పొందేటప్పుడు origins నిర్వహణ త్వరితంగా క్లిష్టమవుతుంది. అయితే, TacoTranslate క్లయింట్ origins
అర్రేను ఉపయోగించి మీరు origins నిర్వహణను ఆటోమేటిక్గా చేయవచ్చు.
మా కాంపోనెంట్స్ మరియు పేజీలను వేర్వేరు ఫైల్లుగా విడగొట్టిన ఈ ఉదాహరణను పరిశీలించండి.
import TacoTranslate, {Translate} from 'tacotranslate/react';
import tacoTranslate from '../tacotranslate-client';
// Set an origin name for this component
const origin = 'components/pricing-table';
// Push the origin into the origins array as this file is imported
tacoTranslate.origins.push(origin);
export default function PricingTable() {
return (
<TacoTranslate origin={origin}>
<Translate string="Pricing table" />
// ...
</TacoTranslate>
);
}
import TacoTranslate, {Translate} from 'tacotranslate/react';
import getTacoTranslateStaticProps from 'tacotranslate/next/get-static-props';
import tacoTranslateClient from '../tacotranslate-client';
import PricingTable from '../components/pricing-table';
const origin = 'pages/pricing';
tacoTranslateClient.origins.push(origin);
export default function PricingPage() {
return (
<TacoTranslate origin={origin}>
<Translate string="Pricing page" />
<PricingTable />
</TacoTranslate>
);
}
// We will now fetch translations for all imported components and their origins automatically
export async function getStaticProps(context) {
return getTacoTranslateStaticProps(context, {client: tacoTranslateClient});
}
మరింత సమాచారం కోసం మా సర్వర్-సైడ్ రేండరింగ్ ఉదాహరణలుని చూడండి getTacoTranslateStaticProps
.