# General Translation Platform: requiresTranslation URL: https://generaltranslation.com/ja/docs/platform/core/reference/utility-functions/locales/requires-translation.mdx --- title: requiresTranslation description: GT インスタンスなしで 2 つのロケール間で翻訳が必要かどうかを確認します。requiresTranslation の API リファレンス。 --- [`requiresTranslation`](/docs/platform/core/reference/gt-class-methods/locales/requires-translation) は、General Translation のコアライブラリに含まれるスタンドアロンのユーティリティ関数で、元のロケールと対象ロケールの間で翻訳が必要かどうかを判定します。 ## 概要 [#overview] `generaltranslation` から `requiresTranslation` を直接インポートし、ソースロケールと対象ロケールを指定して呼び出します。APIキーや [GT](/docs/platform/core/reference/gt-class/constructor) インスタンスは必要ありません。インスタンスベースの同等の機能を使う場合は、代わりに [`GT`](/docs/platform/core/reference/gt-class/constructor) インスタンスの [`requiresTranslation`](/docs/platform/core/reference/gt-class-methods/locales/requires-translation) メソッドを使用してください。 ```typescript import { requiresTranslation } from 'generaltranslation'; console.log(requiresTranslation('en-US', 'es-ES')); // true console.log(requiresTranslation('en-US', 'en')); // false(同じ方言) ``` シグネチャ: ```typescript requiresTranslation( sourceLocale: string, targetLocale: string, approvedLocales?: string[], customMapping?: CustomMapping ): boolean ``` ## 仕組み [#how-it-works] 翻訳の判定は、次のルールに従います。 * 対象ロケールが指定されていない場合は、`false` を返します (翻訳は不要です) 。 * source ロケールと対象ロケールが同じ場合は、`false` を返します。 * `approvedLocales` が指定されていて、対象ロケールがその一覧に含まれていない場合は、`false` を返します。 * それ以外の場合は、`true` を返します。 ロケールは方言を考慮して比較されます。翻訳がスキップされるのは、同じ方言に解決されるロケール同士の場合だけです。`en-US` → `en` (同じ方言) の場合は翻訳不要ですが、`en-US` → `en-GB` の場合はリージョンが異なるため翻訳が必要です。比較時には、[`customMapping`](/docs/platform/core/reference/types/custom-mapping) も適用されます。 ## パラメータ [#parameters] | パラメータ | 説明 | Type | 任意 | デフォルト | | -------------------------------------- | ---------------------- | --------------------------------------------------------------------- | --- | ----- | | [`sourceLocale`](#source-locale) | 元のコンテンツのロケール。 | `string` | いいえ | — | | [`targetLocale`](#target-locale) | コンテンツの対象ロケール。 | `string` | いいえ | — | | [`approvedLocales`](#approved-locales) | 承認済みの対象ロケールの一覧 (省略可) 。 | `string[]` | はい | — | | [`customMapping`](#custom-mapping) | 比較時に適用するカスタムマッピング。 | [`CustomMapping`](/docs/platform/core/reference/types/custom-mapping) | はい | — | ### `sourceLocale` [#source-locale] **型** `string` · **必須** 元のコンテンツの BCP-47 ロケールコード。 ### `targetLocale` [#target-locale] **型** `string` · **必須** コンテンツの対象ロケールとなる BCP-47 ロケールコードです。 ### `approvedLocales` [#approved-locales] **型** `string[]` · **任意** 承認済みの対象ロケールの一覧です。指定した場合、この一覧に含まれていない対象ロケールは `false` を返します。 ### `customMapping` [#custom-mapping] **型** [`CustomMapping`](/docs/platform/core/reference/types/custom-mapping) · **省略可能** ロケールを比較する際に適用されるカスタムマッピングです。 ## 戻り値 [#returns] **型** `boolean` 翻訳が必要な場合は `true`、不要な場合は `false` です。 ## 例 [#examples] ```typescript import { requiresTranslation } from 'generaltranslation'; // 異なる言語は翻訳が必要 console.log(requiresTranslation('en-US', 'es-ES')); // true console.log(requiresTranslation('en-US', 'fr-FR')); // true // 同じ方言は翻訳不要 console.log(requiresTranslation('en-US', 'en-US')); // false console.log(requiresTranslation('en-US', 'en')); // false (同じ方言) // 同じ言語の異なる方言でも翻訳が必要 console.log(requiresTranslation('en-US', 'en-GB')); // true (リージョンが異なる) // approved locales フィルターを使用する場合 const approved = ['en-US', 'es-ES', 'fr-FR']; console.log(requiresTranslation('en-US', 'it-IT', approved)); // false (承認されていない) console.log(requiresTranslation('en-US', 'es-ES', approved)); // true (承認済みかつ異なる) ``` ## メモ [#notes] * 承認済みロケールの制約に従います。 * 対象が承認済みリストに含まれていない場合は、`false` を返します。 * カスタムのロケールマッピングも考慮します。