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