> For the complete documentation index, see [llms.txt](https://ptkyoku.gitbook.io/localflow-translate-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ptkyoku.gitbook.io/localflow-translate-docs/api-reference/function-reference.md).

# Function Reference

The DeepLService class provides methods for translating text, retrieving API usage, and managing DeepL glossaries.

## DeepLService

`DeepLService` provides translation, usage, and glossary operations.

For complete request examples, see the [Usage Guide](/localflow-translate-docs/api-reference/usage-guide.md).

### IsRunning

```csharp
public static bool IsRunning
```

Returns whether any DeepL operation is currently running.

This property returns `true` while a translation, usage request, or glossary request is in progress.

**Returns**

| Type | Description                                                |
| ---- | ---------------------------------------------------------- |
| bool | `true` if any DeepL request is running; otherwise `false`. |

***

### GetUsage

```csharp
Task<UsageResult> GetUsage(string apiKey, Action<float> onProgress = null)
```

Retrieves the current DeepL API character usage.

#### Parameters

| Name       | Description                           |
| ---------- | ------------------------------------- |
| apiKey     | DeepL API key.                        |
| onProgress | Callback that reports progress (0–1). |

#### Returns

Returns a `UsageResult`.

***

### GetGlossary

```csharp
Task<GlossaryResult> GetGlossary(string apiKey, Action<float> onProgress = null)
```

Downloads all available glossaries from the DeepL account.

#### Parameters

| Name       | Description                           |
| ---------- | ------------------------------------- |
| apiKey     | DeepL API key.                        |
| onProgress | Callback that reports progress (0–1). |

#### Returns

Returns a `GlossaryResult`.

***

### GetGlossaryId

```csharp
string GetGlossaryId(string glossaryName, string sourceLang, string targetLang)
```

Returns the glossary ID matching the specified glossary name and language pair.

***

### GetGlossaryName

```csharp
string GetGlossaryName(int index)
```

Returns the glossary name at the specified index.

***

### GetGlossaryNames

```csharp
string[] GetGlossaryNames()
```

Returns all loaded glossary names.

***

### TryGetGlossaryIndex

```csharp
bool TryGetGlossaryIndex(string name, out int index)
```

Attempts to find the index of the specified glossary.

Returns `true` if found.

***

### Translate

The `Translate` method is overloaded to support different translation workflows.

***

#### Single text

```csharp
Task<TranslateResult> Translate(string apiKey, string sourceLang, string targetLang, string text, string glossaryName, Action<string, float> onProgress)
```

Translates a single text string.

***

#### Multiple texts

```csharp
Task<TranslateResult> Translate(string apiKey, string sourceLang, string targetLang, IReadOnlyList<string> texts, string glossaryName, Action<string, float> onProgress)
```

Translates multiple text entries into one target language.

***

#### Multiple target languages

```csharp
Task<TranslateResult> Translate(string apiKey, string sourceLang, IReadOnlyList<string> targetLangs, IReadOnlyList<string> texts, string glossaryName, Action<string, float> onProgress)
```

Translates multiple text entries into multiple target languages in a single request.

The returned `TranslateResult` contains one `TranslateResultItem` for each target language.

***

### ToStatus

```csharp
DeepLStatusCode ToStatus(int code)
```

Converts an HTTP status code into a `DeepLStatusCode`.

***

### Result types

#### TranslateResult

```csharp
public class TranslateResult
```

Represents the result of a translation request.

| Property     | Description                           |
| ------------ | ------------------------------------- |
| statusCode   | Translation status.                   |
| Items        | Collection of translated results.     |
| errorMessage | Error message when the request fails. |

***

#### TranslateResultItem

```csharp
public class TranslateResultItem
```

Represents the translation result for one target language.

| Property       | Description                      |
| -------------- | -------------------------------- |
| TargetLanguage | Target language code.            |
| Texts          | Translated text collection.      |
| errorMessage   | Error message for this language. |

***

#### UsageResult

```csharp
public class UsageResult
```

Represents the result of a usage request.

| Property       | Description                           |
| -------------- | ------------------------------------- |
| statusCode     | Request status.                       |
| characterLimit | Monthly character limit.              |
| characterCount | Characters used.                      |
| errorMessage   | Error message when the request fails. |

***

#### GlossaryResult

```csharp
public class GlossaryResult
```

Represents the result of a glossary request.

| Property     | Description                           |
| ------------ | ------------------------------------- |
| statusCode   | Request status.                       |
| errorMessage | Error message when the request fails. |

***

#### DeepLStatusCode

`DeepLStatusCode` represents the result of a DeepL API request.

It is returned by all API methods and can be used to determine whether the request completed successfully or failed.
