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