# Locale

class

Represents the localization services.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/locale.ts#L17)

<a id="properties">

## Properties

<a id="member-contentLanguage">

### `contentLanguage: string` _(readonly)_

The editor content language code in the [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format.

Usually the same as the [editor language](#member-uiLanguage), it can be customized by passing an optional argument to the `Locale` constructor.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/locale.ts#L37)

<a id="member-contentLanguageDirection">

### `contentLanguageDirection: LanguageDirection` _(readonly)_

Text direction of the [editor content language](#member-contentLanguage).

If the content language was passed directly to the `Locale` constructor, this property represents the direction of that language.

If the [editor content language](#member-contentLanguage) was derived from the [editor language](#member-uiLanguage), the content language direction is the same as the [UI language direction](#member-uiLanguageDirection).

The value is either `'ltr'` or `'rtl'`.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/locale.ts#L50)

<a id="member-t">

### `t: LocaleTranslate` _(readonly)_

Translates the given message to the [`uiLanguage`](#member-uiLanguage). This method is also available in [`Editor`](module_core_editor_editor-Editor.md#member-t) and [`View`](module_ui_view-View.md#member-t).

This method's context is statically bound to the `Locale` instance and **should always be called as a function**:

```typescript
const t = locale.t;
t( 'Label' );
```

The message can be either a string or an object implementing the [`Message`](module_utils_translation-service-Message.md) interface.

The message may contain placeholders (`%<index>`) for value(s) that are passed as a `values` parameter. For an array of values, the `%<index>` will be changed to an element of that array at the given index. For a single value passed as the second argument, only the `%0` placeholders will be changed to the provided value.

```typescript
t( 'Created file "%0" in %1ms.', [ fileName, timeTaken ] );
t( 'Created file "%0", fileName );
```

The message supports plural forms. To specify the plural form, use the `plural` property. Singular or plural form will be chosen depending on the first value from the passed `values`. The value of the `plural` property is used as a default plural translation when the translation for the target language is missing.

```typescript
t( { string: 'Add a space', plural: 'Add %0 spaces' }, 1 ); // 'Add a space' for the English language.
t( { string: 'Add a space', plural: 'Add %0 spaces' }, 5 ); // 'Add 5 spaces' for the English language.
t( { string: '%1 a space', plural: '%1 %0 spaces' }, [ 2, 'Add' ] ); // 'Add 2 spaces' for the English language.

t( { string: 'Add a space', plural: 'Add %0 spaces' }, 1 ); // 'Dodaj spację' for the Polish language.
t( { string: 'Add a space', plural: 'Add %0 spaces' }, 5 ); // 'Dodaj 5 spacji' for the Polish language.
t( { string: '%1 a space', plural: '%1 %0 spaces' }, [ 2, 'Add' ] ); // 'Dodaj 2 spacje' for the Polish language.
```

* The message should provide an ID using the `id` property when the message strings are not unique and their translations should be different.

```typescript
translate( 'en', { string: 'image', id: 'ADD_IMAGE' } );
translate( 'en', { string: 'image', id: 'AN_IMAGE' } );
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/locale.ts#L96)

<a id="member-translations">

### `translations?: Translations`

Object that contains translations.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/locale.ts#L101)

<a id="member-uiLanguage">

### `uiLanguage: string` _(readonly)_

The editor UI language code in the [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format.

If the [content language](#member-contentLanguage) was not specified in the `Locale` constructor, it also defines the language of the content.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/locale.ts#L24)

<a id="member-uiLanguageDirection">

### `uiLanguageDirection: LanguageDirection` _(readonly)_

Text direction of the [editor UI language](#member-uiLanguage). Either `'ltr'` or `'rtl'`.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/locale.ts#L29)

<a id="methods">

## Methods

<a id="function-constructor">

### `constructor( options = { options.contentLanguage?, options.translations?, options.uiLanguage? } )`

Creates a new instance of the locale class. Learn more about [configuring the language of the editor](../getting-started/setup/ui-language.md).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/locale.ts#L115)

#### Parameters

* `options: object`

  Locale configuration.

  Properties

  * `options.contentLanguage?: string`

    The editor content language code in the [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format. If not specified, the same as `options.language`. See [`contentLanguage`](#member-contentLanguage).

  * `options.translations?: ArrayOrItem<Translations>`

    Translations passed as a editor config parameter.

  * `options.uiLanguage?: string`

    The editor UI language code in the [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format. See [`uiLanguage`](#member-uiLanguage).

    Defaults to `'en'`

  Defaults to `{}`

<a id="function-_t">

### `_t( message, values ) → string` _(private)_

An unbound version of the [`t`](#member-t) method.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/locale.ts#L137)

#### Parameters

* `message: string | Message`

* `values: string | number | readonly Array<string | number>`

  Defaults to `[]`

#### Returns

* `string`

---

Full index of the CKEditor 5 API reference: [llms.txt](llms.txt)
