PHPackages                             benmorel/languagelayer - 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. benmorel/languagelayer

AbandonedArchivedLibrary[API Development](/categories/api)

benmorel/languagelayer
======================

LanguageLayer API client for PHP

0.1.3(5y ago)0360MITPHPPHP &gt;=7.1

Since Aug 25Pushed 5y ago1 watchersCompare

[ Source](https://github.com/BenMorel/LanguageLayer)[ Packagist](https://packagist.org/packages/benmorel/languagelayer)[ RSS](/packages/benmorel-languagelayer/feed)WikiDiscussions master Synced yesterday

READMEChangelog (4)Dependencies (1)Versions (5)Used By (0)

LanguageLayer API client for PHP
================================

[](#languagelayer-api-client-for-php)

Perform language detection in PHP using the [LanguageLayer](https://languagelayer.com/) API.

[![Latest Stable Version](https://camo.githubusercontent.com/a8d09d3da039a16dc4611484c72f95ba612580419db8558bf71507cd7fd27b55/68747470733a2f2f706f7365722e707567782e6f72672f62656e6d6f72656c2f6c616e67756167656c617965722f762f737461626c65)](https://packagist.org/packages/benmorel/languagelayer)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](http://opensource.org/licenses/MIT)

**Note: LanguageLayer is not being maintained anymore, and API calls started failing as of November 2020. This library is therefore archived.**

Installation
------------

[](#installation)

This library is installable via [Composer](https://getcomposer.org/):

```
composer require benmorel/languagelayer
```

Requirements
------------

[](#requirements)

This library requires PHP 7.1 or later.

Quickstart
----------

[](#quickstart)

You need a free API key from LanguageLayer to get started.

Just instantiate the LanguageLayer client, and start detecting:

```
use BenMorel\LanguageLayer\LanguageLayerClient;

$client = new LanguageLayerClient('YOUR API KEY');

$results = $client->detectLanguages('Some text. Try more than a few words for accurate detection.');

foreach ($results as $result) {
    if ($result->isReliableResult()) {
        echo $result->getLanguageCode();
    }
}
```

The `detectLanguages()` method returns an array of [LanguageDetectionResult](https://github.com/BenMorel/LanguageLayer/blob/0.1.0/src/LanguageDetectionResult.php) objects, that you can inspect to decide what to do with each detected language.

### Using https

[](#using-https)

You can use the API over a secure connection, if you have a paid plan that supports it:

```
$client = new LanguageLayerClient('YOUR API KEY', true);

```

### Detecting a single language

[](#detecting-a-single-language)

As a convenience, the `detectLanguage()` method helps you detect a single language from a text:

```
$languageCode = $client->detectLanguage('Some text. Try more than a few words for accurate detection.');
```

This method loops through the results to find a single *reliable* result. If it there is no reliable result, but the API returned a single result, it will also accept it, unless the second parameter, `$forceReliable`, is set to true:

```
$languageCode = $client->detectLanguage('...', true); // will not accept a single result, if not "reliable"

```

If no single, acceptable result is found, a [LanguageDetectionException](https://github.com/BenMorel/LanguageLayer/blob/0.1.0/src/LanguageDetectionException.php) is thrown.

### Error handling

[](#error-handling)

Any kind of error—an HTTP error, an error returned by the API, or any other kind of error related to this library—throws a `LanguageDetectionException`.

Therefore you should wrap all your `detectLanguage()` and `detectLanguages()` calls in a `try`/`catch` block:

```
use BenMorel\LanguageLayer\LanguageDetectionException;

// …

try {
    $languageCode = $client->detectLanguage('...');
catch (LanguageDetectionException $exception) {
    // deal with it.
}
```

If the exception was caused by an HTTP error, you can inspect the underlying [Guzzle](http://docs.guzzlephp.org) exception by calling `$exception->getPrevious()` if needed.

If the exception was caused by an error returned by the LanguageLayer API itself, you can inspect it, in addition to the exception message, with `$exception->getCode()` and [$exception-&gt;getType()](https://github.com/BenMorel/LanguageLayer/blob/0.1.0/src/LanguageDetectionException.php#L98).

You can, for example, act upon specific API errors:

```
try {
    $languageCode = $client->detectLanguage('...');
} catch (LanguageDetectionException $exception) {
    switch ($exception->getType()) {
        case 'invalid_access_key':
        case 'usage_limit_reached':
            // report the error!
            break;

        case 'rate_limit_reached':
            // slow down!

        // ...
    }
}
```

Note: if the exception was not caused by an error returned by the API itself, `getType()` will return `null`.

See the [LanguageLayer documentation](https://languagelayer.com/documentation#error_codes) for a list of error codes and types.

###  Health Score

25

—

LowBetter than 36% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~241 days

Total

4

Last Release

2140d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/57189121968030f0770811b461cc92f9c19c08f5c4767292f2ede48b7277cfad?d=identicon)[BenMorel](/maintainers/BenMorel)

---

Top Contributors

[![BenMorel](https://avatars.githubusercontent.com/u/1952838?v=4)](https://github.com/BenMorel "BenMorel (20 commits)")

---

Tags

api-clientlanguage-detectionphplanguage detectionAPILayerLanguageLayer

### Embed Badge

![Health badge](/badges/benmorel-languagelayer/health.svg)

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

###  Alternatives

[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3661.2M46](/packages/tencentcloud-tencentcloud-sdk-php)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k496.1k33](/packages/neuron-core-neuron-ai)[avalara/avataxclient

Client library for Avalara's AvaTax suite of business tax calculation and processing services. Uses the REST v2 API.

528.3M7](/packages/avalara-avataxclient)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

252.5k](/packages/eslazarev-wildberries-sdk)[files.com/files-php-sdk

Files.com PHP SDK

2478.1k](/packages/filescom-files-php-sdk)[aimeos/prisma

A powerful PHP package for integrating media related Large Language Models (LLMs) into your applications

1942.4k4](/packages/aimeos-prisma)

PHPackages © 2026

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