හොඳ ක්රියා පටිපාටි
URL විචල්යවලට තබන්න
URL හෝ ඒවට සමාන දත්ත අඩංගු පෙළ පරිවර්තනය කරන විට, මෙම URL වෙනස්කාරක (variables) තුළ තබා ඔබගේ ටෙම්ප්ලේට් තුළ එවැනි රෙෆරන්ස් භාවිතා කිරීම හොඳ ක්රියාපටිපාටියක් ලෙස සැලකේ.
<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 භාවිතා කරන විට පමණක් ක්රියා කරයි.
විශාල යෙදුම් සමඟ වැඩ කරන විට, පෙළවල් සහ පරිවර්තන බහු, කුඩා මූලාශ්ර කිහිපයකට වෙන් කිරීම ප්රයෝජනවත් වේ. මේ ක්රමය බන්ඩල් ප්රමාණ සහ දත්ත හුවමාරු කාලය අඩු කරමින්, කාර්යක්ෂම හා විහිදුණු දේශීයකරණයක් සලසා දෙයි.
මෙය client‑side පමණක් රෙන්ඩර කරන විට සරල වුවත්, සේවාදායක‑පැත්තෙන් (server-side rendering) පරිවර්තන ලබා ගෙන සිටිද්දී මූලාශ්ර කළමනාකරණය ඉක්මනින් සංකීර්ණ වේ. එහෙත්, TacoTranslate client origins array භාවිතයෙන් ඔබට මූලාශ්ර කළමනාකරණය ස්වයංක්රීය කළ හැක.
අපි කොම්පොනන්ට් සහ පිටු වෙන වෙනම ගොනු වලට වෙන් කර ඇති මෙම උදාහරණය සලකා බලන්න.
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 ගැන වැඩි විස්තර සඳහා අපගේ සේවාදායක පැත්තේ රෙන්ඩර කිරීමේ උදාහරණ බලන්න.