PHPackages                             qpfsoft/lang - 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. [Localization &amp; i18n](/categories/localization)
4. /
5. qpfsoft/lang

ActiveLibrary[Localization &amp; i18n](/categories/localization)

qpfsoft/lang
============

Language

v1.1(6y ago)0201Apache-2.0PHPPHP &gt;=5.6

Since May 6Pushed 6y agoCompare

[ Source](https://github.com/qpfsoft/lang)[ Packagist](https://packagist.org/packages/qpfsoft/lang)[ RSS](/packages/qpfsoft-lang/feed)WikiDiscussions master Synced 2d ago

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

lang
====

[](#lang)

language translation

多语言
---

[](#多语言)

网站多语言, 一般采用语句标识映射一句消息.

```
# en
[
     'welcome' => 'Hello {:name}, nice to meet you!',
]

# zh
[
    'welcome' => '你好 {:name}, 见到你很高兴!',
]
```

根据语言类型, 分包映射对应的语言消息.

目录结构
----

[](#目录结构)

```
/root
   |- langs
   |    |- zh-cn
   |    |   |- simple
   |    |   |- precision
   |    |- en-us
   |    |   |- simple
   |    |   |- precision
```

可将语言包按类别划分, 这样可根据app或class获取自身需要的语言. 不会一次加载所有语言消息.

示例
--

[](#示例)

### 翻译语言

[](#翻译语言)

```
// simple 对应 @root/langs/zh-cn/simple.php 语言包
$lang->translate('simple', 'welcome', ['name'=>'qpf'], 'en-us'); // 'Hello qpf, nice to meet you!'
$lang->translate('simple', 'welcome', ['name'=>'qpf'], 'zh-cn'); // '你好 qpf, 见到你很高兴!'
$lang->translate('simple', 'welcome', ['name'=>'qpf']); // 可通过设置首选语言类型, 或客户端语言类型检查后, 可忽略
```

其它
--

[](#其它)

请自行查看`tests`目录内示例.

翻译词典
----

[](#翻译词典)

网站多语言, 使用语言标记的好处是, 不用做词库(词库size很大), 翻译的语句更准确!

不过还是提供了 词典语言包, 以英文单词为基准, 直接替换翻译, 词典不知道的单词, 将原样返回.

由于语法顺序问题, 也可使用短语, 但建议依赖单词, 而不是短语.

词典语言包格式:

- 短语与单词定义不区分大小写

```
[
    'phrase'    => [
        'Phrase is for better translation'  => '短语是为了更好的翻译',
    ],

    'word'      => [
        't' => [
            'translate' => '翻译', // 推荐, 首字母分组
        ],

        'translate' => '翻译', // 若存在首字符分组, 该词将无效

    ],
]
```

### 翻译语句

[](#翻译语句)

词典默认限定为`en-us`语言, 所以当目标语言也是`en-us`时将不会进行翻译!

```
$this->lang->translate('precision', 'translate  ok!', 'zh-cn'); // `翻译  ok!`
$this->lang->translate('precision', 'Phrase is for better translation', 'zh-cn'); // `短语是为了更好的翻译`
$this->lang->translate('precision', 'translate  ok!', 'en-us'); // `translate  ok!`
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity55

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 ~38 days

Total

2

Last Release

2527d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a9237a3c9ea86839919b354957620eecdc9f54a7af2c92e81536d62fba274dc9?d=identicon)[qpfsoft](/maintainers/qpfsoft)

---

Top Contributors

[![qpfsoft](https://avatars.githubusercontent.com/u/49507188?v=4)](https://github.com/qpfsoft "qpfsoft (5 commits)")

### Embed Badge

![Health badge](/badges/qpfsoft-lang/health.svg)

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

###  Alternatives

[symfony/translation

Provides tools to internationalize your application

6.6k836.5M2.1k](/packages/symfony-translation)[nesbot/carbon

An API extension for DateTime that supports 281 different languages.

169661.4M4.8k](/packages/nesbot-carbon)[joedixon/laravel-translation

A tool for managing all of your Laravel translations

717911.4k11](/packages/joedixon-laravel-translation)[illuminate/translation

The Illuminate Translation package.

6936.4M495](/packages/illuminate-translation)[lajax/yii2-translate-manager

Translation management extension for Yii 2

227578.8k13](/packages/lajax-yii2-translate-manager)[larswiegers/laravel-translations-checker

Make sure your laravel translations are checked and are included in all languages.

256423.2k2](/packages/larswiegers-laravel-translations-checker)

PHPackages © 2026

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