# General Translation Platform: getLocaleName
URL: https://generaltranslation.com/ja/docs/platform/core/reference/gt-class-methods/locales/get-locale-name.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: わかりやすいロケール名を返します。getLocaleName の API リファレンス。

`Intl.DisplayNames` API を使用して、[GT](/docs/platform/core/reference/gt-class/constructor) インスタンス上のロケールコードの表示名を取得します。General Translation は、有効な任意の BCP-47 ロケールコードに対して、インスタンスの source ロケールに応じてローカライズされた、わかりやすい名前を返します。

## 概要 [#overview]

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

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

const name = gt.getLocaleName('fr-CA');
console.log(name); // "Canadian French"
```

シグネチャ:

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

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

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

### 表示言語

表示名は、次の設定に応じてローカライズされます。

1. インスタンスの`sourceLocale` (設定されている場合) 
2. ライブラリのデフォルトロケール (`'en'`)

### マッピング の統合

* カスタムのロケール mapping が最初に確認されます。
* カスタム名が定義されている場合は、それが優先されます。
* それ以外の場合は、標準の BCP-47 コードに対して `Intl.DisplayNames` が使用されます。

### ロケールが未指定

ロケールが指定されておらず、かつインスタンスに `targetLocale` も設定されていない場合は、`Error` をスローします。有効なロケールに対応する名前が見つからない場合は、空の文字列を返します。

## パラメータ [#parameters]

| パラメータ               | 説明                            | 型        | 任意 | デフォルト               |
| ------------------- | ----------------------------- | -------- | -- | ------------------- |
| [`locale`](#locale) | 表示名を取得する対象の BCP-47 ロケールコードです。 | `string` | はい | `this.targetLocale` |

### `locale` [#locale]

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

表示名を取得する BCP-47 ロケールコードです。指定しない場合は、このインスタンスの `targetLocale` が使用されます。

## 戻り値 [#returns]

**型** `string`

ロケールの表示名を、そのロケール向けにローカライズして返します。ロケールが指定されておらず、インスタンスに `targetLocale` も設定されていない場合は、`Error` をスローします。

## 例 [#examples]

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

// ターゲットロケールの名前を取得
console.log(gt.getLocaleName()); // "French"

// 他のロケールの名前を取得
console.log(gt.getLocaleName('es')); // "Spanish"
console.log(gt.getLocaleName('de')); // "German"
console.log(gt.getLocaleName('ja')); // "Japanese"
```

## メモ [#notes]

* このメソッドは、表示言語の判定にインスタンスの `sourceLocale` を使用します。
* カスタムマッピング名は、標準の `Intl.DisplayNames` より優先されます。

## Sitemap

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