શ્રેષ્ઠ પ્રથાઓ
URLને ચલVariablesમાં મૂકો
જ્યારે 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"
/>
આ બાબતમાં કંઈક ખૂબ જ મેટા અનુભવાય છે.
ગ્લોબલ ઓરિજિન્સ એરે અને πολλIPLE COMPONENT ઓરિજિન્સ
આ નમૂનો ફક્ત 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
વિશે.