Countries

关于每个国家的各种有用信息都被包装成方便的小国家对象。它包括 ISO 3166(国家和州/分区)、ISO 4217(货币)和 E.164(电话号码)的数据。「All sorts of useful information about every country packaged as convenient little country objects. It includes data from ISO 3166 (countries and states/subdivisions ), ISO 4217 (currency), and E.164 (phone numbers).」

Github stars Tracking Chart

Countries

Countries is a collection of all sorts of useful information for every country in the ISO 3166 standard. It contains info for the following standards ISO3166-1 (countries), ISO3166-2 (states/subdivisions), ISO4217 (currency) and E.164 (phone numbers). I will add any country based data I can get access to. I hope this to be a repository for all country based information.

Gem Version Build Status Code Climate

Installation

gem install countries

Or you can install via Bundler if you are using Rails. Add this line to your application's Gemfile:

gem 'countries'

And then execute:

$ bundle

Basic Usage

Simply load a new country object using Country.new(alpha2) or the shortcut Country[alpha2]. An example works best.

c = ISO3166::Country.new('US')

Configuration

Country Helper

Some apps might not want to constantly call ISO3166::Country this gem has a
helper that can provide a Country class

# With global Country Helper
c = Country['US']

This will conflict with any existing Country constant

To Use

gem 'countries', require: 'countries/global'

Upgrading to 3.x

We dropped currency support via money by default, see instructions if you are using currency featues

Upgrading Country Helper to > 1.2.0

gem 'countries', require: 'global'

has become

gem 'countries', require: 'countries/global'

Selective Loading of Locales

As of 2.0 you can selectively load locales to reduce memory usage in production.

By default we load I18n.available_locales if I18n is present, otherwise only [:en]. This means almost any rails environment will only bring in its supported translations.

You can add all the locales like this.

ISO3166.configure do

Main metrics

Overview
Name With Ownercountries/countries
Primary LanguageRuby
Program languageRuby (Language Count: 1)
PlatformLinux, Mac, Windows
License:MIT License
所有者活动
Created At2009-12-18 22:42:26
Pushed At2025-06-04 09:08:04
Last Commit At2025-06-02 14:33:23
Release Count108
Last Release Namev8.0.2 (Posted on )
First Release Namev0.1.0 (Posted on )
用户参与
Stargazers Count2.3k
Watchers Count38
Fork Count675
Commits Count1.8k
Has Issues Enabled
Issues Count310
Issue Open Count22
Pull Requests Count501
Pull Requests Open Count5
Pull Requests Close Count101
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private