മികച്ച രീതികൾ
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.