Types
GTConstructorParams
GT クラスのコンストラクター引数用の TypeScript インターフェース
概要
GTConstructorParams は、GT クラスの初期化に使用する設定 options を定義します。
interface GTConstructorParams {
apiKey?: string;
devApiKey?: string;
sourceLocale?: string;
targetLocale?: string;
locales?: string[];
projectId?: string;
baseUrl?: string;
customMapping?: CustomMapping;
}すべてのプロパティは省略可能です。指定がない場合、コンストラクタは環境変数から GT_API_KEY、GT_DEV_API_KEY、GT_PROJECT_ID を読み込みます。
プロパティ
| プロパティ | 型 | 説明 |
|---|---|---|
apiKey? | string | 本番環境のAPIキー |
devApiKey? | string | 開発環境のAPIキー |
sourceLocale? | string | 既定のsourceLocale |
targetLocale? | string | 既定のtargetLocale |
locales? | string[] | 対応ロケールコード |
projectId? | string | プロジェクト識別子 |
baseUrl? | string | カスタムAPIエンドポイント |
customMapping? | CustomMapping | カスタムロケールマッピング |
例
基本的なセットアップ
const gt = new GT({
apiKey: 'your-api-key',
sourceLocale: 'en',
targetLocale: 'es',
locales: ['en', 'es', 'fr']
});環境変数を使う場合
const gt = new GT({
sourceLocale: 'en',
targetLocale: 'es'
});
// 環境変数の GT_API_KEY と GT_PROJECT_ID を使用します関連する型
CustomMapping- カスタムの locale 定義
このガイドはいかがですか?