TacoTranslate
/
DokimantasyonPri
 
  1. Entwodiksyon
  2. Kòmanse
  3. Mete kanpe ak konfigirasyon
  4. Sèvi ak TacoTranslate
  5. Rann sou bò sèvè
  6. Itilizasyon avanse
  7. Pi bon pratik
  8. Jesyon erè ak debogaj
  9. Lang sipòte

Pi bon pratik

Mete URL yo nan varyab

Lè w ap tradui chenn ki gen URL oswa done ki sanble, li konsidere kòm yon bon pratik pou mete URL sa yo nan varyab epi fè referans a yo nan modèl ou yo.

<Translate
	string={`Click <a href="{{url}}">here</a>`}
	variables={{url: 'https://tacotranslate.com'}}
/>

Sèvi ak etikèt ARIA

Lè w ap tradui tèks eleman entèaktif tankou bouton, li enpòtan pou enkli etikèt ARIA pou asire aksesibilite. Etikèt ARIA ede lektè ekran bay enfòmasyon deskriptif sou fonksyon eleman an.

Pa egzanp, si ou gen yon bouton ki pèmèt itilizatè yo kopye tèks soti nan yon blòk kòd, ou ka itilize atribi aria-label la pou bay yon deskripsyon klè:

<Translate
	aria-label={useTranslation('Copy to clipboard')}
	string="Copy"
/>

Gen yon bagay sou sa a ki fè li santi l trè meta.

Tab orijin mondyal ak plizyè orijin konpozan

Modèl sa a sèlman mache lè w ap itilize Next.js Pages Router.

Lè w ap travay ak aplikasyon ki pi gwo, li itil pou divize chenn tèks ak tradiksyon yo an plizyè orijin ki pi piti. Apwòch sa a ede diminye gwosè pake yo ak tan transfè yo, asire yon lokalizasyon efikas ki ka elaji.

Pandan ke sa senp lè w ap rann sèlman sou bò kliyan an, jere orijin yo vin rapidman konplike lè w ap rekipere tradiksyon pou rann sou bò sèvè a. Sepandan, ou ka otomatize jesyon orijin yo lè w itilize tablo origins nan kliyan TacoTranslate la.

Gade egzanp sa a, kote nou te separe konpozan ak paj yo nan fichye separe.

components/pricing-table.tsx
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>
	);
}
pages/pricing.tsx
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});
}

Gade egzanp rann bò sèvè nou yo pou plis enfòmasyon sou getTacoTranslateStaticProps.

Jesyon erè ak debogaj

Yon pwodwi soti nan NattskiftetFèt nan Nòvèj