Amfani na ci gaba
Sarrafa harsuna daga dama zuwa hagu
TacoTranslate yana sauƙaƙa goyon bayan harsunan daga dama zuwa hagu (RTL), kamar su Larabci da Ibrananci, a cikin aikace-aikacen React ɗinku. Kulawa mai kyau ga harsunan RTL tana tabbatar da cewa abun cikin ku yana bayyana daidai ga masu amfani da ke karantawa daga dama zuwa hagu.
import {useTacoTranslate} from 'tacotranslate/react';
function Document() {
const {locale, isRightToLeft} = useTacoTranslate();
return (
<html lang={locale} dir={isRightToLeft ? 'rtl' : 'ltr'}>
<body>
// ...
</body>
</html>
);
}
Hakanan zaka iya amfani da aikin isRightToLeftLocaleCode
da aka bayar don duba harshen yanzu a wajen React.
import {isRightToLeftLocaleCode} from 'tacotranslate';
function foo(locale = 'es') {
const direction = isRightToLeftLocaleCode(locale) ? 'rtl' : 'ltr';
// ...
}
Kashe fassara
Don kashe fassara ga wasu sassa na wani layi ko don tabbatar da cewa wasu ɓangarori sun kasance kamar yadda suke, za ka iya amfani da madadin murabba'i uku. Wannan fasalin yana da amfani wajen kiyaye asalin tsarin sunaye, ƙa'idodin fasaha, ko kowane wani abu da bai kamata a fassara ba.
import {Translate} from 'tacotranslate/react';
function Component() {
return (
<Translate string="Hello, [[[TacoTranslate]]]!" />
);
}
A cikin wannan misalin, kalmar “TacoTranslate” ba za a canza ta ba a cikin fassarar.
Masu ba da sabis na TacoTranslate da yawa
Muna ƙarfafa amfani da masu bayar da TacoTranslate
da yawa a cikin aikace-aikacenku. Wannan yana da amfani don tsara fassarar ku da ƙugiyoyi zuwa tushe daban-daban, kamar yadda ke cikin saman shafi, ƙasan shafi, ko wasu sassa na musamman.
Kuna iya karanta ƙarin game da amfani da asalin nan.
Masu samar da TacoTranslate
suna gada saituna daga kowane mai samar da uwar garke, don haka ba za ku yi buƙatar maimaita wasu saituna ba.
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>
);
}
Sauya tushen ko yanki
Baya ga amfani da masu ba da sabis da yawa na TacoTranslate
, za ka iya kuma ƙetare asali da yare a matakan Translate
sashi da useTranslation
kayan haɗi.
import {Translate, useTranslation} from 'tacotranslate/react';
function Greeting() {
const spanishHello = useTranslation('Hello!', {locale: 'es'});
return (
<>
{spanishHello}
<Translate string="What’s up?" origin="greeting" />
</>
);
}
Sarrafa lodawa
Lokacin canza harsuna a ɓangaren mai amfani, ɗaukar fassarar na iya ɗaukar ƴan lokaci dangane da haɗin intanet ɗin mai amfani. Kuna iya nuna alamar lodawa don haɓaka ƙwarewar mai amfani ta hanyar bayar da martani na gani yayin canjin.
import {useTacoTranslate} from 'tacotranslate/react';
function Component() {
const {isLoading} = useTacoTranslate();
return (
isLoading ? 'Translations are loading...' : null
);
}
Rarraba jam'i
Don sarrafa jam'i da nuna alamomin da suka danganci ƙidaya yadda ya kamata a cikin harsuna daban-daban, wannan ana ɗauka a matsayin mafi kyawun aiki:
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)}}
/>
);
}
Harsuna da dama
Don tallafawa harsuna da yawa a lokaci guda cikin wannan aikace-aikacen, za ka iya amfani da masu ba da sabis na TacoTranslate da yawa tare da daban-daban locale
ƙimomi kamar yadda aka nuna a ƙasa:
Hakanan zaka iya sauya locale
a matakin ɓangare ko harsashi.
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>
);
}
Amfani da translation IDs
Kuna iya ƙara id
zuwa ga Translate
sashi don sarrafa fassarar daban-daban ko ma’anoni ga wannan layin guda. Wannan yana da amfani ƙwarai musamman lokacin da rubutun guda yana buƙatar fassarori daban-daban bisa ga mahallin sa. Ta hanyar ba da IDs na musamman, kuna tabbatar da cewa kowanne misali na layin an fassara shi daidai gwargwadon ma’anarsa ta musamman.
import {Translate} from 'tacotranslate/react';
function Header() {
return (
<Translate id="header" string="Login" />
);
}
function Footer() {
return (
<Translate id="footer" string="Login" />
);
}
Alal misali, shiga na header zai iya fassara zuwa “Iniciar sesión”, kuma shiga na footer zai iya fassara zuwa “Acceder” a harshen Sifaniyanci.