საუკეთესო პრაქტიკა
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.
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.
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
-ის შესახებ.