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

[`standardizeLocale`](/docs/platform/core/reference/gt-class-methods/locales/standardize-locale) は、General Translation の Core ライブラリに含まれるスタンドアロンのユーティリティ関数で、BCP-47 ロケールコードを大文字・小文字の表記を補正しながら標準の形式に正規化します。

## 概要 [#overview]

`generaltranslation` から `standardizeLocale` を直接 import し、ロケールコードを渡して呼び出します。APIキーや [GT](/docs/platform/core/reference/gt-class/constructor) インスタンスは必要ありません。インスタンスベースで同等の処理を行うには、[`GT`](/docs/platform/core/reference/gt-class/constructor) インスタンスの [`standardizeLocale`](/docs/platform/core/reference/gt-class-methods/locales/standardize-locale) メソッドを使用してください。

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

// 大文字・小文字を正規化
console.log(standardizeLocale('EN-gb')); // 'en-GB'
console.log(standardizeLocale('fr-ca')); // 'fr-CA'

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

シグネチャ:

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

## 仕組み [#how-it-works]

* **正規化。** 入力を `Intl.getCanonicalLocales` に渡し、最初の正準化済みの結果を返します。これにより、大文字・小文字の形式が正規化されます (言語は小文字、リージョンは大文字、script は先頭大文字) 。
* **フォールバック。** 入力を正規化できない場合は、元の入力文字列が変更されずにそのまま返されます。

## パラメータ [#parameters]

| パラメータ               | 説明                  | 型        | 省略可能 | デフォルト |
| ------------------- | ------------------- | -------- | ---- | ----- |
| [`locale`](#locale) | 正規化するBCP-47ロケールコード。 | `string` | いいえ  | —     |

### `locale` [#locale]

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

標準化する対象の BCP-47 ロケールコード。

## 戻り値 [#returns]

**Type** `string`

標準化された BCP-47 ロケールコード。標準化できない場合は、入力文字列をそのまま返します。

## 例 [#examples]

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

// ハイフン区切りのタグの大文字・小文字を正規化する
console.log(standardizeLocale('EN-gb')); // 'en-GB'
console.log(standardizeLocale('fr-ca')); // 'fr-CA'
console.log(standardizeLocale('en-us')); // 'en-US'

// すでに標準化済みのロケールはそのまま通過する
console.log(standardizeLocale('es-ES')); // 'es-ES'

// 正規化できない入力はそのまま返される
console.log(standardizeLocale('en_us')); // 'en_us'（アンダースコアは有効なBCP-47ではない）
console.log(standardizeLocale('not a locale')); // 'not a locale'
```

```typescript
import { standardizeLocale, isValidLocale } from 'generaltranslation';

// ユーザー入力の正規化
function processUserInput(input: string) {
  const standardized = standardizeLocale(input.trim());
  const isValid = isValidLocale(standardized);

  return {
    original: input,
    standardized,
    isValid,
  };
}

// さまざまな入力をテスト
const inputs = ['EN-gb', 'FR-ca', 'invalid', 'zh-CN'];
inputs.forEach((input) => {
  console.log(processUserInput(input));
});
```

## メモ [#notes]

* `Intl.getCanonicalLocales` を使って、大文字・小文字の表記を正規化します (言語は小文字、リージョンは大文字) 。
* 正準化できない入力については、入力文字列を変更せずそのまま返します。
* さまざまな source からのロケール入力を正規化するうえで不可欠です。
* `Intl` API 以外の外部依存関係はありません。

## Sitemap

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