> For the complete documentation index, see [llms.txt](https://jsverse.gitbook.io/transloco/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jsverse.gitbook.io/transloco/core-concepts/language-api.md).

# Language API

## **`getDefaultLang()`**

Returns the default language of the application.

```typescript
app.component.ts
export class AppComponent {
  constructor(private translocoService: TranslocoService) {
    const defaultLang = translocoService.getDefaultLang();
    console.log(defaultLang);
  }
}
```

***

## **`setDefaultLang()`**

Sets the default language.

```typescript
app.component.ts
export class AppComponent {
  constructor(private translocoService: TranslocoService) {
    translocoService.setDefaultLang('es');
  }
}
```

***

## **`getActiveLang()`**

Returns the current active language.

```typescript
app.component.ts
export class AppComponent {
  constructor(private translocoService: TranslocoService) {
    const activeLang = translocoService.getActiveLang();
    console.log(activeLang);
  }
}
```

***

## **`setActiveLang()`**

Sets the active language for the application.

```typescript
app.component.ts
export class AppComponent {
  constructor(private translocoService: TranslocoService) {
    translocoService.setActiveLang('es');
  }
}
```

***

## **`getAvailableLangs()`**

Retrieves the list of available languages.

```typescript
app.component.ts
export class AppComponent {
  constructor(private translocoService: TranslocoService) {
    const availableLangs = translocoService.getAvailableLangs();
    console.log(availableLangs);
  }
}
```

***

## **`setFallbackLangForMissingTranslation()`**

Defines a fallback language to be used when a translation key is missing for the active language.

```typescript
app.component.ts
export class AppComponent {
  constructor(private translocoService: TranslocoService) {
    translocoService.setFallbackLangForMissingTranslation({
      fallbackLang: 'he',
    });
  }
}
```

{% hint style="info" %}
**Note**\
If you provide an array, only the first language is used. Fallback translations for missing keys support a single language.
{% endhint %}

***

## **`setAvailableLangs()`**

Sets the list of available languages.

```typescript
app.component.ts
export class AppComponent {
  constructor(private translocoService: TranslocoService) {
    translocoService.setAvailableLangs(['en', 'es']);

    // Alternatively, use an array of objects for additional metadata
    translocoService.setAvailableLangs([{ id: 'en', label: 'English' }]);
  }
}
```

***

## **`langChanges$`**

An observable that emits whenever the active language changes.

```typescript
app.component.ts
export class AppComponent {
  constructor(private translocoService: TranslocoService) {
    translocoService.langChanges$.subscribe(lang => {
      console.log(`Language changed to: ${lang}`);
    });
  }
}
```

{% hint style="info" %}
**Note**\
`langChanges$` will emit the currently active language immediately upon subscription.
{% endhint %}

***

## **`load()`**

Loads the specified language and adds it to the service.

```typescript
app.component.ts
export class AppComponent {
  constructor(private translocoService: TranslocoService) {
    translocoService.load('en').subscribe(() => {
      console.log('Language loaded successfully');
    });
  }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://jsverse.gitbook.io/transloco/core-concepts/language-api.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
