A Java library that provides country data and flag resources from 1900 until today.
Includes ISO 3166-1 countries, UK countries (ISO 3166-2:GB), and selected historical countries without ISO codes.
Sources:
- ISO 3166-1 alpha-2
- ISO 3166-2:GB
- Flag files are from Wikipedia (public domain).
This library allows you to:
- Access all countries by ISO code.
- Get country names in different locales.
- Retrieve historical country names and intervals.
- Get SVG content of country flags.
- Configure native country and custom properties.
If a translation is not available for a selected Locale, the English name is used as a fallback.
One country is marked as native (default: your system locale), configurable via Country.properties.
Java 8or higherMavenfor dependency management
Add the following to your pom.xml:
<dependency>
<groupId>se.ergot</groupId>
<artifactId>country</artifactId>
<version>2.0.2</version>
</dependency>- Location:
src/main/resources/config/countries/ - File format:
CountryNames_<language-code>.propertiesExample for French:CountryNames_fr.properties
Note: Translations are not accumulative - a new file replaces the previous translations.
- Location:
src/main/resources/config/countries/ - File format:
Country.<key>.propertiesExample: Country.fifa.properties for FIFA codes
Note: Custom property files are accumulative — multiple files can be combined.
Set the native country in Country.properties: country.native=SE
Location: src/main/resources/se/ergot/country/flags/
File naming convention:
<iso>.svg- current flag<iso>_<endYear>.svg- historical flags
All countries are accessed from the Country enum via their ISO code.
Example:
final Country sweden = Country.SE;
// Get country name
String name = sweden.getName(); // Default locale
String nameEN = sweden.getName(Locale.ENGLISH); // English
// Get flag SVG content
String flagSvg = sweden.getFlagSvg();
// Get all flags
List<CountryFlag> flags = sweden.getAllFlags();
// Check historical independence or relations at a specific year
boolean independent1997 = Country.EE.independentAtYear(Year.of(1997));
boolean partOfRU1907 = Country.EE.partOfAtYear(Country.RU, Year.of(1907));
boolean belongsToGB1977 = Country.DM.belongsToAtYear(Country.GB, Year.of(1977));
// Get all administering countries at a year (supports condominiums with multiple countries)
List<Country> rulers = Country.VU.getBelongsToAtYear(Year.of(1970)); // [GB, FR]
// Get the nature of the dependency relationship
BelongsToVariant variant = Country.NO.getBelongsToVariantAtYear(Year.of(1900)); // PERSONAL_UNION
BelongsToVariant variant = Country.DM.getBelongsToVariantAtYear(Year.of(1977)); // COLONY
// Get country by its iso code
Country congo = Country.find("CD");
String congoName = congo.getName(Locale.ENGLISH);
// Find country by previous ISO code
Country yugoslavia = Country.find("YU");
// Get previous names
Map<Year, String> previousNames = Country.CD.getPreviousNames(Locale.ENGLISH);
// Get country properties
String fifaCode = Country.SE.getValue("fifa");Some codes clash or are not standard ISO 3166-1:
| Country | Code | Notes |
|---|---|---|
| Czechoslovakia | CSHH | ISO code CS clashes with Serbia & Montenegro |
| Ottoman Empire | OE_X | No ISO 3166-1 code |
| Zanzibar | TZ_Z | No ISO 3166-1 code |
| Korean Empire (-1910) | KR_X | No ISO 3166-1 code |
The belongsTo field on a country interval describes that the country was under the authority of one or more other countries during that period. It is a list of ISO codes to support cases where multiple powers jointly administered a territory (condominiums).
The optional variant field classifies the nature of the relationship:
| Variant | JSON value | Description | Example |
|---|---|---|---|
COLONY |
colony |
Direct colonial administration | Lesotho → GB |
PROTECTORATE |
protectorate |
External power controls foreign affairs/defence; local governance continues | Kuwait → GB |
MANDATE |
mandate |
League of Nations mandate or UN Trust Territory | Iraq → GB |
PERSONAL_UNION |
personalUnion |
Sovereign states sharing a monarch, each with their own government | Norway → SE |
CONDOMINIUM |
condominium |
Joint administration by two or more powers | Vanuatu → GB + FR |
ASSOCIATED_STATE |
associatedState |
Self-governing state in free association | Cook Islands → NZ |
OCCUPIED_TERRITORY |
occupiedTerritory |
De facto administration without recognised sovereignty | Western Sahara → MA |
A null variant means no classification has been assigned (e.g. territories with a unique legal status).
Licensed under the Apache License, Version 2.0.