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(7y ago)0201Apache-2.0PHPPHP &gt;=5.6

Since May 6Pushed 7y agoCompare

[ Source](https://github.com/qpfsoft/lang)[ Packagist](https://packagist.org/packages/qpfsoft/lang)[ RSS](/packages/qpfsoft-lang/feed)WikiDiscussions master Synced 2w 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 36% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity56

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

2573d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/49507188?v=4)[qpfsoft](/maintainers/qpfsoft)[@qpfsoft](https://github.com/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

[php-translation/translator

Translator services

25224.8k5](/packages/php-translation-translator)[smmoosavi/php-gettext

Wrapper for php-gettext by danilo segan. This library provides PHP functions to read MO files even when gettext is not compiled in or when appropriate locale is not present on the system.

1926.6k1](/packages/smmoosavi-php-gettext)[laradevs/spanish

labels translated to spanish

166.7k](/packages/laradevs-spanish)

PHPackages © 2026

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