શ્રેષ્ઠ પ્રથાઓ
URLs ને વેરિયેબલોમાં મૂકો
URL અથવા સમાન ડેટા ધરાવતા સ્ટ્રિંગ્સનું અનુવાદ કરતી વખતે, આ URL-ઓને વેરિએબલમાં મૂકી તેમને તમારા ટેમ્પ્લેટ્સમાં સંદર્ભિત કરવું શ્રેષ્ઠ પ્રથા માનવામાં આવે છે.
<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 નો ઉપયોગ કરતી વખતે જ કામ કરે છે.
મોટા એપ્લિકેશન્સ પર કામ કરતી વખતે, સ્ટ્રિંગ્સ અને અનુવાદોને અનેક નાના ઓરિજિન્સમાં વિભાજિત કરવું લાભદાયક હોય છે. આ પદ્ધતિ બંડલના કદ અને ટ્રાન્સફર સમય ઘટાડવામાં મદદ કરે છે અને અસરકારક તેમજ સ્કેલેબલ લોકલાઇઝેશન સુનિશ્ચિત કરે છે.
જ્યારે રેન્ડરિંગ ફક્ત ક્લાયન્ટ-સાઇડ પર થાય છે ત્યારે આ સરળ છે, પરંતુ સર્વર-સાઇડ રેન્ડરિંગ માટે અનુવાદો લાવતા સમયે ઓરિજિન્સનું મેનેજમેન્ટ ઝડપથી જટિલ બની શકે છે. તેમ છતાં, તમે 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 વિશે વધુ માહિતી માટે અમારા સર્વર-સાઇડ રેન્ડરિંગ ઉદાહરણો જુઓ.