nazariitsubera/country-aliases
Composer 安装命令:
composer require nazariitsubera/country-aliases
包简介
ISO 3166-1 alpha-2 lookup for thousands of dirty country spellings, plus a PHP helper.
README 文档
README
This bundle packages the country alias lookup generated from the GeoNames datasets plus a thin PHP wrapper you can ship as a Composer package.
Structure
data/country_aliases.json– Map{normalized_name: "ISO2"}for every unambiguous alias.data/country_aliases.csv– Two-column CSV (normalized_name,iso2) mirroring the JSON.data/country_aliases_ambiguous.json– Optional file with aliases that match more than one ISO2 code so you can handle them manually.src/– PHP wrapper exposing a simple runtime API.
Regenerate the data by rerunning the build_country_aliases.py script you used earlier (or fetch the latest GeoNames exports, then rebuild using the same normalization logic). The script should still trim, uppercase, strip accents, and ignore alternate names that look like URLs (strings starting with HTTP/HTTPS) so the output only contains actual country spellings. Once regenerated, drop the new files back into data/.
The JSON file is best suited for programmatic use (load once, look up millions of rows in-memory); the CSV is easier to scan manually.
PHP wrapper
The CountryAliasResolver class in src/ loads data/country_aliases.json and exposes a lookup($value) method that returns the ISO2 code (or null when no match exists). Example:
use CountryAliases\CountryAliasResolver; $resolver = new CountryAliasResolver(__DIR__ . '/data/country_aliases.json'); var_dump($resolver->lookup('United States of America')); // "US" var_dump($resolver->lookup(' republic of ireland ')); // "IE"
Drop this repository into a Composer package (e.g., country-aliases/country-aliases), configure PSR-4 autoloading for src/, and you can normalize millions of dirty country strings with a single method call.
nazariitsubera/country-aliases 适用场景与选型建议
nazariitsubera/country-aliases 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 11 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 nazariitsubera/country-aliases 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nazariitsubera/country-aliases 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 35
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-21