சிறந்த நடைமுறைகள்
URL-களை மாறிலிகளில் வைக்கவும்
URL-கள் அல்லது அதுபோன்ற தரவுகளை கொண்ட ஸ்ட்ரிங்களை மொழிபெயர்க்கும் போது, அந்த URL-களை மாறிகளாக (variables) வைக்கி, பின்னர் உங்கள் டெம்ப்ளேட்டுகளில் அவற்றைக் குறிப்புசெய்வது ஒரு நல்ல நடைமுறை.
<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 ஐப் பயன்படுத்தும்போது மட்டுமே செயல்படும்.
பெரிய பயன்பாடுகளுடன் பணியாற்றும்போது, string-களையும் மொழிபெயர்ப்புகளையும் பல சிறிய மூலங்களாக பிரிப்பது பயனுள்ளதாக இருக்கும். இந்த அணுகுமுறை பண்டில் அளவுகளையும் பரிமாற்ற நேரங்களையும் குறைத்து, திறமையான மற்றும் விரிவாக்கக்கூடிய உள்ளூராக்கத்தை (localization) உறுதி செய்கிறது.
இது கிளையன்ட் பக்கத்தில் மட்டும் ரெண்டர் செய்யும் போது எளிமையாக இருக்கும்; ஆனாலும், சர்வர்-பக்கம் ரெண்டரிங்கிற்காக மொழிபெயர்ப்புகளை பெறும்போது மூலங்களை நிர்வகிப்பது விரைவில் சிக்கலாகிவிடும். எனினும், TacoTranslate கிளையன்ட் 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
.