Pierwsze kroki
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, opakować aplikację w dostawcę TacoTranslate, oraz 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 pod kątem twojego przypadku użycia, na przykład z Next.js App Router lub z użyciem Create React App.
Mamy też przygotowany CodeSandbox, który możesz obejrzeć tutaj.