> ## Documentation Index
> Fetch the complete documentation index at: https://docs.locadapt.com/llms.txt
> Use this file to discover all available pages before exploring further.

# API Reference

> Programmatically interact with Locadapt using the `window.locadapt` object

Locadapt exposes a `window.locadapt` object that allows developers to programmatically interact with the translation functionality. This API reference outlines the main methods and properties available for advanced usage and integration.

<Warning>
  Locadapt is optimized to work out-of-the box, and only call or rewrite these methods when necessary for advanced or bespoke functionality.
</Warning>

## Main Methods

### `updateContent()`

Manually triggers a content update, translating any new or changed content on the page.

```javascript theme={null}
window.locadapt.updateContent();
```

Use this method if Locadapt isn't picking up on new content / the first page render. For example, if you have dynamically updated *text nodes*, you may want to call this (our `mutationObserver` picks up on added nodes, but not text updates by default as for most scenarios this leads to excessive translation requests).

### `figureOutLanguage()`

Detects the current language based on the URL structure.

```javascript theme={null}
const languageInfo = window.locadapt.figureOutLanguage();
```

Returns an array with the language name and its mapping information, or null if not detected.

### `setupCanonicalAndAlternateLinks()`

Updates the canonical and alternate links in the document's head to reflect the current language and available translations.

```javascript theme={null}
window.locadapt.setupCanonicalAndAlternateLinks();
```

This method is automatically called by Locadapt when the language is changed. You could rewrite this method to change the canonical and alternate links in a custom way, or to add additional functionality.

### `toggleSelector()`

Toggles the visibility of the language selector dropdown.

```javascript theme={null}
window.locadapt.toggleSelector();
```

Useful for creating custom language selection interfaces.

### `selectLanguage(code: string, nativeName: string)`

Programmatically changes the current language.

```javascript theme={null}
window.locadapt.selectLanguage('fr', 'Français');
```

Use this to switch languages without user interaction with the default selector.

## Properties

### `currentTranslateToLanguage`

Gets or sets the current target language for translations.

```javascript theme={null}
console.log(window.locadapt.currentTranslateToLanguage);
window.locadapt.currentTranslateToLanguage = 'Español';
```

### `localStorageData`

Provides access to the current Locadapt configuration and translation data.

```javascript theme={null}
const config = window.locadapt.localStorageData;
```

This object contains information about the project settings, available languages, and cached translations. It is a subset of the data stored on Locadapt's servers, and a mirror of the data present in the actual `localStorage` of your site by our plugin.

## Advanced Usage

For more complex integrations or custom behavior, you can also access and modify internal Locadapt properties and methods. However, use these with caution as they may affect the core functionality:

* `applyTranslations(translations: Map<string, { originalText: string; translatedText: string; }>)`
* `collectTranslatableContent()`
* `sendTranslationRequest(items: TranslationItem[])`

Refer to the `window.locadapt` object or <a href="mailto:support@locadapt.com" target="_blank">contact us</a> for detailed information on these advanced methods.

<Warning>
  Modifying internal Locadapt functionality may lead to unexpected behavior. Always test thoroughly when using these advanced methods.
</Warning>
