PHPackages                             siugnur/whatlang-php - 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. siugnur/whatlang-php

ActiveLibrary

siugnur/whatlang-php
====================

Natural language detection library for PHP

v0.1.0(1mo ago)153↑25%MITPHPPHP &gt;=8.2

Since Jul 16Pushed 1mo agoCompare

[ Source](https://github.com/SIugnur/whatlang-php)[ Packagist](https://packagist.org/packages/siugnur/whatlang-php)[ RSS](/packages/siugnur-whatlang-php/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Whatlang PHP
============

[](#whatlang-php)

基于 [whatlang-rs](https://github.com/greyblake/whatlang-rs) 开发的 PHP 语言检测库，支持检测 **70 种语言** 和 **26 种书写系统**。

[📖 中文文档](./docs/README_zh.md) | [📖 English Documentation](./docs/README_en.md)

---

安装
--

[](#安装)

```
composer require siugnur/whatlang-php
```

基础用法
----

[](#基础用法)

### 检测语言和书写系统

[](#检测语言和书写系统)

```
use Whatlang\Detector;
use Whatlang\Lang;
use Whatlang\Script;

$detector = Detector::new();

$info = $detector->detect("Hello World");

echo $info->lang();       // Lang::Eng
echo $info->script();     // Script::Latin
echo $info->confidence(); // 1.0
echo $info->isReliable(); // true
```

### 只检测语言

[](#只检测语言)

```
$detector = Detector::new();

$lang = $detector->detectLang("Bonjour le monde");
echo $lang; // Lang::Fra
```

### 只检测书写系统

[](#只检测书写系统)

```
$detector = Detector::new();

$script = $detector->detectScript("Привет мир");
echo $script; // Script::Cyrillic
```

### 使用便捷函数

[](#使用便捷函数)

```
use function Whatlang\{detect, detectLang, detectScript};

$info = detect("こんにちは世界");
echo $info->lang(); // Lang::Jpn

$lang = detectLang("你好世界");
echo $lang; // Lang::Cmn
```

语言过滤
----

[](#语言过滤)

### 只检测指定语言（白名单）

[](#只检测指定语言白名单)

```
$detector = Detector::withAllowlist([Lang::Eng, Lang::Spa, Lang::Fra]);

$lang = $detector->detectLang("Hello World");
// 如果白名单包含 Eng，返回 Eng，否则返回 null
```

### 排除指定语言（黑名单）

[](#排除指定语言黑名单)

```
$detector = Detector::withDenylist([Lang::Jpn, Lang::Kor]);

$lang = $detector->detectLang("こんにちは");
echo $lang; // null (日文被排除)
```

语言信息
----

[](#语言信息)

```
// 获取语言属性
Lang::Eng->code();    // "eng"
Lang::Eng->name();     // "English"
Lang::Eng->engName();  // "English"

// 通过代码获取语言
Lang::fromCode("eng");  // Lang::Eng
Lang::fromCode("zho");  // Lang::Cmn
```

支持的语言
-----

[](#支持的语言)

语言代码语言代码中文zho英语eng俄语rus西班牙语spa法语fra德语deu日语jpn韩语kor阿拉伯语ara印地语hin葡萄牙语por意大利语ita越南语vie土耳其语tur荷兰语nld波兰语pol希腊语ell希伯来语heb波斯语fas泰语tha孟加拉语ben乌克兰语ukr[查看全部 70 种语言...](src/Lang.php)

运行测试
----

[](#运行测试)

```
composer install
./vendor/bin/phpunit
```

License
-------

[](#license)

MIT

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance90

Actively maintained with recent releases

Popularity14

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

46d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/118788017?v=4)[iugnur](/maintainers/SIugnur)[@SIugnur](https://github.com/SIugnur)

---

Top Contributors

[![SIugnur](https://avatars.githubusercontent.com/u/118788017?v=4)](https://github.com/SIugnur "SIugnur (8 commits)")

---

Tags

whatlang

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/siugnur-whatlang-php/health.svg)

```
[![Health](https://phpackages.com/badges/siugnur-whatlang-php/health.svg)](https://phpackages.com/packages/siugnur-whatlang-php)
```

PHPackages © 2026

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