മികച്ച പ്രവർത്തനരീതികൾ
URL-കൾ വേരിയബിളുകളിൽ വെക്കുക
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
array ഉപയോഗിച്ച് 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
സംബന്ധിച്ച കൂടുതൽ വിവരങ്ങൾക്ക്.