Itilizasyon avanse
Jere lang ki ekri de dwat ale goch
TacoTranslate fè li fasil pou sipòte lang dwat-a-gòch (RTL), tankou Arab ak Ebre, nan aplikasyon React ou yo. Yon bon jesyon lang RTL asire ke kontni ou afiche kòrèkteman pou itilizatè ki li soti nan dwat ale nan gòch.
import {useTacoTranslate} from 'tacotranslate/react';
function Document() {
const {locale, isRightToLeft} = useTacoTranslate();
return (
<html lang={locale} dir={isRightToLeft ? 'rtl' : 'ltr'}>
<body>
// ...
</body>
</html>
);
}
Ou ka itilize tou fonksyon isRightToLeftLocaleCode
ki disponib pou verifye lang aktyèl la deyò React.
import {isRightToLeftLocaleCode} from 'tacotranslate';
function foo(locale = 'es') {
const direction = isRightToLeftLocaleCode(locale) ? 'rtl' : 'ltr';
// ...
}
Dezaktive tradiksyon
Pou dezaktive tradiksyon pou pati espesifik nan yon fisèl oswa pou asire sèten segman rete jan yo ye a, ou ka itilize triples crochets kare . Karakteristik sa a itil pou kenbe fòma orijinal non, tèm teknik, oswa nenpòt lòt kontni ki pa ta dwe tradui.
import {Translate} from 'tacotranslate/react';
function Component() {
return (
<Translate string="Hello, [[[TacoTranslate]]]!" />
);
}
Nan egzanp sa a, mo “TacoTranslate” p ap chanje nan tradiksyon an.
Plizyè founisè TacoTranslate
Nou ankouraje fò anpil pou itilize plizyè TacoTranslate
founisè nan aplikasyon ou a. Sa itil pou òganize tradiksyon ou yo ak chèn karaktè ou yo nan diferan orijin, tankou tèt paj ou, pye paj ou, oswa seksyon espesifik.
Ou ka li plis sou kijan pou itilize orijin yo isit la.
Founisè TacoTranslate
eritye anviwònman ki soti nan nenpòt founisè paran, konsa ou pap bezwen repete okenn lòt anviwònman.
import createTacoTranslateClient from 'tacotranslate';
import {TacoTranslate} from 'tacotranslate/react';
const tacoTranslateClient = createTacoTranslateClient({apiKey: 'YOUR_API_KEY'});
function Header() {
return (
<TacoTranslate origin="header">
// ...
</TacoTranslate>
);
}
function Menu() {
return (
<TacoTranslate origin="menu">
// ...
</TacoTranslate>
);
}
export default function App() {
return (
<TacoTranslate client={tacoTranslateClient} origin="page" locale="es">
<Header />
<Menu />
</TacoTranslate>
);
}
Ranplase orijin oswa lokal
Anplis de sèvi ak plizyè TacoTranslate
founisè, ou ka tou ranplase tou de orijin ak lokal sou konpozan Translate
ak nivo kòd useTranslation
.
import {Translate, useTranslation} from 'tacotranslate/react';
function Greeting() {
const spanishHello = useTranslation('Hello!', {locale: 'es'});
return (
<>
{spanishHello}
<Translate string="What’s up?" origin="greeting" />
</>
);
}
Jere chaje
Lè w ap chanje lang sou bò kliyan an, pran tradiksyon yo ka pran kèk moman selon koneksyon itilizatè a. Ou ka montre yon endikatè chajman pou amelyore eksperyans itilizatè a lè w bay yon fidbak vizyèl pandan chanjman an.
import {useTacoTranslate} from 'tacotranslate/react';
function Component() {
const {isLoading} = useTacoTranslate();
return (
isLoading ? 'Translations are loading...' : null
);
}
Pliralizasyon
Pou jere pliryèl ak montre etikèt ki baze sou kantite yo kòrèkteman nan diferan lang, sa konsidere kòm yon pratik ki pi bon:
import {Translate, useLocale} from 'tacotranslate/react';
function PhotoCount() {
const locale = useLocale();
const count = 1;
return count === 0 ? (
<Translate string="You have no photos." />
) : count === 1 ? (
<Translate string="You have 1 photo." />
) : (
<Translate
string="You have {{count}} photos."
variables={{count: count.toLocaleString(locale)}}
/>
);
}
Plizyè lang
Pou sipòte plizyè lang an menm tan nan menm aplikasyon an, ou ka itilize plizyè founisè TacoTranslate
ak diferan valè locale
jan sa montre anba a:
Ou ka tou ranvèse locale
nan nivo konpozan oswa hook.
import createTacoTranslateClient from 'tacotranslate';
import {TacoTranslate, Translate} from 'tacotranslate/react';
const tacoTranslateClient = createTacoTranslateClient({apiKey: 'YOUR_API_KEY'});
function Spanish() {
return (
<TacoTranslate locale="es">
<Translate string="Hello, world in Spanish!" />
</TacoTranslate>
);
}
function Norwegian() {
return (
<TacoTranslate locale="no">
<Translate string="Hello, world in Norwegian!" />
</TacoTranslate>
);
}
export default function App() {
return (
<TacoTranslate client={tacoTranslateClient} origin="page" locale="es">
<Spanish />
<Norwegian />
</TacoTranslate>
);
}
Itilize ID tradiksyon yo
Ou ka ajoute yon id
nan konpozan Translate
pou jere diferan tradiksyon oswa siyifikasyon pou menm chèn nan. Sa a espesyalman itil lè menm tèks la bezwen diferan tradiksyon selon kontèks la. Lè w asiyen ID inik, ou asire ke chak okasyon nan chèn nan tradui avèk presizyon selon siyifikasyon espesifik li.
import {Translate} from 'tacotranslate/react';
function Header() {
return (
<Translate id="header" string="Login" />
);
}
function Footer() {
return (
<Translate id="footer" string="Login" />
);
}
Pa egzanp, header login ta ka tradui kòm “Iniciar sesión”, epi footer login ta ka tradui kòm “Acceder” nan lang Panyòl.