മികച്ച പ്രവൃത്തികൾ
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 ഉപയോഗിക്കുമ്പോഴേ മാത്രം പ്രവർത്തിക്കും.
വലുതായ ആപ്ലിക്കേഷനുകളുമായി ജോലി ചെയ്യുമ്പോൾ, സ്ട്രിംഗുകളും പരിഭാഷകളും പല ചെറുതും സ്വതന്ത്രവുമായ ഓറിജിനുകളായി വിഭജിക്കുന്നത് ഫലപ്രദമാണ്. ഈ സമീപനം ബണ്ടിൽ വലിപ്പവും ട്രാൻസ്ഫർ സമയവും കുറയ്ക്കാൻ സഹായിച്ച് കാര്യക്ഷമവും സ്കെയിലബിൾയായ പ്രാദേശീകരണം ഉറപ്പാക്കുന്നു.
ഇത് ക്ലയന്റ്-സൈഡ്లో മാത്രം റെൻഡർ ചെയ്യുമ്പോൾ ലളിതമാണെങ്കിലും, സെർവർ-സൈഡ് റെൻഡറിംഗിനായി പരിഭാഷകൾ ഫെച്ച് ചെയ്യുമ്പോൾ ഓറിജിനുകളുടെ മാനേജ്മെന്റ് വേഗത്തിൽ സങ്കീർണ്ണമാവും. എന്നിരുന്നാലും, 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 നെക്കുറിച്ചുള്ള കൂടുതൽ വിവരങ്ങൾക്ക് ഞങ്ങളുടെ സെർവർ-സൈഡ് റെൻഡറിംഗ് ഉദാഹരണങ്ങൾ കാണുക.