Bắt đầu
Cài đặt
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.
Sử dụng cơ bản
Ví dụ dưới đây minh họa cách tạo một client TacoTranslate, bọc ứng dụng của bạn bằng provider TacoTranslate và sử dụng component Translate để hiển thị các chuỗi đã được dịch.
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>
);
}Ví dụ được đặt để sử dụng tiếng Tây Ban Nha (locale="es"), nên thành phần Translate sẽ hiển thị "¡Hola, mundo!".
Ví dụ
Hãy ghé qua thư mục ví dụ trên GitHub của chúng tôi để tìm hiểu thêm về cách thiết lập TacoTranslate cụ thể cho trường hợp sử dụng của bạn, chẳng hạn với Next.js App Router, hoặc khi sử dụng Create React App.
Chúng tôi cũng có một CodeSandbox được thiết lập mà bạn có thể xem tại đây.