# generaltranslation: General Translation Core SDK: determineLocale URL: https://generaltranslation.com/ja/docs/core/class/methods/locales/determine-locale.mdx --- title: determineLocale description: GT の determineLocale メソッドに関する API リファレンス --- ## 概要 `determineLocale` メソッドは、承認済みロケールの一覧から、ユーザー設定に基づいて最適なロケールを判定します。 このメソッドはロケールネゴシエーションを実装しており、完全一致するロケールが利用できない場合に、最も適したロケールを見つけます。 ```typescript const gt = new GT({ sourceLocale: 'en-US', locales: ['en-US', 'es-ES', 'fr-FR', 'de-DE'] }); // 完全一致 console.log(gt.determineLocale('en-US')); // 'en-US' // 言語フォールバック console.log(gt.determineLocale('en-GB')); // 'en-US' (最も近い英語バリアント) // 複数の優先設定 console.log(gt.determineLocale(['fr-CA', 'es-MX', 'en-US'])); // 'es-ES' (最も近いスペイン語バリアント) // 一致なし console.log(gt.determineLocale('it-IT')); // undefined ``` *** ## リファレンス ### パラメーター ### 戻り値 `string | undefined` - 最も適合するロケール。一致するものが見つからない場合は undefined *** ## 例 ### ユーザーのロケールネゴシエーション ```typescript const gt = new GT({ sourceLocale: 'en-US', locales: ['en-US', 'en-GB', 'es-ES', 'fr-FR'] }); // ブラウザの Accept-Language ヘッダーをシミュレート const userPreferences = ['fr-CA', 'en-GB', 'en']; const bestMatch = gt.determineLocale(userPreferences); console.log(bestMatch); // 優先順位に基づき 'fr-FR' ``` *** ## 注意事項 * 承認済みロケールの中から最初に見つかった完全一致を返します * リージョンまで完全一致するものがない場合は、言語の一致にフォールバックします * 入力配列内の優先順を保持します * 適切な一致が見つからない場合は `undefined` を返します * Web アプリケーションでロケールネゴシエーションを実装する際に不可欠です ## 次のステップ * [`requires-translation`](/docs/core/class/methods/locales/requires-translation)を使って翻訳が必要か確認する * [`is-same-language`](/docs/core/class/methods/locales/is-same-language)を使って言語を比較する