# General Translation Platform: resolveAliasLocale
URL: https://generaltranslation.com/ja/docs/platform/core/reference/utility-functions/locales/resolve-alias-locale.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: GT インスタンスを使わずに、カスタムマッピングで使用されるロケールコードにロケール エイリアス を解決します。resolveAliasLocale の API リファレンス。

[`resolveAliasLocale`](/docs/platform/core/reference/gt-class-methods/locales/resolve-alias-locale) は、General Translation のコアライブラリに含まれるスタンドアロンのユーティリティ関数で、カスタムマッピングが設定されている場合に、正規ロケールコードを対応する エイリアス ロケールコードへ逆変換します。

## 概要 [#overview]

`generaltranslation` から `resolveAliasLocale` を直接インポートし、ロケールコードとカスタムマッピングを渡して呼び出します。API Key や [GT](/docs/platform/core/reference/gt-class/constructor) インスタンスは不要です。インスタンスベースの同等の機能を使う場合は、代わりに [`GT`](/docs/platform/core/reference/gt-class/constructor) インスタンスの [`resolveAliasLocale`](/docs/platform/core/reference/gt-class-methods/locales/resolve-alias-locale) メソッドを使用してください。

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

const customMapping = {
  'simplified-chinese': { code: 'zh-CN', name: 'Simplified Chinese' },
  'traditional-chinese': { code: 'zh-TW', name: 'Traditional Chinese' },
};

console.log(resolveAliasLocale('zh-CN', customMapping)); // 'simplified-chinese'
```

シグネチャ：

```typescript
resolveAliasLocale(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 { resolveAliasLocale } from 'generaltranslation';

const customMapping = {
  'simplified-chinese': { code: 'zh-CN', name: 'Simplified Chinese' },
  'traditional-chinese': { code: 'zh-TW', name: 'Traditional Chinese' },
};

// canonicalをエイリアスに解決する
console.log(resolveAliasLocale('zh-CN', customMapping)); // 'simplified-chinese'
console.log(resolveAliasLocale('zh-TW', customMapping)); // 'traditional-chinese'

// マッピングされていないロケールは元の値を返す
console.log(resolveAliasLocale('es-ES', customMapping)); // 'es-ES'
```

## メモ [#notes]

* 正規のロケールコードを、ユーザーにわかりやすいエイリアスに戻します。
* 対応するマッピングがない場合は、元のロケールを返します。
* ユーザー向けのロケール名を表示するうえで重要です。
* カスタムのロケールマッピングにも対応しています。
* ステートレスな関数で、副作用はありません。

## Sitemap

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