PHPackages                             tourze/gb-t-3304 - 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-3304

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

tourze/gb-t-3304
================

PHP 8.1+ implementation of GB/T 3304-1991 standard - Chinese nationalities with numeric and alpha codes

0.0.3(11mo ago)07MITPHPPHP ^8.1CI passing

Since Mar 24Pushed 6mo ago1 watchersCompare

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

READMEChangelog (3)Dependencies (3)Versions (4)Used By (0)

GB/T 3304
=========

[](#gbt-3304)

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

[![Latest Version](https://camo.githubusercontent.com/5cb98d3f90ed8d9643576663027b51b415f18c27ca9724413e4ddd620ef0155d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f67622d742d333330342e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/gb-t-3304)[![Build Status](https://github.com/tourze/gb-t-3304/actions/workflows/ci.yml/badge.svg)](https://github.com/tourze/gb-t-3304/actions)[![Quality Score](https://camo.githubusercontent.com/c02421393c16fda8889001eefb36b542930586f9ce642fd384bce00d8bf91216/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f746f75727a652f67622d742d333330342e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/tourze/gb-t-3304)[![Total Downloads](https://camo.githubusercontent.com/037dd0fee394f411829d9bbdb819df14f30ca8178bc7f49a19b5279402701d63/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f75727a652f67622d742d333330342e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/gb-t-3304)[![PHP Version Require](https://camo.githubusercontent.com/b94fbb0896c43a4a506a2aef4db6bf4c942d8bf144254ea22b756298a5a91c5d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f75727a652f67622d742d333330342e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/gb-t-3304)[![Coverage Status](https://camo.githubusercontent.com/994d68acb2aadf1c3c7711ddcb3b30429246a6c05da9e601f62c3f932ac795a8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/tourze/gb-t-3304)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)

Introduction
------------

[](#introduction)

This package implements the GB/T 3304-1991 standard "Names of nationalities of China in romanization with codes" as a type-safe PHP 8.1+ enum. It provides both numeric (01-56) and two-letter (HA-JN) codes for all 56 officially recognized Chinese ethnic groups, with convenient integration interfaces for modern PHP applications.

Overview
--------

[](#overview)

GB/T 3304-1991 is a Chinese national standard that defines the romanization and coding system for Chinese ethnic groups. This package provides a modern PHP implementation using enums, making it easy to work with Chinese nationality data in a type-safe manner.

Features
--------

[](#features)

- **Complete Coverage**: All 56 officially recognized Chinese ethnic groups
- **Dual Coding System**: Both numeric codes (01-56) and two-letter codes (HA-JN)
- **Type Safety**: Modern PHP 8.1+ enum implementation
- **Easy Integration**: Implements `Labelable`, `Itemable`, and `Selectable` interfaces
- **Clean API**: Simple methods for code, label, and mapping conversion
- **Well Tested**: Comprehensive PHPUnit test suite with 100% coverage
- **Standards Compliant**: Follows GB/T 3304-1991 specification exactly

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

[](#installation)

**Requirements:**

- PHP &gt;= 8.1
- Composer
- Dependency: `tourze/enum-extra ~0.1.0`

**Install via Composer:**

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

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

[](#quick-start)

```
use Tourze\GBT3304\Nationality;

// Get numeric code
$code = Nationality::Han->value; // "01"

// Get Chinese label
$label = Nationality::Han->getLabel(); // "汉族"

// Get two-letter code
$alphaCode = Nationality::Han->toCode(); // "HA"
```

Advanced Usage
--------------

[](#advanced-usage)

### Getting All Nationalities

[](#getting-all-nationalities)

```
// Get all nationality options for forms/selects
$options = Nationality::getSelectOptions();
// Returns: ['01' => '汉族', '02' => '蒙古族', ...]

// Get as items for API responses
$items = Nationality::getItems();
// Returns: [['value' => '01', 'label' => '汉族'], ...]
```

### Finding by Code

[](#finding-by-code)

```
// From numeric code
$nationality = Nationality::from('01'); // Han

// From alpha code (you'll need to implement this if needed)
$han = array_search('HA', array_map(fn($n) => $n->toCode(), Nationality::cases()));
```

### Integration with Forms

[](#integration-with-forms)

```
// Symfony forms
$builder->add('nationality', ChoiceType::class, [
    'choices' => Nationality::getSelectOptions(),
]);

// Laravel
Form::select('nationality', Nationality::getSelectOptions());
```

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

[](#api-reference)

### Methods

[](#methods)

- `getLabel(): string` - Returns the Chinese name of the nationality
- `toCode(): string` - Returns the two-letter code
- `value` - The numeric code (01-56)
- `getSelectOptions(): array` - Returns all options for dropdowns
- `getItems(): array` - Returns all items for API responses

### Interfaces

[](#interfaces)

- `Labelable` - Provides `getLabel()` method
- `Itemable` - Provides `getItems()` static method
- `Selectable` - Provides `getSelectOptions()` static method

Development
-----------

[](#development)

### Running Tests

[](#running-tests)

```
# Run all tests
composer test

# Run with coverage
composer test-coverage

# Run PHPStan
composer analyse
```

### Code Quality

[](#code-quality)

This package maintains high code quality standards:

- PHPStan Level 9 (maximum)
- 100% test coverage
- PSR-12 coding standards
- No external dependencies except `tourze/enum-extra`

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

[](#contributing)

Contributions are welcome! Please follow these guidelines:

1. **Issues**: Report bugs or request features via GitHub Issues
2. **Pull Requests**: Fork the repo and submit PRs against the main branch
3. **Code Style**: Follow PSR-12 coding standards
4. **Testing**: Ensure all tests pass and add tests for new features
5. **Documentation**: Update README and docblocks as needed

### Development Setup

[](#development-setup)

```
git clone https://github.com/tourze/gb-t-3304.git
cd gb-t-3304
composer install
composer test
```

License
-------

[](#license)

MIT License. See [LICENSE](LICENSE) for details.

Related Standards
-----------------

[](#related-standards)

- [GB/T 3304-1991](https://openstd.samr.gov.cn/bzgk/gb/newGbInfo?hcno=E5C3271B62636C5DA6853A0DA23EBBA9) - Official standard document
- [ISO 639](https://www.iso.org/iso-639-language-codes.html) - Language codes standard
- [ISO 3166](https://www.iso.org/iso-3166-country-codes.html) - Country codes standard

Security
--------

[](#security)

If you discover any security-related issues, please email  instead of using the issue tracker.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance61

Regular maintenance activity

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity38

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

Every ~33 days

Total

3

Last Release

349d 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 (2 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

PHPackages © 2026

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