PHPackages                             tacman/libretranslate - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. tacman/libretranslate

ActiveLibrary[API Development](/categories/api)

tacman/libretranslate
=====================

PHP interface for the open source LibreTranslate project

2.0.2(1y ago)04131GPL-3.0-or-laterPHPPHP ^8.3

Since Apr 3Pushed 1y agoCompare

[ Source](https://github.com/tacman/libretranslate)[ Packagist](https://packagist.org/packages/tacman/libretranslate)[ RSS](/packages/tacman-libretranslate/feed)WikiDiscussions tac Synced 1mo ago

READMEChangelog (3)Dependencies (4)Versions (12)Used By (1)

libretranslate
==============

[](#libretranslate)

PHP Interface to the open source [LibreTranslate](https://github.com/LibreTranslate/LibreTranslate) project

Install
-------

[](#install)

### Composer (recommended)

[](#composer-recommended)

```
composer require jefs42/libretranslate
```

Local Development
=================

[](#local-development)

```
composer config repositories.libretranslate '{"type": "vcs", "url": "git@github.com:survos/SurvosGridBundle.git"}'

composer config repositories.libretranslate '{"type": "path", "url": "~/g/tacman/libretranslate"}'
composer require tacman/libretranslate:"*@dev"
```

```
require('vendor/autoload.php');

use Jefs42\LibreTranslate;

$translator = new LibreTranslate();
```

### Manual

[](#manual)

Download the LibreTranslate.php file from src/ directory and place somewhere in you project.

Include the file in your project:

```
require_once("path/to/LibreTranslate.php");

use Jefs42\LibreTranslate;

$translator = new LibreTranslate();
```

Usage
-----

[](#usage)

By default, this class will try to connect to and use a local installation of the LibreTranslate server at

Pass *host* and optionally *port*, *source* and/or *target* parameters to override defaults.

```
// use locally installed LibreTranslate server on port 5000 with default language settings
$translator = new LibreTranslate();

// specify server with alternate port
$translator = new LibreTranslate("https://libretranslate", 5042);

// use localhost, default port, but override default languages used in translations
$translator = new LibreTranslate(null, null, 'de', 'it');
```

[LibreTranslate Mirros](https://github.com/LibreTranslate/LibreTranslate#mirrors)

### Set API Key

[](#set-api-key)

Depending on the server settings, you may need to provide a valid API key to make translation request.

```
$translator->setApiKey('xxxxx-xxxxx-xxxxx');
```

### Set Default Languages

[](#set-default-languages)

The default source and target languages are set by the server. You may override these settings when constructing the class, or as needed:

```
// Set to translate from English to Swedish
$translator->setLanguages('en', 'sv');

// change only one - source or target
$translator->setSource('es');

$translator->setTarget('ru');
```

Each translation function also supports specifying the languages to use when calling the function.

---

### Detect Language

[](#detect-language)

LibreTranslate will attempt to determine the language of the string passed to it.

```
$lang = $translator->detect("mi nombre es jefs42");
// expected result: $lang = 'es'
```

### Translate Text

[](#translate-text)

Translate a string of text, or an array of multiple texts. A server may or may not have a character limit set. For larger texts see Translate File.

```
// translate text using current default source/target languages
$translatedText = $translator->translate("My name is jefs42");

// specifally request languages to use in translation.
// eg. from English to German
$translatedText = $translator->translate("My name is jefs42", "en", "de");

// translate multiple texts in one call
// returns array of translated texts
$translatedText = $translator->translate(["My name is jefs42", "Where is the bathroom?"]);
```

### Translate File

[](#translate-file)

Translate a file of text.

Check $translator-&gt;Settings(), current supported formats appear to be - .txt, .odt, .odp, .docx and .pptx

```
// translate file using current default source/target languages
$translatedText = $translator->translateFile("/full/path/to/file.txt");

// translate file with specific source/target languages
// eg. from English to Italian
$translatedText = $translator->translateFile("/full/path/to/file.txt", "en", "it");
```

- Translation server may have max size limits on post/files size.
- Could pass $\_SERVER\['FILES'\]\['formfield'\]\['tmp\_name'\] if using for a web form.

### Suggest

[](#suggest)

Submit a suggested translation to the server.

```
// Submit suggestion using current source/target language
$translator->suggest('My name is jefs42', 'Mi nombre es jefs42');

// Specify languages for suggestion
$translator->suggest('My name is jefs42', 'Mi chiamo jefs42', 'en', 'it');
```

Sugesstions must be enabled on the LibreTranslate server.

---

### Get Available Languages

[](#get-available-languages)

Get the list of languages available on the current server.

```
$languages = $translator->Languages();
/*
Returns array of language codes/names:
[en] => 'English',
[it] => 'Italian',
...
*/
```

### Check Server Settings

[](#check-server-settings)

Get settings current server is running with.

```
$settings = $translator->Settings();
/*
Returns array of settings and their current values:
[api_keys] => 1,
[keyRequired] => ,
[char_limit] => -1,
...
*/
```

See [LibreTranslate Arguments](https://github.com/LibreTranslate/LibreTranslate#arguments) for server settings.

---

LTManage
--------

[](#ltmanage)

If you are running a locally hosted LibreTranslate server, you may have access to `ltmanage`. This allows you to view current keys and their request limits, as well as create new keys and delete current keys.

See [LibreTranslate Manage Keys](https://github.com/LibreTranslate/LibreTranslate#manage-api-keys) for details.

If `ltmanage` is found in the local path then the following additonal functions will be available for use:

### listKeys

[](#listkeys)

Will return an array of current keys and their request limits.

```
$keys = $translator->listKeys();
/*
Returns array of current keys and limits:
[
    'key1' => '500',
    'key2' => '50',
    ...
]
*/
```

### addKey

[](#addkey)

Create a new key for local server with optional request limit.

```
// create a new key limited to server defaults
$key = $translator->addKey();

// create a new key with a specific request limit (higher or lower than server default)
$key = $translator->addKey(400); // limit to 400 requests per minute

/*
Returns string of new key:
"xxxxx-xxxx-xxxx"
*/
```

### removeKey

[](#removekey)

Delete an existing key from the available keys.

```
try {
    $translator->removeKey("xxxxx-xxxxx-xxxxx");
} catch (Exception $e) {
    // key doesn't exist
}
/*
Returns true on deletion
*/
```

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance42

Moderate activity, may be stable

Popularity13

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 60.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~171 days

Recently: every ~249 days

Total

7

Last Release

471d ago

Major Versions

v1.1.2 → 2.0.02025-01-19

PHP version history (3 changes)v1.0.0PHP ^7.2|^8.0

v1.1.2PHP ^7.0|^8.0

2.0.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/21b39551f92ed4143772c622f9e571589c5a72c96ab3c53fe67489ce0d83e806?d=identicon)[tacman1123](/maintainers/tacman1123)

---

Top Contributors

[![jefs42](https://avatars.githubusercontent.com/u/6254923?v=4)](https://github.com/jefs42 "jefs42 (14 commits)")[![tacman](https://avatars.githubusercontent.com/u/619585?v=4)](https://github.com/tacman "tacman (6 commits)")[![arkonisus](https://avatars.githubusercontent.com/u/7242966?v=4)](https://github.com/arkonisus "arkonisus (2 commits)")[![tabuna](https://avatars.githubusercontent.com/u/5102591?v=4)](https://github.com/tabuna "tabuna (1 commits)")

---

Tags

phptranslatelibretranslate

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tacman-libretranslate/health.svg)

```
[![Health](https://phpackages.com/badges/tacman-libretranslate/health.svg)](https://phpackages.com/packages/tacman-libretranslate)
```

###  Alternatives

[deepseek-php/deepseek-php-client

deepseek PHP client is a robust and community-driven PHP client library for seamless integration with the Deepseek API, offering efficient access to advanced AI and data processing capabilities.

47073.9k5](/packages/deepseek-php-deepseek-php-client)[jefs42/libretranslate

PHP interface for the open source LibreTranslate project

3788.2k1](/packages/jefs42-libretranslate)[aurawindsurfing/google-translate

Free Laravel package for Paid Google Translate REST API with your own API key

1119.5k1](/packages/aurawindsurfing-google-translate)[afiqiqmal/malaysiaholiday

to get all holidays date in malaysia

329.0k](/packages/afiqiqmal-malaysiaholiday)[google-gemini-php/symfony

Symfony Bundle for Gemini

149.4k1](/packages/google-gemini-php-symfony)[piteurstudio/satim-php

PHP package to interact with Satim.dz API

321.0k](/packages/piteurstudio-satim-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
