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 thành phần Translate để hiển thị các chuỗi đã 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 thiết lập để sử dụng tiếng Tây Ban Nha (locale="es"), vì vậy thành phần Translate sẽ xuất "¡Hola, mundo!".
Ví dụ
Hãy truy cập vào 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 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 đã thiết lập một CodeSandbox mà bạn có thể xem tại đây.