PHPackages                             tourze/gb-t-4880 - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. tourze/gb-t-4880

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

tourze/gb-t-4880
================

GB/T 4880 中国国家标准语言代码库

0.0.1(11mo ago)10MITPHPPHP ^8.1CI passing

Since May 29Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/tourze/gb-t-4880)[ Packagist](https://packagist.org/packages/tourze/gb-t-4880)[ RSS](/packages/tourze-gb-t-4880/feed)WikiDiscussions master Synced 1mo ago

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

GB/T 4880
=========

[](#gbt-4880)

[English](README.md) | [中文](README.zh-CN.md)

[![Latest Version](https://camo.githubusercontent.com/348d2798bcfe0f9e59d9aff1bee642767caaebf1c27381c2c26e4e55157c7fec/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f67622d742d343838302e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/gb-t-4880)[![PHP Version](https://camo.githubusercontent.com/8b7b8855da17cb8ce42710c94f0c478d553d2a1c6dd44dc27c0abd5c1fb7d03f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f75727a652f67622d742d343838302e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/gb-t-4880)[![License](https://camo.githubusercontent.com/294139631fbb46431cfac4f0f7b1d721071054b3e6a99b5b1854cc565f76a79a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f75727a652f67622d742d343838302e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/gb-t-4880)[![Build Status](https://camo.githubusercontent.com/e6bba0c0da3b46b5e67ed19234d55c9b5fcc0de36169dd898e0a1d7bc7aa9be9/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f746f75727a652f67622d742d343838302f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/tourze/gb-t-4880)[![Quality Score](https://camo.githubusercontent.com/2cae247f39e7d3876bd7d0fe931c4313e74c0de536bf6fb74b198af5e9bea79e/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f746f75727a652f67622d742d343838302e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/tourze/gb-t-4880)[![Code Coverage](https://camo.githubusercontent.com/887361f7bbc8f5b54bb0ccf63be824c338acbeecbc2d59e5898b1a48e1d4a524/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f746f75727a652f67622d742d343838302e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/tourze/gb-t-4880)[![Total Downloads](https://camo.githubusercontent.com/71da1b5093290ab3884585399e73018704ff7b284af217eaf372df5103d62c3c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f75727a652f67622d742d343838302e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/gb-t-4880)

GB/T 4880 is a PHP package implementing the GB/T 4880.1-2005 language code standard. It provides a comprehensive enum class containing all two-letter language codes defined by the standard, along with their corresponding Chinese labels.

This package is designed for applications that need to work with language codes according to Chinese national standards, offering both the ISO 639-1 compatible codes and localized Chinese names.

Features
--------

[](#features)

- **Standards Compliant**: Implements the GB/T 4880.1-2005 standard
- **Comprehensive**: Provides 180+ two-letter language codes
- **Localized**: Includes corresponding Chinese labels for all languages
- **Modern PHP**: Utilizes PHP 8.1+ enum features with strict typing
- **Framework Ready**: Implements `Labelable`, `Itemable`, and `Selectable` interfaces for easy integration
- **Select Options**: Built-in support for generating select/dropdown options
- **Type Safety**: Full type safety with enum-based implementation

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

[](#requirements)

- PHP 8.1 or higher
- [tourze/enum-extra](https://packagist.org/packages/tourze/enum-extra)

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

[](#installation)

```
composer require tourze/gb-t-4880
```

Quick Start
-----------

[](#quick-start)

### Basic Usage

[](#basic-usage)

```
use Tourze\GBT4880\Alpha2Code;

// Get language code
$code = Alpha2Code::Chinese->value; // 'zh'

// Get Chinese label
$name = Alpha2Code::Chinese->getLabel(); // '汉语'

// Check if languages are the same
$isSame = Alpha2Code::Chinese === Alpha2Code::from('zh'); // true
```

### Advanced Usage

[](#advanced-usage)

```
// Create from string code
$language = Alpha2Code::from('en');
echo $language->getLabel(); // '英语'

// Safe creation (returns null for invalid codes)
$language = Alpha2Code::tryFrom('invalid');
if ($language === null) {
    echo "Invalid language code";
}

// Generate options for select elements
$options = Alpha2Code::genOptions();
// Returns: [['value' => 'zh', 'label' => '汉语'], ...]

// Convert to array
$data = Alpha2Code::French->toArray();
// Returns: ['value' => 'fr', 'label' => '法语']

// Convert to select item
$item = Alpha2Code::German->toSelectItem();
// Returns: ['value' => 'de', 'label' => '德语']
```

### Working with All Languages

[](#working-with-all-languages)

```
// Get all language codes
foreach (Alpha2Code::cases() as $language) {
    echo $language->value . ' => ' . $language->getLabel() . PHP_EOL;
}

// Filter languages (example: find all languages containing '语')
$languages = array_filter(Alpha2Code::cases(), function($lang) {
    return str_contains($lang->getLabel(), '语');
});
```

API Reference
-------------

[](#api-reference)

### Core Methods

[](#core-methods)

- `Alpha2Code::from(string $value): Alpha2Code` - Create enum instance from language code
- `Alpha2Code::tryFrom(string $value): ?Alpha2Code` - Safe creation, returns null for invalid codes
- `getLabel(): string` - Get the Chinese label for the language
- `cases(): array` - Get all available language codes

### Interface Methods

[](#interface-methods)

- `toArray(): array` - Convert to associative array with 'value' and 'label' keys
- `toSelectItem(): array` - Alias for toArray(), useful for form select options
- `genOptions(): array` - Generate array of all languages as select options

### Special Cases

[](#special-cases)

- Most language codes follow the ISO 639-1 standard (2 letters)
- Exception: Montenegrin uses 'cnr' (3 letters) as defined by GB/T 4880.1-2005
- All 180+ languages defined by the standard are included

Integration
-----------

[](#integration)

This package is designed to work seamlessly with the `tourze/enum-extra` ecosystem:

```
// Works with form builders
$selectOptions = Alpha2Code::genOptions();

// Works with validation
$isValid = Alpha2Code::tryFrom($userInput) !== null;

// Works with serialization
$jsonData = json_encode(Alpha2Code::Chinese->toArray());
```

Testing
-------

[](#testing)

```
# Run tests
composer test

# Run with coverage
composer test -- --coverage-text

# Run PHPStan analysis
composer phpstan
```

Contributing
------------

[](#contributing)

- Issues and PRs are welcome
- Please follow PSR-12 coding standards
- Ensure all tests pass before submitting
- Add tests for new features
- Update documentation when needed

Standards Reference
-------------------

[](#standards-reference)

- [GB/T 4880.1-2005 Standard](https://github.com/Haixing-Hu/typesetting-standard/blob/master/%E8%AF%AD%E7%A7%8D%E5%8F%8A%E6%9C%89%E5%85%B3%E4%BB%A3%E7%A0%81/%E3%80%90GB%3AT%204880.1-2005%E3%80%91%E4%BF%A1%E6%81%AF%E4%B8%8E%E6%96%87%E7%8C%AE%20%E4%B9%A6%E7%9B%AE%E6%95%B0%E6%8D%AE%E5%85%83%E7%9B%AE%E5%BD%95%20%E7%AC%AC1%E9%83%A8%E5%88%86%EF%BC%9A2%E5%AD%97%E6%AF%8D%E4%BB%A3%E7%A0%81.pdf)Information and documentation -- Bibliographic data element directory -- Part 1: 2-letter codes
- [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) - Codes for the representation of names of languages

License
-------

[](#license)

MIT

Author
------

[](#author)

tourze

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance61

Regular maintenance activity

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity35

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

348d ago

### Community

Maintainers

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

---

Top Contributors

[![tourze](https://avatars.githubusercontent.com/u/13899502?v=4)](https://github.com/tourze "tourze (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-gb-t-4880/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-gb-t-4880/health.svg)](https://phpackages.com/packages/tourze-gb-t-4880)
```

PHPackages © 2026

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