EarthCountriesInfo 10.2.0
dotnet add package EarthCountriesInfo --version 10.2.0
NuGet\Install-Package EarthCountriesInfo -Version 10.2.0
<PackageReference Include="EarthCountriesInfo" Version="10.2.0" />
<PackageVersion Include="EarthCountriesInfo" Version="10.2.0" />
<PackageReference Include="EarthCountriesInfo" />
paket add EarthCountriesInfo --version 10.2.0
#r "nuget: EarthCountriesInfo, 10.2.0"
#:package EarthCountriesInfo@10.2.0
#addin nuget:?package=EarthCountriesInfo&version=10.2.0
#tool nuget:?package=EarthCountriesInfo&version=10.2.0
EarthCountriesInfo
EarthCountriesInfo is an open-source C# class library that provides comprehensive information about countries on planet Earth. Whether you're building educational tools, geographic applications, or simply curious about global diversity, EarthCountriesInfo has you covered!
Features
- Country Names: Retrieve country names in multiple languages.
- Country Phone Codes: Access phone codes for each country.
- Valid Lengths and Formats: Obtain valid phone number lengths and formats (if available).
Where the data comes from
Country names are derived from the Unicode CLDR (version
48.2.1), the same locale data that underpins ICU and the .NET globalization stack. They are
regenerated by tools/GenerateCountryData, which pins the CLDR version in a single constant.
Two caveats worth knowing before you depend on a given value:
- CLDR does not cover every language this library exposes. 23 of the 240
LanguageIdvalues have no CLDR locale at all, and 28 more cover only a handful of territories. For those, the previously curated name is kept rather than blanked, so roughly 2,600 names are not CLDR-derived. - Names are populated for about 84% of country/language pairs. The rest are the empty string,
which means "no translation available" — fall back to another language such as
LanguageId.en.
Phone codes and number formats are not CLDR data; they are maintained in this repository.
CLDR is licensed under Unicode-3.0 — see THIRD-PARTY-NOTICES.md.
Installation
To include EarthCountriesInfo in your project, install the NuGet package:
dotnet add package EarthCountriesInfo
Usage
Country Properties
The CountryProperties class provides essential information for each country:
public sealed record CountryProperties(
IReadOnlyDictionary<LanguageId, string> CountryNames,
string CountryPhoneCode,
IReadOnlyDictionary<int, string>? ValidLengthsAndFormat
);
CountryNames: A dictionary containing country names in various languages. Every supported language is present as a key; where no translation is available the value is an empty string, so treat empty as "unknown" and fall back to another language such asLanguageId.en.CountryPhoneCode: The international phone code for the country, digits only, without a leading+.ValidLengthsAndFormat(optional): Valid phone number lengths mapped to a display format, where each#is one digit.nullwhen unknown.
Example Usage
using EarthCountriesInfo;
using HumanLanguages;
// Get information for a specific country (e.g., INDIA)
if (Countries.CountryPropertiesDictionary.TryGetValue(CountryIsoCode.IN, out CountryProperties? infoAboutIndia))
{
Console.WriteLine($"Country Name (English): {infoAboutIndia.CountryNames[LanguageId.en]}");
Console.WriteLine($"Country Phone Code: +{infoAboutIndia.CountryPhoneCode}");
if (infoAboutIndia.ValidLengthsAndFormat != null)
{
foreach (var (length, format) in infoAboutIndia.ValidLengthsAndFormat)
{
Console.WriteLine($"Valid Length: {length}, Format: {format}");
}
}
}
Contributing
We welcome contributions! If you find a bug, have an idea for improvement, or want to add support for additional countries, please submit an issue or a pull request on GitHub.
Before editing a country name by hand: the names in EarthCountriesInfo/CountryInformation/*.cs
are generated, and a re-run of tools/GenerateCountryData will overwrite anything you change there.
- A name that is wrong in CLDR should be fixed upstream in CLDR; it then arrives here on the next version bump.
- A name for a language CLDR does not cover can be edited in place — the generator keeps existing values when CLDR has nothing.
- A name that should deliberately differ from CLDR belongs in the
EditorialOverridestable intools/GenerateCountryData/Program.cs, with a comment explaining why.
Phone codes and ValidLengthsAndFormat are not generated and can be edited directly.
GitHub Repository
Visit our GitHub repository for the latest updates, documentation, and community contributions: EarthCountriesInfo GitHub Repository
License
This project is licensed under the GNU GENERAL PUBLIC LICENSE.
Happy coding! 🌎🚀📚
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- HumanLanguages (>= 11.0.0)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on EarthCountriesInfo:
| Package | Downloads |
|---|---|
|
GeoIpServices
A C# library that provides geolocation information for IP addresses with MongoDB caching. Wraps third-party IP geolocation services (IpStack) to reduce API usage and costs through intelligent caching and session management. |
|
|
SMSwitch
Package Description |
|
|
StorageConnector
A unified interface for multi-cloud storage operations. StorageConnector provides a consistent abstraction layer for Azure Blob Storage, AWS S3, and Google Cloud Storage with built-in support for pre-signed URLs, geographic routing, and facial recognition integration. |
|
|
UmbCountryPicker
A property editor for Umbraco CMS. It let's you pick a country from a list of countries. |
GitHub repositories
This package is not used by any popular GitHub repositories.