快速開始
安裝
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.
基本用法
以下範例示範如何建立 TacoTranslate 用戶端,使用 TacoTranslate 提供者包裹您的應用程式,並使用 Translate 元件來顯示已翻譯的字串。
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>
);
}範例設定為使用西班牙語(locale="es"),因此 Translate 元件會輸出「¡Hola, mundo!」。
範例
前往 我們的 GitHub 範例資料夾 以了解更多如何為您的使用情境設定 TacoTranslate,例如搭配 Next.js App Router 或使用 Create React App。
我們也已為你設置一個 CodeSandbox,你可以 在這裡查看。