# General Translation Platform: standardizeLocale
URL: https://generaltranslation.com/ja/docs/platform/core/reference/gt-class-methods/locales/standardize-locale.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: ロケールコードを標準形式に正規化します。standardizeLocale の API リファレンス。

[GT](/docs/platform/core/reference/gt-class/constructor) インスタンス上で BCP-47 ロケールコードの形式と大文字・小文字を正しく整えるために標準化します。General Translation はロケールコードを canonical な形式に変換し、アプリケーション全体で一貫性を保ちつつ、国際化 API で使いやすい形にします。

## 概要 [#overview]

[`GT`](/docs/platform/core/reference/gt-class/constructor) インスタンスで、必要に応じてロケールコードを指定して `standardizeLocale` を呼び出します。省略した場合は、そのインスタンスの `targetLocale` が使用されます。

```typescript
const gt = new GT({ sourceLocale: 'en', targetLocale: 'es-ES' });

console.log(gt.standardizeLocale('en-us')); // "en-US"
```

シグネチャ：

```typescript
standardizeLocale(locale?: string): string
```

*注: `standardizeLocale` はローカルで実行されるため、APIキーは不要です。`locale` を省略した場合は、インスタンスの `targetLocale` が使用されます。`GT` インスタンスなしで正規化する場合は、スタンドアロンの [`standardizeLocale`](/docs/platform/core/reference/utility-functions/locales/standardize-locale) を参照してください。*

## 動作の仕組み [#how-it-works]

* **正規化。** `Intl.getCanonicalLocales` に委ねられ、大文字・小文字が正規化されます。言語サブタグは小文字に、リージョンサブタグは大文字になります。
* **ロケールのフォールバック。** `locale` を省略した場合は、インスタンスの `targetLocale` が使用されます。
* **失敗時はそのまま返します。** 標準化できない場合は、入力文字列を変更せずに返します。
* **ロケール未指定。** ロケールが指定されておらず、かつインスタンスに `targetLocale` が設定されていない場合は、`Error` をスローします。

ハイフン付きコードによく適用される大文字・小文字の修正:

* `en-us` → `en-US` (リージョンを大文字化) 
* `EN-gb` → `en-GB` (言語を小文字化し、リージョンを大文字化) 
* `fr-ca` → `fr-CA` (全体を適切な表記に修正)

## パラメータ [#parameters]

| パラメータ               | 説明                      | 型        | 任意 | デフォルト               |
| ------------------- | ----------------------- | -------- | -- | ------------------- |
| [`locale`](#locale) | 標準化する BCP-47 ロケールコードです。 | `string` | はい | `this.targetLocale` |

### `locale` [#locale]

**型** `string` · **任意** · **デフォルト** `this.targetLocale`

標準化する BCP-47 ロケールコードです。指定しない場合は、インスタンスの `targetLocale` が使われます。

## 戻り値 [#returns]

**型** `string`

標準化された BCP-47 ロケールコードを返します。標準化できない場合は、入力文字列をそのまま返します。ロケールが指定されておらず、インスタンスに `targetLocale` も設定されていない場合は、`Error` をスローします。

## 例 [#examples]

```typescript
const gt = new GT({ sourceLocale: 'en', targetLocale: 'es-ES' });

// ハイフン付きコードの大文字・小文字は正規化される
console.log(gt.standardizeLocale('en-us')); // "en-US"
console.log(gt.standardizeLocale('EN-gb')); // "en-GB"
console.log(gt.standardizeLocale('fr-ca')); // "fr-CA"

// すでに標準化済みのロケールはそのまま返される
console.log(gt.standardizeLocale('es-ES')); // "es-ES"
console.log(gt.standardizeLocale('ja-JP')); // "ja-JP"
```

## メモ [#notes]

* 大文字・小文字を正規化します。言語コードは小文字、リージョンコードは大文字になります。
* コードを標準化できない場合は、入力文字列を変更せずそのまま返します。
* ロケール拡張とバリアントが存在する場合は、それらを保持します。

## Sitemap

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