TacoTranslate
/
DokümantasyonFiyatlandırma
 
  1. Giriş
  2. Başlarken
  3. Kurulum ve yapılandırma
  4. TacoTranslate Kullanımı
  5. Sunucu tarafı render etme
  6. Gelişmiş kullanım
  7. En iyi uygulamalar
  8. Hata yönetimi ve hata ayıklama
  9. Desteklenen diller

En iyi uygulamalar

URL’leri değişkenlerde saklayın

When translating strings that contain URLs or similar data, it is considered a good practice to place these URLs inside variables and then referencing them within your templates.

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

ARIA etiketlerini kullanın

When translating the text of interactive elements like buttons, it’s important to include ARIA labels to ensure accessibility. ARIA labels help screen readers provide descriptive information about the element’s function.

For instance, if you have a button that lets users copy text from a code block, you can use the aria-label attribute to provide a clear description:

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

Something about this feels very meta.

Küresel origin dizisi ve birden fazla bileşen origin'i

This pattern only works when using the Next.js Pages Router.

When working with larger applications, it’s beneficial to split strings and translations into multiple, smaller origins. This approach helps decrease bundle sizes and transfer times, ensuring efficient and scalable localization.

While this is straightforward when rendering only on the client side, managing origins quickly becomes complex when fetching translations for server-side rendering. However, you can automate origin management by utilizing the TacoTranslate client origins array.

Consider this example, where we have separated our components and pages into separate files.

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});
}

See our server-side rendering examples for more information about getTacoTranslateStaticProps.

Hata yönetimi ve hata ayıklama

Bir ürün Nattskiftet'tenNorveç Yapımı