5 个版本
| 0.1.5 | 2022 年 12 月 25 日 |
|---|---|
| 0.1.4 | 2022 年 12 月 23 日 |
| 0.1.3 | 2022 年 12 月 9 日 |
| 0.1.2 | 2022 年 12 月 8 日 |
| 0.1.0 | 2022 年 12 月 7 日 |
#68 在 国际化 (i18n)
3,671 每月下载量
用于 6 crates
580KB
1K SLoC
包 codes-iso-3166
本包包含 ISO 3166 第 1 部和第 2 部标准的实现。
ISO 3166 的目的是定义国际上公认的字母和/或数字代码,当我们在提及国家和它们的次级单位时可以使用。然而,它并不定义国家的名称——这些信息来自联合国来源(联合国统计局维护的术语公报国家名称和用于统计的国家和地区代码)。
国家代码可以用两种字母代码(alpha-2)表示,这是推荐用作通用代码,三个字母代码(alpha-3)与国家名称更为接近,以及三个数字代码(numeric-3),如果需要避免使用拉丁字母,这可能很有用。
本包不包括第 3 部分,即 废弃国家名称代码 的实现。
有关 API 设计的说明,请参阅仓库 README。
示例
此示例展示了第 1 部分 国家代码的使用。
use codes_iso_3166::part_1::CountryCode;
let country = CountryCode::from_str("AG").unwrap();
assert_eq!(country.alpha_2_code(), "AG");
assert_eq!(country.short_name(), "Antigua and Barbuda");
功能
默认情况下,仅启用 serde 功能,并启用第 1 部两种字母语言代码。
serde- 启用不同语言代码类型的序列化。alpha_3_code- 添加CountryCode::alpha_3_code方法。numeric_code- 添加CountryCode::numeric_code方法。independent- 添加CountryCode::independent方法。status- 添加CountryCode::status方法。full_name- 添加CountryCode::full_name方法。local_names- 添加了CountryCode::local_short_name和CountryCode::local_full_name方法。languages- 添加了CountryCode::administrative_language和CountryCode::languages方法(需要包codes-iso-639)。formerly- 添加了CountryCode::former_short_name和CountryCode::former_alpha_3_code方法。part_2- 添加相应的模块和SubdivisionCode。categories- 添加了SubdivisionCode::category_code方法和SubdivisionCategoryCode类型。territories- 添加了TerritoryCode类型。languages- 添加了SubdivisionCode::name_language方法。
注意,方法 CountryCode::local_full_name 需要同时具备 local_names 和 full_name 功能。
刷新
虽然 ISO 免费许可 3166 表,但整个数据表可通过订阅访问,因此目前还没有定期下载表以保持更新的方法。
变更
版本 0.1.5
- 为 codes-common 中的新
build模块提供支持。
版本 0.1.4
- 实现了
Standardized和FixedLengthCode特性。 - 使用新的
codes-commonCSV 处理框架。
版本 0.1.3
- 在第二部分使用新的枚举风格为类别和领土提供支持。
版本 0.1.2
- 为所有相关类型添加了
ALL_CODES常量。 - 在第一部分和第二部分添加了
indices模块,部分实现。
版本 0.1.1
- 在第一部分添加了
formerly_alpha_3_code和formerly_short_name方法。 - 在第一部分添加了
local_short_name和local_full_name方法。 - 添加了部分-2。
版本 0.1.0
- 初始版本,仅包含部分-1。
待办事项
- 使用行政语言将 local_name 添加到次级类别。
- 为二级代码查找构建真正的索引。
依赖关系
~0.4–2.8MB
~44K SLoC