開始使用
安裝
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,您可以在此處查看。