はじめに
インストール
プロジェクトに TacoTranslate をインストールするには、ターミナルを開き、プロジェクトのルートディレクトリに移動してください。次に、以下のコマンドを実行して npm でインストールします。
npm install tacotranslate
これは、すでにプロジェクトがセットアップされていることを前提としています。詳細については、例をご覧ください。
基本的な使い方
以下の例では、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の例フォルダにアクセスして、Next.js App Router や Create React App を使用するなど、あなたのユースケースに合わせた TacoTranslate の設定方法について詳しく学びましょう。
私たちは CodeSandbox も用意しており、こちらでご覧いただけます。