# General Translation Platform: resolveCanonicalLocale
URL: https://generaltranslation.com/ja/docs/platform/core/reference/utility-functions/locales/resolve-canonical-locale.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: GT インスタンスなしで、ロケールエイリアスを正規ロケールコードに解決します。resolveCanonicalLocale の API リファレンス。

[`resolveCanonicalLocale`](/docs/platform/core/reference/gt-class-methods/locales/resolve-canonical-locale) は、General Translation のコアライブラリに含まれる単体で使えるユーティリティ関数で、ロケールエイリアスを内部で使用される正規 BCP-47 ロケールコードに解決します。これは [`resolveAliasLocale`](/docs/platform/core/reference/gt-class-methods/locales/resolve-alias-locale) の逆の関数です。

## 概要 [#overview]

`generaltranslation` から `resolveCanonicalLocale` を直接インポートし、ロケールコードと省略可能なカスタムマッピングを渡して呼び出します。APIキーや [GT](/docs/platform/core/reference/gt-class/constructor) インスタンスは必要ありません。インスタンスのマッピングを継承して解決する場合は、代わりに [`GT`](/docs/platform/core/reference/gt-class/constructor) インスタンスの [`resolveCanonicalLocale`](/docs/platform/core/reference/gt-class-methods/locales/resolve-canonical-locale) メソッドを使用してください。

```typescript
import { resolveCanonicalLocale } from 'generaltranslation';

const canonical = resolveCanonicalLocale('en', { en: { code: 'en-US' } });
// "en-US"
```

シグネチャ:

```typescript
resolveCanonicalLocale(
  locale: string,
  customMapping?: CustomMapping
): string
```

## 動作 [#how-it-works]

* **順方向参照。** [`CustomMapping`](/docs/platform/core/reference/types/custom-mapping) で、エイリアスに対応する正規ロケールを参照します。
* **パススルー。** 正規マッピングがない場合は、入力されたロケールをそのまま返します。

## パラメーター [#parameters]

| パラメーター                             | 説明                               | 型                                                                     | 任意  | デフォルト |
| ---------------------------------- | -------------------------------- | --------------------------------------------------------------------- | --- | ----- |
| [`locale`](#locale)                | 正規のロケールコードに解決する対象のエイリアスのロケールコード。 | `string`                                                              | いいえ | —     |
| [`customMapping`](#custom-mapping) | 正規のロケールを解決するために使用するカスタムマッピング。    | [`CustomMapping`](/docs/platform/core/reference/types/custom-mapping) | はい  | —     |

### `locale` [#locale]

**型** `string` · **必須**

解決対象のエイリアスのロケールコード。

### `customMapping` [#custom-mapping]

**型** [`CustomMapping`](/docs/platform/core/reference/types/custom-mapping) · **任意**

正規ロケールの解決に使用するカスタムマッピング。

## 戻り値 [#returns]

**型** `string`

エイリアスに対応する正規ロケール、または正規マッピングが存在しない場合は入力ロケールをそのまま返します。

## 例 [#examples]

```typescript
import { resolveCanonicalLocale } from 'generaltranslation';

// mappingなし — 入力をそのまま返す
console.log(resolveCanonicalLocale('en-US')); // "en-US"

// custom mappingあり — エイリアスを解決する
console.log(resolveCanonicalLocale('en', { en: { code: 'en-US' } })); // "en-US"
```

## メモ [#notes]

* これは [`resolveAliasLocale`](/docs/platform/core/reference/utility-functions/locales/resolve-alias-locale) の逆の処理です。
* 正規マッピングが見つからない場合は、入力されたロケールをそのまま返します。

## Sitemap

See the full [sitemap](https://generaltranslation.com/sitemap.md) for all pages.
