Rozpoczęcie pracy
Instalacja
To install TacoTranslate in your application, open your terminal and navigate to the root directory of your project. Then, run the following command to install with npm:
npm install tacotranslateThis assumes you already have an application set up. See examples for more information.
Podstawowe użycie
Poniższy przykład pokazuje, jak utworzyć klienta TacoTranslate, owinąć aplikację za pomocą providera TacoTranslate i użyć komponentu Translate do wyświetlania przetłumaczonych tekstów.
import createTacoTranslateClient from 'tacotranslate';
import {TacoTranslate, Translate} from 'tacotranslate/react';
const tacoTranslateClient = createTacoTranslateClient({apiKey: 'YOUR_API_KEY'});
function Page() {
return <Translate string="Hello, world!" />;
}
export default function App() {
return (
<TacoTranslate client={tacoTranslateClient} locale="es">
<Page />
</TacoTranslate>
);
}Przykład jest ustawiony na język hiszpański (locale="es"), więc komponent Translate wyświetli "¡Hola, mundo!".
Przykłady
Odwiedź nasz folder z przykładami na GitHubie, aby dowiedzieć się więcej o tym, jak skonfigurować TacoTranslate specjalnie dla Twojego przypadku użycia, na przykład z Next.js App Router, lub używając Create React App.
Mamy też przygotowany CodeSandbox, który możesz obejrzeć tutaj.