Module:User:Benwing2/place/shared-data

Hello, you have come here looking for the meaning of the word Module:User:Benwing2/place/shared-data. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:User:Benwing2/place/shared-data, but we will also tell you about its etymology, its characteristics and you will know how to say Module:User:Benwing2/place/shared-data in singular and plural. Everything you need to know about the word Module:User:Benwing2/place/shared-data you have here. The definition of the word Module:User:Benwing2/place/shared-data will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:User:Benwing2/place/shared-data, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

This is a private module sandbox of Benwing2, for their own experimentation. Items in this module may be added and removed at Benwing2's discretion; do not rely on this module's stability.


local export = {}
--[=[
This module contains data shared between ] and ].
You must load this module using require(), not using mw.loadData().
]=]

local m_table = require("Module:table")
local topic_cat_utilities_module = "Module:category tree/topic cat/utilities"

-----------------------------------------------------------------------------------
--                              Placetype Tables                                 --
-----------------------------------------------------------------------------------

-- Recognized political and misc. subdivisions. The key is the plural subdivision and the value is the equivalent
-- description, with links. A value of true means to use the default linking algorithm in link_label() in
-- ]. A value of "w" is similar but links to Wikipedia.
export.political_subdivisions = {
	 = true,
	 = true,
	 = true,
	 = true,
	 = true,
	 = "w",
	 = true,
	 = true,
	 = true,
	 = true,
	 = "w",
	 = true,
	 = true,
	 = true,
	 = "w",
	 = true,
	 = true,
	 = true,
	 = true,
	 = true,
	 = true,
	 = true,
	 = true,
	 = true,
	 = true,
	 = true,
	 = true,
	 = true,
	 = "w",
	 = true,
	 = "]s and ]s",
	 = true,
	 = true,
	 = true,
	 = true,
	 = true,
	 = true,
	 = true,
	 = true,
	 = true,
	 = "w",
	 = "w",
	 = true,
	 = true,
	 = "w",
	 = true,
	 = true,
	 = true,
	 = true,
	 = true,
	 = true,
	 = true,
	 = true,
	 = true,
	 = "w",
	 = "w",
	 = "w",
	 = true,
	 = true,
	 = true,
	 = "w",
	 = "w",
	 = "w",
	 = "]",
	 = true,
	 = true,
	 = true,
	 = true,
	 = "w",
	 = true,
	 = "w",
	 = "w",
	 = true,
	 = true,
	 = true,
}

-- Place types for which categories can be constructed for all the places listed below other than cities. The key should
-- be the plural place type and the value should be the description.
export.generic_place_types = {
	 = "cities",
	 = "]s",
	 = "towns",
	 = "]s",
	 = "villages, hamlets, and other small communities and settlements",
	 = "]s, ]s and other subportions of cities",
	 = "]s, ]s and other subportions of cities",
	 = "]s",
	 = "rivers",
	 = "]s",
	 = "]",
	 = "places of all sorts",
}

-- Place types for which categories can be constructed for cities listed below.
-- The key should be the plural place type and the value should be the description.
export.generic_place_types_for_cities = {
	 = "]s, ]s and other subportions of cities",
	 = "]s, ]s and other subportions of cities",
	 = "]s",
	 = "places of all sorts",
}

export.placetype_to_capital_cat = {
	 = "autonomous community capitals",
	 = "cantonal capitals",
	 = "national capitals",
	 = "departmental capitals",
	 = "district capitals",
	 = "emirate capitals",
	 = "prefectural capitals",
	 = "provincial capitals",
	 = "regional capitals",
	 = "republic capitals",
	 = "state capitals",
	 = "territorial capitals",
	 = "voivodeship capitals",
}

export.capital_cat_to_placetype = {}
for placetype, capital_cat in pairs(export.placetype_to_capital_cat) do
	export.capital_cat_to_placetype = placetype
end

-----------------------------------------------------------------------------------
--                              Placename Tables                                 --
-----------------------------------------------------------------------------------

--[=[
Each of the following tables specifies a group of polities with common properties (e.g. the states of the US). Each
table is associated with a polity "group" (an entry in `export.polities`), which contains handlers specifying how to
process the data tables and also a pointer to the relevant table. The data is used as follows:

1. To generate the text of the bare topical categories directly associated with each polity, such as
   ], ] or ], and per-language
   variants such as ], ] or ].
   These categories (and all placename categories) are found in the ''topic cat subsystem'' of the category system;
   see ] for more information.
2. To generate the text of topical categories for cities/towns/rivers/etc. in a given polity, e.g.
   ] for cities in Alabama, and per-language variants such as
   ] for French terms for cities in Alabama.
3. To generate the text of topical categories for political subdivisions of a given polity, e.g.
   ], ] or
   ], along with per-language variants such as
   ], ] or
   ].
4. To add pages to all the above types of categories when a call to {{place}} on that page
   references the polity, such as by a template call {{place|en|city|state/Alabama}} (which will
   add the page to ]).

Uses #1, #2 and #3 are controlled by ].
Use #4 is controlled by ].

The keys of each table are the polity names in the form they will appear in a category like
] or ] (hence, they should include
prefixes such as "the" and suffixes such as ", USA"). Transforming these keys to the form that appears in the bare
topical category (e.g. ]), in category parents and/or in descriptions can be done using the
`bare_label_setter` and `value_transformer` keys (see `export.polities` below).
	 
The value of an item in each table is itself a table. This table contains properties describing the polity in question.
Note that before being used (e.g. to generate the contents of a category page like ]
or ] of to specify how to add the relevant categories to a page with a call
to {{place}}), the table is passed through the associated polity group's `value_transformer` function (see
`export.polities`). That function generally augments the property table with additional properties that are common to
the group or derivable from group-specific properties. The following are the properties most commonly specified
(additional properties are sometimes attached to entries in specific groups):

- `divtype`: String specifying the type of polity or subpolity (e.g. "country", "state", province"). This can also be a
  table of such types; in this case, the first listed type is the canonical type that will be used in descriptions, but
  the polity will be recognized (e.g. in {{place}} arguments) when tagged with any of the specified types. This value
  overrides the group-level `default_divtype` value, and only needs to be specified if it disagrees with that value.

- `poldiv`: List of recognized political subdivisions; e.g. for the Netherlands, a specification of the form
  'poldiv = {"provinces", "municipalities"}' will allow categories such as ]
  and ] to be created. These categories have a primary parent
  ] (i.e. this is the parent that appears in the breadcrumbs at the top of
  the category page), and have the containing polity, if any (see `containing_polity` below) as an additional parent.
  Any political subdivision that appears here must also be listed in the `political_subdivisions` list, which tells how
  to convert the pluralized political subdivision into the equivalent linked description. (If not listed, an error
  occurs.)

- `miscdiv`: List of recognized historical/popular subdivisions; e.g. for Ireland, a specification of the form
  'miscdiv = {"provinces"}' will allow categories such as ] to be created. These
  categories differ from political subdivision categories in that their primary parent is the country name rather than
  ].

- `is_city`: If 'true', don't recognize or generate categories such as ] (specifically,
  for place types in `generic_place_types` but not in `generic_place_types_for_cities`).

- `is_former_place`: If 'true', don't recognize or generate categories such as
  ] (specifically, for any place type in `generic_place_types` other than
  "places"). NOTE: This key may be added automatically by the `value_transformer` function.
  
- `keydesc`: String directly specifying a description of the polity, for use in generating the contents of category
  pages related to the polity. descriptions. This property is only rarely present, and is normally generated
  automatically by the `value_transformer` function from the key and (for subpolities) the value of `divtype`.

- `parents`: List of parents of the bare topical category. For example, if 'parents = {"Europe", "Asia"}' is specified
  for "Turkey", bare topical categories such as ] will have parent categories
  ] and ]. The first listed category is used for the primary parent (i.e. this
  is the parent that appears in the breadcrumbs at the top of the category page). In this case, for example, "Europe"
  (not "Asia") is used as the breadcrumb. This property only needs to be specified for top-level polities (countries and
  such), not for subpolities (states, provinces, etc.), which use the value of `containing_polity` (see below) as the
  parent.

- `bare_category_desc`: String specifying the description used in the bare topical category. If not given, a default
  description is constructed by the `bare_label_setter` function.

- `containing_polity`: This property does not need to be specified explicitly. It is automatically added by the
  `value_transformer` function for subpolities, and left off for top-level polities. It specifies the larger polity in
  which the subpolity is contained, and is used to construct the primary parent of 'Cities in ...', 'Rivers in ...' and
  similar categories. For example, the subpolity Guangdong (a province of China) will have "China" as the
  `containing_polity`, so that a category of the form ] will have its primary parent
  (i.e. the parent that appears in the breadcrumbs at the top of the category page) as ].
  If `containing_polity` is omitted, as in top-level polities, the primary parent will simply be e.g.
  ] (or "Towns", "Rivers", etc. as appropriate).
]=]

export.countries = {
	 = {parents = {"Asia"}, poldiv = {"provinces", "districts"}, miscdiv = {"regions"}},
	 = {parents = {"Europe"}, poldiv = {"counties", "municipalities"}, british_spelling = true},
	 = {parents = {"Africa"}, poldiv = {"provinces", "communes", "districts", "municipalities"}},
	 = {parents = {"Europe"}, poldiv = {"parishes"}, british_spelling = true},
	 = {parents = {"Africa"}, poldiv = {"provinces", "municipalities"}},
	 = {parents = {"North America"}, poldiv = {"provinces"}, british_spelling = true},
	 = {parents = {"South America"}, poldiv = {"provinces", "departments", "municipalities"}},
	 = {parents = {"Europe", "Asia"}, poldiv = {"provinces", "districts"}, british_spelling = true},
	-- Both a country and continent
	 = {parents = {"Earth", "Oceania"}, poldiv = {"states", "territories", "local government areas"}, british_spelling = true},
	 = {parents = {"Europe"}, poldiv = {"states", "districts", "municipalities"}, british_spelling = true},
	 = {parents = {"Europe", "Asia"}, poldiv = {"districts", "municipalities"}, british_spelling = true},
	 = {parents = {"North America"}, poldiv = {"districts"}, british_spelling = true, wp = "The Bahamas"},
	 = {parents = {"Asia"}, poldiv = {"governorates"}},
	 = {parents = {"Asia"}, poldiv = {"divisions", "districts", "municipalities"}, british_spelling = true},
	 = {parents = {"North America"}, poldiv = {"parishes"}, british_spelling = true},
	 = {parents = {"Europe"}, poldiv = {"regions", "districts"}, british_spelling = true},
	 = {parents = {"Europe"}, poldiv = {"regions", "provinces", "municipalities"}, british_spelling = true},
	 = {parents = {"Central America"}, poldiv = {"districts"}, british_spelling = true},
	 = {parents = {"Africa"}, poldiv = {"departments", "communes"}},
	 = {parents = {"Asia"}, poldiv = {"districts", "gewogs"}},
	 = {parents = {"South America"}, poldiv = {"provinces", "departments", "municipalities"}},
	 = {parents = {"Europe"}, poldiv = {"entities", "cantons", "municipalities"}, british_spelling = true},
	 = {parents = {"Africa"}, poldiv = {"districts", "subdistricts"}, british_spelling = true},
	 = {parents = {"South America"}, poldiv = {"states", "municipalities"}, miscdiv = {"regions"}},
	 = {parents = {"Asia"}, poldiv = {"districts", "mukims"}, british_spelling = true},
	 = {parents = {"Europe"}, poldiv = {"provinces", "municipalities"}, british_spelling = true},
	 = {parents = {"Africa"}, poldiv = {"regions", "departments", "provinces"}},
	 = {parents = {"Asia"}, poldiv = {"regions", "states", "union territories", "self-administered zones", "self-administered divisions", "districts"}},
	 = {parents = {"Africa"}, poldiv = {"provinces", "communes"}},
	 = {parents = {"Asia"}, poldiv = {"provinces", "districts"}},
	 = {parents = {"Africa"}, poldiv = {"regions", "departments"}},
	 = {parents = {"North America"}, poldiv = {"provinces", "territories", "counties", "districts", "municipalities"},
		miscdiv = {"regions", "census divisions"}, british_spelling = true},
	 = {parents = {"Africa"}, poldiv = {"municipalities", "parishes"}},
	 = {parents = {"Africa"}, poldiv = {"prefectures", "subprefectures"}},
	 = {parents = {"Africa"}, poldiv = {"regions", "departments"}},
	 = {parents = {"South America"}, poldiv = {"regions", "provinces", "communes"}},
	 = {parents = {"Asia"}, poldiv = {"provinces", "autonomous regions",
		"special administrative regions", "prefectures", "counties", "districts", "municipalities"},
		miscdiv = {"regions"}},
	 = {parents = {"South America"}, poldiv = {"departments", "municipalities"}},
	 = {parents = {"Africa"}, poldiv = {"autonomous islands"}},
	 = {parents = {"Central America"}, poldiv = {"provinces", "cantons"}},
	 = {parents = {"Europe"}, poldiv = {"counties", "municipalities"}, british_spelling = true},
	 = {parents = {"North America"}, poldiv = {"provinces", "municipalities"}},
	 = {parents = {"Europe", "Asia"}, poldiv = {"districts"}, british_spelling = true},
	 = {parents = {"Europe"}, poldiv = {"regions", "districts", "municipalities"}, british_spelling = true},
	 = {parents = {"Africa"}, poldiv = {"provinces", "territories"}},
	 = {parents = {"Europe"}, poldiv = {"regions", "municipalities", "dependent territories"}, british_spelling = true},
	 = {parents = {"Africa"}, poldiv = {"regions", "districts"}},
	 = {parents = {"North America"}, poldiv = {"parishes"}, british_spelling = true},
	 = {parents = {"North America"}, poldiv = {"provinces", "municipalities"},
		keydesc = "the ], the country that shares the ] island of ] with ]"},
	 = {parents = {"Asia"}, poldiv = {"municipalities"}},
	 = {parents = {"South America"}, poldiv = {"provinces", "cantons"}},
	 = {parents = {"Africa"}, poldiv = {"governorates", "regions"}},
	 = {parents = {"Central America"}, poldiv = {"departments", "municipalities"}},
	 = {parents = {"Africa"}, poldiv = {"provinces"}},
	 = {parents = {"Africa"}, poldiv = {"regions", "subregions"}},
	 = {parents = {"Europe"}, poldiv = {"counties", "municipalities"}, british_spelling = true},
	 = {parents = {"Africa"}, british_spelling = true},
	 = {parents = {"Africa"}, poldiv = {"regions", "zones"}},
	 = {parents = {"Micronesia"}, poldiv = {"states"}},
	 = {parents = {"Melanesia"}, poldiv = {"divisions", "provinces"}, british_spelling = true},
	 = {parents = {"Europe"}, poldiv = {"regions", "municipalities"}, british_spelling = true},
	 = {parents = {"Europe"}, poldiv = {"administrative regions", "departments", "collectivities", "communes", "municipalities",
		"dependent territories", "territories"}, miscdiv = {"provinces", "regions"}, british_spelling = true},
	 = {parents = {"Africa"}, poldiv = {"provinces", "departments"}},
	 = {parents = {"Africa"}, poldiv = {"divisions", "districts"}, british_spelling = true, wp = "The Gambia"},
	 = {parents = {"Europe", "Asia"}, poldiv = {"regions", "districts"}, keydesc = "the country of ], in ]", british_spelling = true},
	 = {parents = {"Europe"}, poldiv = {"states", "municipalities", "districts"}, british_spelling = true},
	 = {parents = {"Africa"}, poldiv = {"regions", "districts"}, british_spelling = true},
	 = {parents = {"Europe"}, poldiv = {"regional units", "municipalities"}, british_spelling = true},
	 = {parents = {"North America"}, poldiv = {"parishes"}, british_spelling = true},
	 = {parents = {"Central America"}, poldiv = {"departments", "municipalities"}},
	 = {parents = {"Africa"}, poldiv = {"regions", "prefectures"}},
	 = {parents = {"Africa"}, poldiv = {"regions"}},
	 = {parents = {"South America"}, poldiv = {"regions"}, british_spelling = true},
	 = {parents = {"North America"}, poldiv = {"departments", "arrondissements"}},
	 = {parents = {"Central America"}, poldiv = {"departments", "municipalities"}},
	 = {parents = {"Europe"}, poldiv = {"counties", "districts"}, british_spelling = true},
	 = {parents = {"Europe"}, poldiv = {"regions", "municipalities", "counties"}, british_spelling = true},
	 = {parents = {"Asia"}, poldiv = {"states", "union territories", "divisions", "districts", "municipalities"}, british_spelling = true},
	 = {parents = {"Asia"}, poldiv = {"regencies", "provinces"}},
	 = {parents = {"Asia"}, poldiv = {"provinces", "counties"}},
	 = {parents = {"Asia"}, poldiv = {"governorates", "districts"}},
	 = {parents = {"Europe", "British Isles"}, poldiv = {"counties", "districts"}, miscdiv = {"provinces"}, british_spelling = true},
	 = {parents = {"Asia"}, poldiv = {"districts"}},
	 = {parents = {"Europe"}, poldiv = {"regions", "provinces", "metropolitan cities"}, miscdiv = {"regions"}, british_spelling = true},
	 = {parents = {"Africa"}, poldiv = {"districts", "regions"}},
	 = {parents = {"North America"}, poldiv = {"parishes"}, british_spelling = true},
	 = {parents = {"Asia"}, poldiv = {"prefectures", "subprefectures", "municipalities"}},
	 = {parents = {"Asia"}, poldiv = {"governorates"}},
	 = {parents = {"Asia", "Europe"}, poldiv = {"regions", "districts"}},
	 = {parents = {"Africa"}, poldiv = {"counties"}, british_spelling = true},
	 = {parents = {"Micronesia"}, british_spelling = true},
	 = {parents = {"Europe"}, british_spelling = true},
	 = {parents = {"Asia"}, poldiv = {"governorates", "areas"}},
	 = {parents = {"Asia"}, poldiv = {"regions", "districts"}},
	 = {parents = {"Asia"}, poldiv = {"provinces", "districts"}},
	 = {parents = {"Europe"}, poldiv = {"municipalities"}, miscdiv = {"regions"}, british_spelling = true},
	 = {parents = {"Asia"}, poldiv = {"governorates", "districts"}},
	 = {parents = {"Africa"}, poldiv = {"districts"}, british_spelling = true},
	 = {parents = {"Africa"}, poldiv = {"counties", "districts"}},
	 = {parents = {"Africa"}, poldiv = {"districts", "municipalities"}},
	 = {parents = {"Europe"}, poldiv = {"municipalities"}, british_spelling = true},
	 = {parents = {"Europe"}, poldiv = {"counties", "municipalities"},
		miscdiv = {"ethnographic regions"}, british_spelling = true},
	 = {parents = {"Europe"}, poldiv = {"cantons"}, miscdiv = {"districts"}, british_spelling = true},
	 = {parents = {"Africa"}, poldiv = {"regions", "districts"}},
	 = {parents = {"Africa"}, poldiv = {"regions", "districts"}, british_spelling = true},
	 = {parents = {"Asia"}, poldiv = {"states", "federal territories", "districts"}, british_spelling = true},
	 = {parents = {"Asia"}, poldiv = {"provinces", "administrative atolls"}, british_spelling = true},
	 = {parents = {"Africa"}, poldiv = {"regions", "cercles"}},
	 = {parents = {"Europe"}, poldiv = {"regions", "local councils"}, british_spelling = true},
	 = {parents = {"Micronesia"}, poldiv = {"municipalities"}},
	 = {parents = {"Africa"}, poldiv = {"regions", "departments"}},
	 = {parents = {"Africa"}, poldiv = {"districts"}, british_spelling = true},
	 = {parents = {"North America", "Central America"}, poldiv = {"states", "municipalities"}},
	 = {parents = {"Europe"}, poldiv = {"districts", "municipalities"}, british_spelling = true},
	 = {parents = {"Europe"}, is_city = true, british_spelling = true},
	 = {parents = {"Asia"}, poldiv = {"provinces", "districts"}},
	 = {parents = {"Europe"}, poldiv = {"municipalities"}},
	 = {parents = {"Africa"}, poldiv = {"regions", "prefectures", "provinces"}},
	 = {parents = {"Africa"}, poldiv = {"provinces", "districts"}},
	 = {parents = {"Africa"}, poldiv = {"regions", "constituencies"}, british_spelling = true},
	 = {parents = {"Micronesia"}, poldiv = {"districts"}, british_spelling = true},
	 = {parents = {"Asia"}, poldiv = {"provinces", "districts"}},
	 = {parents = {"Europe"}, poldiv = {"provinces", "municipalities", "dependent territories"}, british_spelling = true},
	 = {parents = {"Polynesia"}, poldiv = {"regions", "dependent territories", "territorial authorities"}, british_spelling = true},
	 = {parents = {"Central America"}, poldiv = {"departments", "municipalities"}},
	 = {parents = {"Africa"}, poldiv = {"regions", "departments"}},
	 = {parents = {"Africa"}, poldiv = {"states", "local government areas"}, british_spelling = true},
	 = {parents = {"Asia", "Korea"}, poldiv = {"provinces", "counties"}},
	 = {parents = {"Europe"}, poldiv = {"municipalities"}, british_spelling = true},
	 = {parents = {"Europe"}, poldiv = {"counties", "municipalities", "dependent territories"},
		miscdiv = {"districts", "unincorporated areas"}, british_spelling = true},
	 = {parents = {"Asia"}, poldiv = {"governorates", "provinces"}},
	 = {parents = {"Asia"}, poldiv = {"provinces", "districts"}, british_spelling = true},
	 = {parents = {"Asia"}},
	 = {parents = {"Micronesia"}, poldiv = {"states"}},
	 = {parents = {"Central America"}, poldiv = {"provinces", "districts"}},
	 = {parents = {"Melanesia"}, poldiv = {"provinces", "districts"}, british_spelling = true},
	 = {parents = {"South America"}, poldiv = {"departments", "districts"}},
	 = {parents = {"South America"}, poldiv = {"regions", "provinces", "districts"}},
	 = {parents = {"Asia"}, poldiv = {"regions", "provinces", "districts", "municipalities"}},
	 = {poldiv = {"voivodeships", "counties"}, parents = {"Europe"}, british_spelling = true},
	 = {parents = {"Europe"}, poldiv = {"districts and autonomous regions", "provinces", "municipalities"}, british_spelling = true},
	 = {parents = {"Asia"}, poldiv = {"municipalities", "zones"}},
	 = {parents = {"Africa"}, poldiv = {"departments", "districts"}},
	 = {parents = {"Europe"}, poldiv = {"regions", "counties"}, british_spelling = true},
	 = {parents = {"Europe", "Asia"}, poldiv = {"republics", "autonomous oblasts", "autonomous okrugs", "oblasts", "krais", "federal cities", "districts"}, british_spelling = true},
	 = {parents = {"Africa"}, poldiv = {"provinces", "districts"}},
	 = {parents = {"North America"}, poldiv = {"parishes"}, british_spelling = true},
	 = {parents = {"North America"}, poldiv = {"quarters"}, british_spelling = true},
	 = {parents = {"North America"}, poldiv = {"parishes"}, british_spelling = true},
	 = {parents = {"Polynesia"}, poldiv = {"districts"}, british_spelling = true},
	 = {parents = {"Europe"}, poldiv = {"municipalities"}, british_spelling = true},
	 = {parents = {"Africa"}, poldiv = {"districts"}},
	 = {parents = {"Asia"}, poldiv = {"provinces", "governorates"}},
	 = {parents = {"Africa"}, poldiv = {"regions", "departments"}},
	 = {parents = {"Europe"}, poldiv = {"districts", "municipalities"}}, 
	 = {parents = {"Africa"}, poldiv = {"districts"}, british_spelling = true},
	 = {parents = {"Africa"}, poldiv = {"provinces", "districts"}, british_spelling = true},
	 = {parents = {"Asia"}, poldiv = {"districts"}, british_spelling = true},
	 = {parents = {"Europe"}, poldiv = {"regions", "districts"}, british_spelling = true},
	 = {parents = {"Europe"}, poldiv = {"municipalities"}, british_spelling = true},
	-- Note: the official name does not include "the" at the beginning, but it sounds strange in
	-- English to leave it out and it's commonly included, so we include it.
	 = {parents = {"Melanesia"}, poldiv = {"provinces"}, british_spelling = true},
	 = {parents = {"Africa"}, poldiv = {"regions", "districts"}},
	 = {parents = {"Africa"}, poldiv = {"provinces", "districts"}, british_spelling = true},
	 = {parents = {"Asia", "Korea"}, poldiv = {"provinces", "counties", "districts"}},
	 = {parents = {"Africa"}, poldiv = {"regions", "states", "counties"}, british_spelling = true},
	 = {parents = {"Europe"}, poldiv = {"autonomous communities", "provinces", "municipalities"}, british_spelling = true},
	 = {parents = {"Asia"}, poldiv = {"provinces", "districts"}, british_spelling = true},
	 = {parents = {"Africa"}, poldiv = {"states", "districts"}, british_spelling = true},
	 = {parents = {"South America"}, poldiv = {"districts"}},
	 = {parents = {"Europe"}, poldiv = {"provinces", "counties", "municipalities"}, british_spelling = true},
	 = {parents = {"Europe"}, poldiv = {"cantons", "municipalities", "districts"}, british_spelling = true},
	 = {parents = {"Asia"}, poldiv = {"governorates", "districts"}},
	 = {parents = {"Asia"}, poldiv = {"counties", "districts"}},
	 = {parents = {"Asia"}, poldiv = {"provinces"}, miscdiv = {"regions", "districts"}},
	 = {parents = {"Africa"}, poldiv = {"provinces", "districts"}, british_spelling = true},
	 = {parents = {"Asia"}, poldiv = {"provinces", "districts"}},
	 = {parents = {"Africa"}, poldiv = {"provinces", "prefectures"}},
	 = {parents = {"Polynesia"}, poldiv = {"divisions"}, british_spelling = true},
	 = {parents = {"North America"}, poldiv = {"regions", "municipalities"}, british_spelling = true},
	 = {parents = {"Africa"}, poldiv = {"governorates", "delegations"}},
	 = {parents = {"Europe", "Asia"}, poldiv = {"provinces", "districts"}},
	 = {parents = {"Asia"}, poldiv = {"regions", "districts"}},
	 = {parents = {"Polynesia"}, poldiv = {"atolls"}, british_spelling = true},
	 = {parents = {"Africa"}, poldiv = {"districts", "counties"}, british_spelling = true},
	 = {parents = {"Europe"}, poldiv = {"oblasts", "municipalities", "raions"}, british_spelling = true},
	 = {parents = {"Asia"}, poldiv = {"emirates"}},
	 = {parents = {"Europe", "British Isles"},
		poldiv = {"countries", "territories", "dependent territories"},
		keydesc = "the ] of Great Britain and Northern Ireland", british_spelling = true},
	 = {parents = {"North America"},
		poldiv = {"counties", "county seats", "states", "territories", "dependent territories",
			"municipalities", -- these exist politically at least in Colorado and Connecticut
		}, miscdiv = {"regions"}},
	 = {parents = {"South America"}, poldiv = {"departments", "municipalities"}},
	 = {parents = {"Asia"}, poldiv = {"regions", "districts"}},
	 = {parents = {"Melanesia"}, poldiv = {"provinces"}, british_spelling = true},
	 = {parents = {"Europe", "Rome"}, is_city = true, british_spelling = true},
	 = {parents = {"South America"}, poldiv = {"states", "municipalities"}},
	 = {parents = {"Asia"}, poldiv = {"provinces", "districts", "municipalities"}},
	 = {parents = {"Africa"}},
	 = {parents = {"Asia"}, poldiv = {"governorates", "districts"}},
	 = {parents = {"Africa"}, poldiv = {"provinces", "districts"}, british_spelling = true},
	 = {parents = {"Africa"}, poldiv = {"provinces", "districts"}, british_spelling = true},
}

export.pseudo_countries = {
	-- British Overseas Territory
	 = {divtype = {"overseas territory", "territory"}, parents = {"Cyprus", "Europe", "United Kingdom"}, british_spelling = true},
	-- unincorporated territory of the United States
	 = {divtype = {"unincorporated territory", "overseas territory", "territory"}, parents = {"Polynesia", "United States"}},
	 = {divtype = {"unincorporated territory", "overseas territory", "territory"}, parents = {"Islands", "Micronesia", "Polynesia", "United States"}},
	-- British Overseas Territory
	 = {divtype = {"overseas territory", "territory"}, parents = {"North America", "United Kingdom"}, british_spelling = true},
	-- de-facto independent state, internationally recognized as part of Georgia
	 = {divtype = {"unrecognized state", "country"}, parents = {"Georgia", "Europe", "Asia"},
		poldiv = {"districts"},
		keydesc = "the de-facto independent state of ], internationally recognized as part of the country of ]"},
	-- de-facto independent state of Armenian ethnicity, internationally recognized as part of Azerbaijan
	-- (also known as Nagorno-Karabakh)
	-- NOTE: Formerly listed Armenia as a parent; this seems politically non-neutral
	-- so I've taken it out.
	 = {divtype = {"unrecognized state", "country"}, parents = {"Azerbaijan", "Europe", "Asia"},
		keydesc = "the de-facto independent state of ], internationally recognized as part of ]", british_spelling = true},
	-- British Overseas Territory
	 = {divtype = {"overseas territory", "territory"}, parents = {"United Kingdom", "Atlantic Ocean"}, british_spelling = true},
	-- constituent country of the Netherlands
	 = {divtype = {"constituent country", "country"}, parents = {"Netherlands", "North America"}},
	-- British Overseas Territory
	 = {divtype = {"overseas territory", "territory"}, parents = {"United Kingdom", "North America"}, british_spelling = true},
	-- British Overseas Territory
	 = {divtype = {"overseas territory", "territory"}, parents = {"United Kingdom", "North America"}, british_spelling = true},
	-- British Overseas Territory
	 = {divtype = {"overseas territory", "territory"}, parents = {"United Kingdom", "North America"}, british_spelling = true},
	-- British Overseas Territory
	 = {divtype = {"overseas territory", "territory"}, parents = {"United Kingdom", "North America"}, british_spelling = true},
	-- Australian external territory
	 = {divtype = {"external territory", "territory"}, parents = {"Australia", "Asia"}, british_spelling = true},
	-- Australian external territory; also called the Keeling Islands or (officially) the Cocos (Keeling) Islands
	 = {divtype = {"external territory", "territory"}, parents = {"Australia", "Asia"}, british_spelling = true,
		wp = "Cocos (Keeling) Islands" },
	-- self-governing but in free association with New Zealand
	 = {divtype = {"country"}, parents = {"Polynesia", "New Zealand"}, british_spelling = true},
	-- constituent country of the Netherlands
	 = {divtype = {"constituent country", "country"}, parents = {"Netherlands", "North America"}},
	-- special territory of Chile
	 = {divtype = {"special territory", "territory"}, parents = {"Chile", "Polynesia"}},
	-- British Overseas Territory
	 = {divtype = {"overseas territory", "territory"}, parents = {"United Kingdom", "South America"}, british_spelling = true},
	-- autonomous territory of Denmark
	 = {divtype = {"autonomous territory", "territory"}, parents = {"Denmark", "Europe"}},
	-- overseas department of France
	 = {divtype = {"overseas department", "department"}, parents = {"France", "South America"}},
	-- overseas collectivity of France
	 = {divtype = {"overseas collectivity", "collectivity"}, parents = {"France", "Polynesia"}},
	-- British Overseas Territory
	 = {divtype = {"overseas territory", "territory"}, parents = {"United Kingdom", "North America"}, british_spelling = true},
	-- autonomous territory of Denmark
	 = {divtype = {"autonomous territory", "territory"}, parents = {"Denmark", "North America"}, poldiv = {"municipalities"}},
	-- overseas department of France
	 = {divtype = {"overseas department", "department"}, parents = {"France", "North America"}},
	-- unincorporated territory of the United States
	 = {divtype = {"unincorporated territory", "overseas territory", "territory"}, parents = {"United States", "Micronesia"}},
	-- self-governing British Crown dependency; technically called the Bailiwick of Guernsey
	 = {divtype = {"crown dependency", "dependency", "dependent territory", "bailiwick", "territory"}, parents = {"British Isles", "Europe"}, british_spelling = true},
	-- special administrative region of China
	 = {divtype = "special administrative region", parents = {"China"}},
	-- self-governing British Crown dependency
	 = {divtype = {"crown dependency", "dependency", "dependent territory", "territory"}, parents = {"British Isles", "Europe"}, british_spelling = true},
	-- self-governing British Crown dependency; technically called the Bailiwick of Jersey
	 = {divtype = {"crown dependency", "dependency", "dependent territory", "bailiwick", "territory"}, parents = {"British Isles", "Europe"}, british_spelling = true},
	-- special administrative region of China
	 = {divtype = "special administrative region", parents = {"China"}},
	-- overseas department of France
	 = {divtype = {"overseas department", "department"}, parents = {"France", "North America"}},
	-- British Overseas Territory
	 = {divtype = {"overseas territory", "territory"}, parents = {"United Kingdom", "North America"}, british_spelling = true},
	-- special collectivity of France
	 = {divtype = {"special collectivity", "collectivity"}, parents = {"France", "Melanesia"}},
	-- self-governing but in free association with New Zealand
	 = {divtype = {"country"}, parents = {"Polynesia", "New Zealand"}, british_spelling = true},
	-- Australian external territory
	 = {divtype = {"external territory", "territory"}, parents = {"Australia", "Polynesia"}, british_spelling = true},
	-- commonwealth, unincorporated territory of the United States
	 = {divtype = {"commonwealth", "unincorporated territory", "overseas territory", "territory"}, parents = {"United States", "Micronesia"}},
	-- British Overseas Territory
	 = {divtype = {"overseas territory", "territory"}, parents = {"United Kingdom", "Polynesia"}, british_spelling = true},
	-- commonwealth of the United States
	 = {divtype = {"commonwealth", "overseas territory", "territory"}, parents = {"United States", "North America"}, poldiv = {"municipalities"}},
	-- overseas collectivity of France
	 = {divtype = {"overseas collectivity", "collectivity"}, parents = {"France", "North America"}},
	-- British Overseas Territory
	 = {divtype = {"overseas territory", "territory"}, parents = {"United Kingdom", "Atlantic Ocean"}, british_spelling = true},
	-- overseas collectivity of France
	 = {divtype = {"overseas collectivity", "collectivity"}, parents = {"France", "North America"}},
	-- overseas collectivity of France
	 = {divtype = {"overseas collectivity", "collectivity"}, parents = {"France", "North America"}},
	-- de-facto independent state, internationally recognized as part of Georgia
	 = {divtype = {"unrecognized state", "country"}, parents = {"Georgia", "Europe", "Asia"},
		keydesc = "the de-facto independent state of ], internationally recognized as part of the country of ]", british_spelling = true},
	-- constituent country of the Netherlands
	 = {divtype = {"constituent country", "country"}, parents = {"Netherlands", "North America"}},
	-- British Overseas Territory
	 = {divtype = {"overseas territory", "territory"}, parents = {"United Kingdom", "Atlantic Ocean"}, british_spelling = true},
	-- British Overseas Territory
	 = {divtype = {"overseas territory", "territory"}, parents = {"United Kingdom", "Atlantic Ocean"}, british_spelling = true,
		wp = true, wpcat = "South Georgia and the South Sandwich Islands"
	},
	-- dependent territory of New Zealnd
	 = {divtype = {"dependent territory", "territory"}, parents = {"New Zealand", "Polynesia"}, british_spelling = true},
	-- de-facto independent state, internationally recognized as part of Moldova
	 = {divtype = {"unrecognized state", "country"}, parents = {"Moldova", "Europe"},
		keydesc = "the de-facto independent state of ], internationally recognized as part of ]", british_spelling = true},
	-- British Overseas Territory
	 = {divtype = {"overseas territory", "territory"}, parents = {"United Kingdom", "Atlantic Ocean"}, british_spelling = true},
	-- British Overseas Territory
	 = {divtype = {"overseas territory", "territory"}, parents = {"United Kingdom", "North America"}, british_spelling = true},
	-- unincorporated territory of the United States
	 = {divtype = {"unincorporated territory", "overseas territory", "territory"}, parents = {"United States", "North America"}},
	-- unincorporated territory of the United States
	 = {divtype = {"unincorporated territory", "overseas territory", "territory"}, parents = {"United States", "North America"}},
	-- overseas collectivity of France
	 = {divtype = {"overseas collectivity", "collectivity"}, parents = {"France", "Polynesia"}},
}

export.former_countries = {
	 = {parents = {"Europe"}, british_spelling = true},
	 = {parents = {"Europe", "Germany"}, british_spelling = true},
	 = {parents = {"Asia", "Vietnam"}},
	 = {parents = {"Asia"}, poldiv = {"provinces"}},
	 = {divtype = {"empire", "country"}, parents = {"Europe", "Africa", "Asia", "Rome"}, poldiv = {"provinces"}},
	 = {parents = {"Asia", "Vietnam"}},
	 = {parents = {"Europe", "Asia"}, poldiv = {"republics", "autonomous republics"}, british_spelling = true},
	 = {parents = {"Europe", "Germany"}, british_spelling = true},
	 = {parents = {"Europe"}, poldiv = {"districts"},
		keydesc = "the former ] (1918-1943) or the former ] (1943-1992)", british_spelling = true},
}

export.australian_states_and_territories = {
	 = {divtype = "territory"},
	 = {},
	 = {divtype = "territory"},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
}

export.austrian_states = {
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
}

export.bangladeshi_divisions = {
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
}

export.brazilian_states = {
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
}

local rural_municipalities = {"rural municipalities", parent="rural municipalities"}
local canadian_counties = {"counties", parent="counties of Canada"}
export.canadian_provinces_and_territories = {
	 = {poldiv = {"municipal districts"}},
	 = {poldiv = {"regional districts", "regional municipalities"}},
	 = {poldiv = {rural_municipalities}},
	 = {poldiv = {canadian_counties}},
	 = {},
	 = {divtype = "territory"},
	 = {poldiv = {canadian_counties, "regional municipalities"}},
	 = {divtype = "territory"},
	 = {poldiv = {canadian_counties, "regional municipalities"}},
	 = {poldiv = {canadian_counties, rural_municipalities}},
	 = {poldiv = {rural_municipalities}},
	 = {poldiv = {canadian_counties, "regional county municipalities"}},
	 = {divtype = "territory"},
}

-- table of Chinese provinces and autonomous regions; interpolated into the main 'places' table, but also needed separately
export.chinese_provinces_and_autonomous_regions = {
	 = {},
	 = {},
	 = {},
	 = {},
	 = {divtype = "autonomous region"},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {divtype = "autonomous region"},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {divtype = "autonomous region"},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {divtype = "autonomous region"},
	 = {divtype = "autonomous region"},
	 = {},
	 = {},
}

export.finnish_regions = {
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
}

export.french_administrative_regions = {
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
}

export.german_states = {
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
}

-- Indian states and union territories. Only some of them are divided into
-- divisions.
export.indian_states_and_union_territories = {
	 = {divtype = "union territory"},
	 = {},
	 = {poldiv = {"divisions"}},
	 = {poldiv = {"divisions"}},
	 = {poldiv = {"divisions"}},
	 = {divtype = "union territory"},
	 = {poldiv = {"divisions"}},
	 = {divtype = "union territory"},
	 = {divtype = "union territory"},
	 = {divtype = "union territory", poldiv = {"divisions"}},
	 = {},
	 = {},
	 = {poldiv = {"divisions"}},
	 = {poldiv = {"divisions"}},
	 = {divtype = "union territory", poldiv = {"divisions"}},
	 = {poldiv = {"divisions"}},
	 = {poldiv = {"divisions"}},
	 = {},
	 = {divtype = "union territory", poldiv = {"divisions"}},
	 = {divtype = "union territory"},
	 = {poldiv = {"divisions"}},
	 = {poldiv = {"divisions"}},
	 = {},
	 = {poldiv = {"divisions"}},
	 = {},
	 = {poldiv = {"divisions"}},
	 = {poldiv = {"divisions"}},
	 = {divtype = "union territory"},
	 = {poldiv = {"divisions"}},
	 = {poldiv = {"divisions"}},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {poldiv = {"divisions"}},
	 = {poldiv = {"divisions"}},
	 = {poldiv = {"divisions"}},
}

export.indonesian_provinces = {
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
}

export.irish_counties = {
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
}

export.italian_regions = {
	 = {},
	 = {divtype = {"autonomous region", "region"}},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {divtype = {"autonomous region", "region"}},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {divtype = {"autonomous region", "region"}},
	 = {divtype = {"autonomous region", "region"}},
	 = {divtype = {"autonomous region", "region"}},
	 = {},
	 = {},
	 = {},
}

-- table of Japanese prefectures; interpolated into the main 'places' table, but also needed separately
export.japanese_prefectures = {
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {poldiv = {{"subprefectures", parent="subprefectures of Japan"}}}, -- just "Hokkaido" not "Hokkaido Prefecture"
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {keydesc = "] Metropolis", poldiv = {"special wards", {"subprefectures", parent="subprefectures of Japan"}}}, -- just "Tokyo" not "Tokyo Prefecture" or "Tokyo Metropolis"
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
}

local function japanese_placename_to_key(placename)
	if placename == "Hokkaido" or placename == "Tokyo" then
		return placename
	end
	return placename .. " Prefecture"
end

export.maltese_regions = {
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
}

export.mexican_states = {
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
}
		
export.moroccan_regions = {
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
}

export.netherlands_provinces = {
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
}

export.norwegian_counties = {
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
}

export.philippine_provinces = {
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
}

export.russian_federal_subjects = {
	-- autonomous oblasts
	 = {divtype = {"autonomous oblast", "oblast"}},
	-- autonomous okrugs
	 = {divtype = "autonomous okrug"},
	 = {divtype = "autonomous okrug"},
	 = {divtype = "autonomous okrug"},
	 = {divtype = "autonomous okrug"},
	-- krais
	 = {divtype = "krai"},
	 = {divtype = "krai"},
	 = {divtype = "krai"},
	 = {divtype = "krai"},
	 = {divtype = "krai"},
	 = {divtype = "krai"},
	 = {divtype = "krai"},
	 = {divtype = "krai"},
	 = {divtype = "krai"},
	-- oblasts
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	-- republics
	 = {divtype = "republic"},
	 = {divtype = "republic"},
	 = {divtype = "republic"},
	 = {divtype = "republic"},
	 = {divtype = "republic"},
	 = {divtype = "republic"},
	 = {divtype = "republic"},
	 = {divtype = "republic"},
	 = {divtype = "republic"},
	 = {divtype = "republic"},
	 = {divtype = "republic"},
	 = {divtype = "republic"},
	 = {divtype = "republic"},
	 = {divtype = "republic"},
	 = {divtype = "republic"},
	 = {divtype = "republic"},
	 = {divtype = "republic"},
	 = {divtype = "republic"},
	 = {divtype = "republic"},
	 = {divtype = "republic"},
	 = {divtype = "republic"},
	-- Not sure what to do about this one from a neutrality perspective
	--  = {divtype = "republic"},
	-- There are also federal cities (not included because they're cities):
	-- Moscow, Saint Petersburg, Sevastopol (not sure what to do about the
	-- last one if we were to include federal cities, see "Republic of Crimea"
	-- above)
}

local function russian_placename_to_key(placename)
	-- We allow the user to say e.g. "obl/Samara" and "rep/Tatarstan" in place of
	-- "obl/Samara Oblast" and "rep/Republic of Tatarstan".
	if export.russian_federal_subjects or export.russian_federal_subjects then
		return placename
	end
	for _, suffix in ipairs({"Autonomous Okrug", "Krai", "Oblast"}) do
		local suffixed_placename = placename .. " " .. suffix
		if export.russian_federal_subjects then
			return suffixed_placename
		end
	end
	local republic_placename = "Republic of " .. placename
	if export.russian_federal_subjects then
		return republic_placename
	end
	local republic_placename = placename .. " Republic"
	if export.russian_federal_subjects then
		return republic_placename
	end
	return placename
end

export.spanish_autonomous_communities = {
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
}

export.uk_constituent_countries = {
	 = {poldiv = {"regions", "counties", "districts", "civil parishes"}},
	 = {divtype = "province", parents = {"United Kingdom", "Ireland"},
		poldiv = {"districts"}, miscdiv = {"traditional counties"}},
	 = {poldiv = {"council areas"}, miscdiv = {"regions", "districts", "traditional counties"}},
	 = {poldiv = {"counties", "county boroughs"}},
}

-- table of US states; interpolated into the main 'places' table, but also needed separately
export.us_states = {
	 = {},
	 = {poldiv = {
		{"boroughs", parent="counties of the United States"},
		{"borough seats", parent="county seats of the United States"},
	}},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {parents = {"United States", "Polynesia"}},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {poldiv = {
		{"parishes", parent="counties of the United States"},
		{"parish seats", parent="county seats of the United States"},
	}},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
}

export.english_counties = {
	--  = {}, -- no longer
	 = {},
	 = {},
	--  = {}, -- city
	--  = {}, -- city
	 = {},
	 = {},
	--  = {}, -- no longer
	 = {},
	--  = {}, -- no longer
	 = {},
	--  = {}, -- no longer
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	--  = {}, -- no longer
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	--  = {}, -- no longer
	 = {}, 
	 = {},
	--  = {}, -- no longer
	--  = {}, -- no longer
	--  = {}, -- no longer
	--  = {}, -- no longer
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	--  = {}, -- no longer
	 = {},
	--  = {}, -- no longer
	 = {},
	 = {},
	 = {},
	--  = {}, -- no longer
	 = {},
	 = {},
	 = {},
	--  = {}, -- no longer
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	--  = {}, -- no longer
	 = {},
	 = {},
	 = {},
	--  = {}, -- no longer
	--  = {}, -- no longer
	 = {},
	 = {},
	 = {},
	 = {},
	--  = {}, -- no longer
	 = {},
	--  = {}, -- no longer
	--  = {}, -- no longer
}

export.northern_irish_counties = {
	 = {},
	 = {},
	 = {is_city = true},
	 = {},
	 = {},
	 = {},
	 = {is_city = true},
	 = {},
}

export.romanian_counties = {
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
}

export.scottish_council_areas = {
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
}

export.welsh_principal_areas = {
	 = {},
	 = {},
	 = {},
	--  = {divtype = "city"},
	 = {divtype = "county"},
	 = {divtype = "county"},
	 = {},
	 = {divtype = "county"},
	 = {divtype = "county"},
	 = {divtype = "county"},
	 = {divtype = "county"},
	 = {},
	 = {divtype = "county"},
	 = {},
	--  = {divtype = "city"},
	 = {divtype = "county"},
	 = {divtype = "county"},
	 = {},
	--  = {divtype = "city"},
	 = {},
	 = {},
	 = {},
}

export.new_york_boroughs = {
	 = true,
	 = true,
	 = true,
	 = true,
	 = true,
}

export.cities = {
	{
		default_divtype = "state",
		containing_polities = {"Australia", divtype="country"},
		data = {
			 = {"New South Wales"},
			 = {"Victoria"},
			 = {"Queensland"},
			 = {"Western Australia"},
			 = {"South Australia"},
		},
	},
	{
		default_divtype = "state",
		containing_polities = {"Brazil", divtype="country"},
		data = {
			-- This only lists cities, not metro areas, over 1,000,000 inhabitants.
			 = {"São Paulo"},
			 = {"Rio de Janeiro"},
			 = {"Distrito Federal"},
			 = {alias_of="Brasília"},
			 = {"Bahia", wp="%c, %d", commonscat="%c (%d)"},
			 = {"Ceará"},
			 = {"Minas Gerais"},
			 = {"Amazonas"},
			 = {"Paraná"},
			 = {"Pernambuco"},
			 = {"Goiás"},
			 = {alias_of="Goiânia"},
			 = {"Pará"},
			 = {alias_of="Belém"},
			 = {"Rio Grande do Sul"},
			 = {"São Paulo"},
			 = {"São Paulo"},
		},
	},
	{
		default_divtype = "province",
		containing_polities = {"Canada", divtype="country"},
		data = {
			 = {"Ontario"},
			 = {"Quebec"},
			 = {"British Columbia"},
			 = {"Alberta"},
			 = {"Alberta"},
			 = {"Ontario"},
			 = {"Manitoba"},
			 = {"Quebec"},
			 = {"Ontario", wp="%c, %d"},
			 = {"Ontario", wp="%c, %d"},
		},
	},
	{
		default_divtype = "province",
		containing_polities = {"China", divtype="country"},
		data = {
			-- This only lists the top 50. Per ], there
			-- are 102 cities over 1,000,000 inhabitants, not to mention metro areas. Our coverage
			-- of China is fairly sparse; when it increases, add to this list.
			 = {},
			 = {},
			 = {"Guangdong"},
			 = {"Guangdong"},
			 = {},
			 = {"Hubei"},
			 = {"Guangdong"},
			 = {"Sichuan"},
			 = {"Guangdong"},
			 = {},
			 = {"Jiangsu"},
			 = {"Liaoning"},
			 = {"Zhejiang"},
			 = {"Shaanxi"},
			 = {"Heilongjiang"},
			 = {"Jiangsu"},
			 = {"Shandong"},
			 = {"Liaoning"},
			 = {"Henan"},
			 = {"Guangdong"},
			 = {"Shandong"},
			 = {"Jilin"},
			 = {"Yunnan"},
			 = {"Hunan"},
			 = {"Shanxi"},
			 = {"Fujian"},
			 = {"Anhui"},
			 = {"Hebei"},
			 = {"Xinjiang", divtype="autonomous region"},
			 = {alias_of="Ürümqi"},
			 = {"Fujian"},
			 = {"Jiangsu"},
			 = {"Guangdong"},
			 = {"Zhejiang"},
			 = {"Guangxi", divtype="autonomous region"},
			 = {"Jiangxi"},
			 = {"Zhejiang"},
			 = {"Guizhou"},
			 = {"Gansu"},
			 = {"Shandong"},
			 = {"Jiangsu"},
			 = {"Jiangsu"},
			 = {"Hebei"},
			 = {"Inner Mongolia", divtype="autonomous region"},
			 = {"Guangdong"},
			 = {"Shandong"},
			 = {"Zhejiang"},
			 = {"Guangxi", divtype="autonomous region"},
			 = {"Jiangsu"},
			 = {"Henan"},
			 = {"Jiangsu"},
		},
	},
	{
		default_divtype = "administrative region",
		containing_polities = {"France", divtype="country"},
		data = {
			 = {"Île-de-France"},
			 = {"Auvergne-Rhône-Alpes"},
			 = {alias_of="Lyon"},
			 = {"Provence-Alpes-Côte d'Azur"},
			 = {alias_of="Marseille"},
			 = {"Occitanie"},
			 = {"Hauts-de-France"},
			 = {"Nouvelle-Aquitaine"},
			 = {"Provence-Alpes-Côte d'Azur"},
			 = {"Pays de la Loire"},
			 = {"Grand Est"},
			 = {"Brittany"},
		},
	},
	{
		default_divtype = "state",
		containing_polities = {"Germany", divtype="country"},
		data = {
			 = {},
			 = {"North Rhine-Westphalia"},
			 = {"North Rhine-Westphalia"},
			 = {"North Rhine-Westphalia"},
			 = {},
			 = {"Bavaria"},
			 = {"Baden-Württemberg"},
			 = {"Hesse"},
			 = {"North Rhine-Westphalia"},
			 = {"North Rhine-Westphalia"},
			 = {alias_of="Düsseldorf"},
			 = {"Bavaria"},
			 = {},
		},
	},
	{
		default_divtype = "state",
		containing_polities = {"India", divtype="country"},
		data = {
			-- This only lists the top 20. Per ], there
			-- are 46 cities over 1,000,000 inhabitants, not to mention metro areas. Our coverage
			-- of India is fairly sparse; when it increases, add to this list.
			 = {"Maharashtra"},
			 = {},
			 = {"Karnataka"},
			 = {"Telangana"},
			 = {"Gujarat"},
			 = {"Tamil Nadu"},
			 = {"West Bengal"},
			 = {"Gujarat"},
			 = {"Maharashtra"},
			 = {"Rajasthan"},
			 = {"Uttar Pradesh"},
			 = {"Uttar Pradesh"},
			 = {"Maharashtra"},
			 = {"Madhya Pradesh"},
			 = {"Maharashtra"},
			 = {"Madhya Pradesh"},
			 = {"Andhra Pradesh"},
			 = {"Maharashtra"},
			 = {"Bihar"},
			 = {"Gujarat"},
		},
	},
	{
		default_divtype = "prefecture",
		containing_polities = {"Japan", divtype="country"},
		data = {
			-- Population figures from ]. Metro areas from
			-- ].
			 = {}, -- no single figure given for Tokyo as a whole.
			 = {"Kanagawa"}, -- 3,697,894
			 = {"Osaka"}, -- 2,668,586
			 = {"Aichi"}, -- 2,283,289
			-- FIXME, Hokkaido is handled specially.
			 = {}, -- {"Hokkaido"}, -- 1,918,096
			 = {"Fukuoka"}, -- 1,581,527
			 = {"Hyōgo"}, -- 1,530,847
			 = {"Kyoto"}, -- 1,474,570
			 = {"Kanagawa", wp="%c, %d"}, -- 1,373,630
			 = {"Saitama", wp="%c (city)", commonscat="%c, %d"}, -- 1,192,418
			 = {"Hiroshima"}, -- 1,163,806
			 = {"Miyagi"}, -- 1,029,552
			-- the remaining cities are considered "central cities" in a 1,000,000+ metro area
			-- (sometimes there is more than one central city in the area).
			 = {"Fukuoka"}, -- 986,998
			 = {"Chiba", wp="%c (city)", commonscat="%c, %d"}, -- 938,695
			 = {"Osaka"}, -- 835,333
			 = {"Niigata", wp="%c (city)", commonscat="%c, %d"}, -- 813,053
			 = {"Shizuoka"}, -- 811,431
			 = {"Shizuoka", wp="%c (city)", commonscat="%c, %d"}, -- 710,944
			 = {"Kanagawa"}, -- 706,342
			 = {"Okayama"}, -- 701,293
			 = {"Kumamoto"}, -- 670,348
			 = {"Kagoshima"}, -- 605,196
			-- skipped 6 cities (Funabashi, Hachiōji, Kawaguchi, Himeji, Matsuyama, Higashiōsaka)
			-- with population in the range 509k - 587k because not central cities in any
			-- 1,000,000+ metro area.
			 = {"Tochigi"}, -- 507,833
		},
	},
	{
		default_divtype = "oblast",
		containing_polities = {"Russia", divtype="country"},
		data = {
			-- This only lists cities, not metro areas, over 1,000,000 inhabitants.
			 = {},
			 = {},
			 = {"Novosibirsk Oblast"},
			 = {"Sverdlovsk Oblast"},
			 = {"Nizhny Novgorod Oblast"},
			 = {"the Republic of Tatarstan", divtype="republic"},
			 = {"Chelyabinsk Oblast"},
			 = {"Omsk Oblast"},
			 = {"Samara Oblast"},
			 = {"the Republic of Bashkortostan", divtype="republic"},
			 = {"Rostov Oblast"},
			 = {alias_of="Rostov-on-Don"},
			 = {"Krasnoyarsk Krai", divtype="krai"},
			 = {"Voronezh Oblast"},
			 = {"Perm Krai", divtype="krai", wp="Perm, Russia"},
			 = {"Volgograd Oblast"},
			 = {"Krasnodar Krai", divtype="krai"},
		},
	},
	{
		default_divtype = "autonomous community",
		containing_polities = {"Spain", divtype="country"},
		data = {
			 = {"the Community of Madrid"},
			 = {"Catalonia"},
			-- this causes recursion errors.
			--  = {"Valencia"},
			 = {"Andalusia"},
			 = {"the Basque Country"},
		},
	},
	{
		default_divtype = "county",
		containing_polities = {"the United Kingdom", divtype="country"},
		data = {
			 = {{"Greater London"}, {"England", divtype="constituent country"}},
			 = {{"Greater Manchester"}, {"England", divtype="constituent country"}},
			 = {{"the West Midlands"}, {"England", divtype="constituent country"}},
			 = {{"Merseyside"}, {"England", divtype="constituent country"}},
			 = {{"the City of Glasgow", divtype="council area"}, {"Scotland", divtype="constituent country"}},
			 = {{"West Yorkshire"}, {"England", divtype="constituent country"}},
			 = {{"Tyne and Wear"}, {"England", divtype="constituent country"}},
			 = {alias_of="Newcastle upon Tyne"},
			 = {{"England", divtype="constituent country"}},
			 = {{"Wales", divtype="constituent country"}},
			 = {{"Hampshire"}, {"England", divtype="constituent country"}},
			 = {{"the City of Edinburgh", divtype="council area"}, {"Scotland", divtype="constituent country"}},
			-- under 1,000,000 people but principal areas of Wales; requested by ]
			 = {{"Wales", divtype="constituent country"}},
			 = {{"Wales", divtype="constituent country"}, wp="Newport, Wales"},
		},
	},
	-- cities in the US
	{
		default_divtype = "state",
		containing_polities = {"the United States", divtype="country"},
		wp = "%c, %d",
		data = {
			-- top 50 CSA's by population, with the top and sometimes 2nd or 3rd city listed
			 = {"New York", wp="%c"},
			 = {"New Jersey"},
			 = {"California", wp="%c"},
			 = {"California"},
			 = {"California"},
			 = {"Illinois", wp="%c"},
			 = {wp="%c"},
			 = {"Maryland", wp="%c"},
			 = {"California"},
			 = {"California", wp="%c"},
			 = {"California"},
			 = {"Massachusetts", wp="%c"},
			 = {"Rhode Island"},
			 = {"Texas", wp="%c", commonscat="%c, %d"},
			 = {"Texas"},
			 = {"Pennsylvania", wp="%c"},
			 = {"Texas", wp="%c"},
			 = {"Florida", wp="%c", commonscat="%c, %d"},
			 = {"Georgia", wp="%c"},
			 = {"Michigan", wp="%c"},
			 = {"Arizona", wp="%c", commonscat="%c, %d"},
			 = {"Arizona"},
			 = {"Washington", wp="%c"},
			 = {"Florida"},
			 = {"Minnesota", wp="%c"},
			 = {"Ohio", wp="%c", commonscat="%c, %d"},
			 = {"Colorado", wp="%c", commonscat="%c, %d"},
			 = {"California", wp="%c", commonscat="%c, %d"},
			 = {"Oregon"},
			 = {"Florida"},
			 = {"Missouri", wp="%c", commonscat="%c, %d"},
			 = {"North Carolina"},
			 = {"California"},
			 = {"Pennsylvania", wp="%c"},
			 = {"Utah", wp="%c"},
			 = {"Texas", wp="%c", commonscat="%c, %d"},
			 = {"Ohio"},
			 = {"Missouri", wp="%c metropolitan area", commonscat="%c, %d"},
			 = {"Indiana", wp="%c"},
			 = {"Nevada", wp="%c"},
			 = {"Ohio", wp="%c", commonscat="%c, %d"},
			 = {"Texas"},
			 = {"Wisconsin", wp="%c", commonscat="%c, %d"},
			 = {"North Carolina"},
			 = {"Tennessee"},
			 = {"Virginia"},
			 = {"Virginia"},
			 = {"North Carolina"},
			 = {"North Carolina"},
			 = {"Florida"},
			 = {"Louisiana", wp="%c"},
			 = {"Kentucky"},
			 = {"South Carolina"},
			 = {"Connecticut"},
			 = {"Oklahoma", wp="%c"},
			 = {"Michigan"},
			 = {"Tennessee"},
			 = {"Alabama"},
			 = {"California"},
			 = {"Virginia"},
			 = {"Pennsylvania"},
			-- any major city of top 50 MSA's that's missed by previous
			 = {"New York"},
			-- any of the top 50 city by city population that's missed by previous
			 = {"Texas"},
			 = {"New Mexico"},
			 = {"Arizona"},
			 = {"Colorado"},
			 = {"Nebraska"},
			 = {"Oklahoma"},
			-- skip Arlington, Texas; too obscure and likely to be interpreted as Arlington, Virginia
		}
	},
	{
		default_divtype = "country",
		containing_polities = {},
		data = {
			 = {"Armenia"},
			 = {"Austria"},
			 = {"Belarus"},
			 = {"Belgium"},
			 = {"Belgium"},
			 = {"Bulgaria"},
			 = {"Croatia"},
			 = {"the Czech Republic"},
			 = {"the Czech Republic"},
			 = {"Denmark"},
			 = {{"Uusimaa", divtype="region"}, {"Finland"}},
			 = {"Greece"},
			 = {"Greece"},
			 = {"Hungary"},
			-- FIXME, per Wikipedia "County Dublin" is now the "Dublin Region"
			 = {{"Dublin", divtype="county"}, {"Ireland"}},
			 = {{"Veneto", divtype="region"}, {"Italy"}},
			 = {{"Lazio", divtype="region"}, {"Italy"}},
			 = {{"Lombardy", divtype="region"}, {"Italy"}},
			 = {{"Campania", divtype="region"}, {"Italy"}},
			 = {{"Piedmont", divtype="region"}, {"Italy"}},
			 = {"Latvia"},
			 = {"the Netherlands"},
			 = {"the Netherlands"},
			 = {"the Netherlands"},
			 = {"Norway"},
			 = {"Poland"},
			 = {"Poland"},
			 = {"Poland"},
			 = {alias_of="Kraków"},
			 = {"Poland"},
			 = {alias_of="Gdańsk"},
			 = {"Poland"},
			 = {alias_of="Poznań"},
			 = {"Poland"},
			 = {alias_of="Łódź"},
			 = {"Portugal"},
			 = {"Portugal"},
			 = {"Romania"},
			 = {"Serbia"},
			 = {"South Korea"},
			 = {"Sweden"},
			 = {"Switzerland"},
			 = {alias_of="Zürich"},
			 = {"Turkey"},
			 = {"Ukraine"},
			 = {alias_of="Kyiv"},
			 = {"Ukraine"},
			 = {"Ukraine", wp="Odesa"},
			 = {alias_of="Odessa"},
		},
	},
}

-----------------------------------------------------------------------------------
--                              Helper functions                                 --
-----------------------------------------------------------------------------------

local function ucfirst(label)
	return mw.getContentLanguage():ucfirst(label)
end

local function add_indefinite_article(label)
	if label:find("^") then
		return "an " .. label
	else
		return "a " .. label
	end
end

-- Format a description that can have the special value of 'true' or 'nil' (use link_label() in
-- ]) or "w" (use link_label(..., "wikify")). Any other value is returned as-is.
function export.format_description(desc, label)
	if desc == nil then
		desc = true
	end
	if desc == true then
		desc = require(topic_cat_utilities_module).link_label(label)
	elseif desc == "w" then
		desc = require(topic_cat_utilities_module).link_label(label, nil, "wikify")
	end
	return desc
end

function export.construct_bare_and_linked_version(key)
	local bare_key = key:match("^the (.*)$")
	local linked_key
	if bare_key then
		linked_key = "the ]"
	else
		linked_key = "]"
		bare_key = key
	end
	return bare_key, linked_key
end

local function simple_polity_bare_label_setter()
	return function(labels, group, key, value)
		local bare_key, linked_key = export.construct_bare_and_linked_version(key)
		local keydesc = value.keydesc or linked_key
		-- wp= defaults to true (Wikipedia article matches bare key = label)
		local wp = value.wp
		if wp == nil then
			wp = true
		end
		-- wpcat= defaults to wp= (if Wikipedia article has its own name, Wikipedia category and Commons category generally follow)
		local wpcat = value.wpcat
		if wpcat == nil then
			wpcat = wp
		end
		-- commonscat= defaults to wpcat= (if Wikipedia category has its own name, Commons category generally follows)
		local commonscat = value.commonscat
		if commonscat == nil then
			commonscat = wpcat
		end
		labels = {
			type = "topic",
			description = value.bare_category_desc or "{{{langname}}} terms related to the people, culture, or territory of " .. keydesc .. ".",
			parents = value.parents,
			wp = wp,
			wpcat = wpcat,
			commonscat = commonscat,
		}
	end
end

local function subpolity_keydesc(key, value, containing_polity, default_divtype)
	local divtype = value.divtype or default_divtype
	divtype = type(divtype) == "table" and divtype or divtype
	divtype = add_indefinite_article(divtype)
	local bare_key, linked_key = export.construct_bare_and_linked_version(key)
	local bare_containing_polity, linked_containing_polity = export.construct_bare_and_linked_version(containing_polity)
	return value.keydesc or linked_key .. ", " .. divtype .. " of " .. linked_containing_polity
end

local function apply_key_to_placename(key, key_to_placename)
	local placename = key
	if key_to_placename then
		placename = key_to_placename(key)
		if type(placename) == "table" then
			placename = placename
		end
	end
	return placename
end

-- Return whether `list_or_element` (a list of strings, or a single string) "contains" `item` (a string). If
-- `list_or_element` is a list, this returns true if `item` is in the list; otherwise it returns true if `item`
-- equals `list_or_element`.
local function list_or_element_contains(list_or_element, item)
	if type(list_or_element) == "table" then
		return m_table.contains(list_or_element, item)
	else
		return list_or_element == item
	end
end

local function subpolity_bare_label_setter(containing_polity)
	return function(labels, group, key, value)
		local placename = apply_key_to_placename(key, group.key_to_placename)
		local keydesc = subpolity_keydesc(placename, value, containing_polity, group.default_divtype)
		local bare_key, linked_key = export.construct_bare_and_linked_version(key)
		local bare_containing_polity, linked_containing_polity = export.construct_bare_and_linked_version(containing_polity)
		labels = {
			type = "topic",
			description = value.bare_category_desc or "{{{langname}}} terms related to the people, culture, or territory of " .. keydesc .. ".",
			parents = value.parents or {bare_containing_polity},
		}
	end
end

local function subpolity_value_transformer(containing_polity)
	local containing_polity_type = "country"
	if type(containing_polity) == "table" then
		containing_polity_type, containing_polity = containing_polity, containing_polity
	end
	return function(group, key, value)
		local placename = apply_key_to_placename(key, group.key_to_placename)
		value.keydesc = subpolity_keydesc(placename, value, containing_polity, group.default_divtype)
		value.containing_polity = containing_polity
		value.containing_polity_type = containing_polity_type
		value.poldiv = value.poldiv or group.default_poldiv
		value.british_spelling = value.british_spelling or group.british_spelling
		value.no_containing_polity_cat = value.no_containing_polity_cat or group.no_containing_polity_cat
		return value
	end
end

-- See the documentation for `place_cat_handler` above the definition of `export.polities` below.
function export.default_place_cat_handler(group, placetypes, placename)
	if group.placename_to_key then
		placename = group.placename_to_key(placename)
	end
	local spec = group.data
	local article = ""
	local bare_placename = placename
	if not spec then
		placename = "the " .. placename
		spec = group.data
	end
	if not spec then
		return nil
	end
	local divtype = spec.divtype or group.default_divtype
	if type(divtype) == "table" then
		for _, dt in ipairs(divtype) do
			if list_or_element_contains(placetypes, dt) then
				return placename, bare_placename
			end
		end
		return nil
	elseif list_or_element_contains(placetypes, divtype) then
		return placename, bare_placename
	else
		return nil
	end
end

-- This is typically used to define key_to_placename. It generates a function that chops off
-- part of a string using the regex TO_CHOP. To chop at the end, add $ at the end of the regex;
-- to chop at the beginning, add ^ at the beginning. It is normally used for subpolities (e.g.
-- states of the US or counties of England) when the placename of the polity as found in
-- categories includes the larger containing polity in it (e.g. "Georgia, USA" or
-- "Hampshire, England"). Typical usage is like this:
--
-- ...
-- key_to_placename = chop(", England$"),
-- ...
local function chop(to_chop)
	return function(key) return key:gsub(to_chop, "") end
end

-- This is typically used to define placename_to_key. It generates a function that appends a
-- string to the end of a given string. It does the opposite operation of chop() and is used
-- along with that function. It is normally used for subpolities (e.g. states of the US or
-- counties of England) when the placename of the polity as found in categories includes the
-- larger containing polity in it (e.g. "Georgia, USA" or "Hampshire, England"). Typical usage
-- is like this:
--
-- ...
-- placename_to_key = append(", England"),
-- ...
local function append(to_append)
	return function(placename) return placename .. to_append end
end

local function construct_russian_federal_subject_keydesc(linked_key, divtype)
	if divtype == "oblast" then
		-- Hack: Oblasts generally don't have entries under "Foo Oblast"
		-- but just under "Foo", so fix the linked key appropriately;
		-- doesn't apply to the Jewish Autonomous Oblast
		linked_key = linked_key:gsub(" Oblast%]%]", "%]%] Oblast")
	end
	return linked_key .. ", a federal subject (]) of ]"
end

local function northern_ireland_key_to_placename(key)
	key = key:gsub(", Northern Ireland$", "")
	local bare_key = key:gsub("^County ", "")
	if key == bare_key then
		return key
	else
		return {key, bare_key}
	end
end

local function northern_ireland_placename_to_key(placename)
	if not placename:find("^County ") and not placename:find("^City ") then
		placename = "County " .. placename
	end
	return placename .. ", Northern Ireland"
end

local function ireland_key_to_placename(key)
	key = key:gsub(", Ireland$", "")
	local bare_key = key:gsub("^County ", "")
	if key == bare_key then
		return key
	else
		return {key, bare_key}
	end
end

local function ireland_placename_to_key(placename)
	if not placename:find("^County ") and not placename:find("^City ") then
		placename = "County " .. placename
	end
	return placename .. ", Ireland"
end

function export.get_city_containing_polities(group, key, value)
	local containing_polities = group.containing_polities
	if type(containing_polities) == "string" then
		containing_polities = {containing_polities}
	elseif value then
		containing_polities = m_table.shallowcopy(containing_polities)
	end
	local this_containing_polities = value
	if type(value) == "string" then
		this_containing_polities = {this_containing_polities}
	end
	for n, polity in ipairs(this_containing_polities) do
		table.insert(containing_polities, n, polity)
	end
	return containing_polities
end

-- Given a containing polity of a city, possibly with preceding "the" removed,
-- find the group and key in 'export.polities'.
function export.city_containing_polity_to_group_and_key(polity)
	for _, polity_group in ipairs(export.polities) do
		local key_polity = polity
		if polity_group.placename_to_key then
			key_polity = polity_group.placename_to_key(key_polity)
		end
		if polity_group.data then
			return polity_group, key_polity
		end
		key_polity = "the " .. key_polity
		if polity_group.data then
			return polity_group, key_polity
		end
	end
	return nil
end

-----------------------------------------------------------------------------------
--                                  Polities                                     --
-----------------------------------------------------------------------------------

--[=[

The following table specifies the known polities and their properties, where a polity is either a top-level political
division (e.g. a country) or a subpolity (political subdivision of a top-level polity). Polities are gathered into
''groups'', each of which contains several items (places) that are handled similarly. Each group contains a list of all
the places contained in that group along with their properties, as well as group-specific handlers that specify common
properties of all items in the group. These items are used to construct the category description objects (i.e. the
objects that describe how to format the display of a category page, as documented in
]) for the following types of categories:

1. A bare topical category, e.g. ]. Category description objects for these are created by the
   `bare_label_setter` handler of a given group. (The term "label" is used here because the category system internally
   refers to the category name, without any language prefix, as a "label", and the corresponding per-label category
   description objects are stored in the `labels` table in a `topic cat` submodule, notably
   ].)
2. Normally, several categories of the form ],
   ], etc., for the place types listed above in `generic_place_types`.
   There is a top-level handler that will automatically create category description objects for such categories. It can
   be disabled for all place types in `generic_place_types` that aren't in `generic_place_types_for_cities` by
   specifying `is_city = true` in the data for a given item. (This is used for city-states such as Monaco and
   Vatican City.) It can also be disabled for all place types in `generic_place_types` other than "places" by specifying
   `is_former_place = true` in the data for a given item. (The group below for former countries and empires has a
   handler that specifies `is_former_place = true` for all items in the group. The reason for this is that former states
   such as Persia, East Germany, the Soviet Union and the Roman Empire should have their cities, towns, rivers and such
   listed under the current entities occupying the same area.)
3. Optionally, one or more categories of the form ],
   ], etc. These are for political subdivisions, and for historic/popular subdivisions
   that have no current political significance (e.g. ],
   ]). These are controlled by the `poldiv` (for political subdivisions) and
   `miscdiv` (for historic/popular subdivisions) keys in the data for a given item.

NOTE: Second-level political subdivisions (e.g. counties of states of the US) could be handled here but normally aren't.
Instead, there are special handlers below for US counties and Brazilian and Philippine municipalities, and
manually-created labels for certain other countries (e.g. Canadian counties). The reason for this is that all political
and historic/popular subdivisions handled here have a category like ] as their
primary parent, whereas we often want a different primary parent for second-level political subdivisions, such as
] for US counties. FIXME: We should allow the parents to be specified for
political subdivisions. This will probably necessitate another type of group-specific handler, similar to
`value_transformer` and `bare_label_setter` (see below).

NOTE: Some of the above categories are added automatically to pages that use the {{place}} template with the appropriate
values. Currently, whether or not such categories are added is controlled by ], which is independent
of the data here but in many ways duplicates it. FIXME: The two should be merged.

NOTE: There is also some duplication in ], particularly for continents and
supranational regions (e.g. "the British Isles"). FIXME: Consolidate the data there into here.

Each group consists of a table with the following keys:

* `data`: This is a table listing the polities in the group. The keys are polities in the form that they appear in a
  category like ] or ] (hence, they
  should include prefixes such as "the" and suffixes such as ", USA"). The value of a key is a property table. Its
  format is described above under "Placename Tables". Note that the property table is transformed using the group's
  `value_transformer` handler before being used.

* `value_transformer`: This function is used to transform the value of an item in `data` (an object containing
  properties of a place; see above) to the final form used by the handlers in
  ] that handle city-type and political-subdivision-type categories. It is
  passed three arguments (the group and the key and value of the data item). Its normal purpose is to add extra
  properties to the data item value, such as `containing_polity` (see above) and `keydesc` (the appropriate description
  of the place, which often includes the type of division and the country).  Some groups (in particular, the one for
  former polities, such as Persia and the Roman Empire) also add `is_former_place = true`. The reason these extra
  properties are added by a function like this instead of included directly is that they are typically the same or
  similar for all items in a group, and including them directly would be duplicative. Note that there is a
  preconstructed function subpolity_bare_label_setter() (for subpolities of top-level polities) to help.

* `bare_label_setter`: This function adds an entry in the `labels` table for
  ] for bare topical categories such as ],
  ] or ]. It is passed four arguments (the `labels`
  table, the group and the key and value of the data item). There are preconstructed functions to help here, such as
  simple_polity_bare_label_setter() (for top-level polities) and subpolity_bare_label_setter() (for subpolities of
  top-level polities). This function often makes use of the `parents` and/or `description` keys in the data item's
  value (see above).

* `place_cat_handler`: Used in conjunction with {{place}} to properly categorize placenames. It is passed three
  arguments: GROUP, the spec for a given group; PLACETYPES, the placetype of a place or a list of such placetypes;
  and PLACENAME, the corresponding placename as found in a holonym, i.e. without any preceding "the". If a place
  matching PLACENAME is found in GROUP, and the place's placetype is compatible with PLACETYPE, return two arguments:
  the form of PLACENAME to be used in categories that include a preceding article (usually "the"), and the bare form
  of PLACENAME, without a preceding article. Otherwise, return nil. Here, "compatible" means that any of the
  placetypes in PLACETYPES is equal to any of the known placetypes of PLACENAME. (Most placenames in most groups have
  a single associated placetype, but some have more than one, e.g. Wales, which is associated with both
  "constituent country" and "country", and will be recognized for categorization purposes if either placetype is used.)
  For example, given the placename "Bashkortostan", placetype "republic", and group data associated with Russian
  federal subjects, the first return value will be "the Republic of Bashkortostan" and the second return value will be
  "Republic of Bashkortostan". Note that the first value is always equal to the key in `group.data` that describes the
  placename. (Both return values are needed because some categories contain the article, e.g. [[:Category:Places in the
  Republic of Bashkortostan]], and some don't, in particular the bare topical category
  ].) If omitted, the function default_place_cat_handler() is used.

* `default_divtype`: The default entity type for entities in this group, if not overidden at the entity level. See
  `divtype` above under "Placename Tables".
]=]

export.polities = {
	-- countries
	{
		bare_label_setter = simple_polity_bare_label_setter(),
		value_transformer = function(group, key, value)
			value.british_spelling = value.british_spelling or group.british_spelling
			return value
		end,
		default_divtype = "country",
		data = export.countries,
	},

	-- pseudo-countries: typically overseas territories or de-facto independent countries, which in both cases
	-- are not internationally recognized as sovereign nations but which we treat similarly to countries.
	{
		bare_label_setter = simple_polity_bare_label_setter(),
		value_transformer = function(group, key, value)
			value.british_spelling = value.british_spelling or group.british_spelling
			return value
		end,
		default_divtype = "country",
		data = export.pseudo_countries,
	},

	-- former countries and such; we don't create "Cities in ..." categories because they don't exist anymore
	{
		bare_label_setter = simple_polity_bare_label_setter(),
		value_transformer = function(group, key, value)
			value.british_spelling = value.british_spelling or group.british_spelling
			value.is_former_place = true
			return value
		end,
		default_divtype = "country",
		data = export.former_countries,
	},

	-- states and territories of Australia
	{
		bare_label_setter = subpolity_bare_label_setter("Australia"),
		value_transformer = subpolity_value_transformer("Australia"),
		default_divtype = "state",
		british_spelling = true,
		data = export.australian_states_and_territories,
	},

	-- states of Austria
	{
		bare_label_setter = subpolity_bare_label_setter("Austria"),
		value_transformer = subpolity_value_transformer("Austria"),
		default_divtype = "state",
		british_spelling = true,
		default_poldiv = {{"municipalities", parent="municipalities of Austria"}},
		data = export.austrian_states,
	},

	-- divisions of Bangladesh
	{
		key_to_placename = chop(" Division$"),
		placename_to_key = append(" Division"),
		bare_label_setter = subpolity_bare_label_setter("Bangladesh"),
		value_transformer = subpolity_value_transformer("Bangladesh"),
		default_divtype = "division",
		british_spelling = true,
		default_poldiv = {{"districts", parent="districts of Bangladesh"}},
		data = export.bangladeshi_divisions,
	},

	-- states of Brazil
	{
		key_to_placename = chop(", Brazil$"),
		placename_to_key = append(", Brazil"),
		bare_label_setter = subpolity_bare_label_setter("Brazil"),
		value_transformer = subpolity_value_transformer("Brazil"),
		default_divtype = "state",
		default_poldiv = {{"municipalities", parent="municipalities of Brazil"}},
		data = export.brazilian_states,
	},

	-- provinces and territories of Canada
	{
		bare_label_setter = subpolity_bare_label_setter("Canada"),
		value_transformer = subpolity_value_transformer("Canada"),
		default_divtype = "province",
		british_spelling = true,
		data = export.canadian_provinces_and_territories,
	},

	-- provinces and autonomous regions of China
	{
		bare_label_setter = subpolity_bare_label_setter("China"),
		value_transformer = subpolity_value_transformer("China"),
		default_divtype = "province",
		data = export.chinese_provinces_and_autonomous_regions,
	},

	-- regions of Finland
	{
		key_to_placename = chop(", Finland$"),
		placename_to_key = append(", Finland"),
		bare_label_setter = subpolity_bare_label_setter("Finland"),
		value_transformer = subpolity_value_transformer("Finland"),
		default_divtype = "region",
		default_poldiv = {{"municipalities", parent="municipalities of Finland"}},
		british_spelling = true,
		data = export.finnish_regions,
	},

	-- administrative regions of France
	{
		bare_label_setter = subpolity_bare_label_setter("France"),
		value_transformer = subpolity_value_transformer("France"),
		-- Canonically these are 'administrative regions' but also categorize if identified as a 'region'.
		default_divtype = {"administrative region", "region"},
		british_spelling = true,
		data = export.french_administrative_regions,
	},

	-- states of Germany
	{
		bare_label_setter = subpolity_bare_label_setter("Germany"),
		value_transformer = subpolity_value_transformer("Germany"),
		default_divtype = "state",
		british_spelling = true,
		data = export.german_states,
	},

	-- states and union territories of India
	{
		bare_label_setter = subpolity_bare_label_setter("India"),
		value_transformer = subpolity_value_transformer("India"),
		default_divtype = "state",
		british_spelling = true,
		data = export.indian_states_and_union_territories,
	},

	-- provinces of Indonesia
	{
		bare_label_setter = subpolity_bare_label_setter("Indonesia"),
		value_transformer = subpolity_value_transformer("Indonesia"),
		default_divtype = "province",
		british_spelling = true,
		data = export.indonesian_provinces,
	},

	-- counties of Ireland
	{
		key_to_placename = ireland_key_to_placename,
		placename_to_key = ireland_placename_to_key,
		bare_label_setter = subpolity_bare_label_setter("Ireland"),
		value_transformer = subpolity_value_transformer("Ireland"),
		default_divtype = "county",
		british_spelling = true,
		data = export.irish_counties,
	},

	-- regions of Italy
	{
		bare_label_setter = subpolity_bare_label_setter("Italy"),
		value_transformer = subpolity_value_transformer("Italy"),
		default_divtype = "region",
		british_spelling = true,
		data = export.italian_regions,
	},

	-- prefectures of Japan
	{
		key_to_placename = chop(" Prefecture$"),
		placename_to_key = japanese_placename_to_key,
		-- We can't use the normal subpolity_bare_label_setter() because we set a special parent
		-- (normally the parent would just be "Japan"). FIXME: Do we want this difference?
		-- Or do we want e.g. provinces in China to have a parent "Provinces of China" instead of
		-- just "China"?
		bare_label_setter = function(labels, group, key, value)
			labels = {
				type = "topic",
				description = "{{{langname}}} terms related to ], a ] of ].",
				parents = {"Prefectures of Japan"},
			}
		end,
		value_transformer = subpolity_value_transformer("Japan"),
		default_divtype = "prefecture",
		data = export.japanese_prefectures,
	},

	-- regions of Malta
	{
		key_to_placename = chop(", Malta$"),
		placename_to_key = append(", Malta"),
		bare_label_setter = subpolity_bare_label_setter("Malta"),
		value_transformer = subpolity_value_transformer("Malta"),
		default_divtype = "region",
		british_spelling = true,
		-- The regions are too generic in name. For example, "Central Region" exists elsewhere, e.g. in South Africa.
		no_containing_polity_cat = true,
		data = export.maltese_regions,
	},


	-- Mexican states
	{
		bare_label_setter = subpolity_bare_label_setter("Mexico"),
		value_transformer = subpolity_value_transformer("Mexico"),
		default_divtype = "state",
		data = export.mexican_states,
	},

	-- regions of Morocco
	{
		bare_label_setter = subpolity_bare_label_setter("Morocco"),
		value_transformer = subpolity_value_transformer("Morocco"),
		default_divtype = "region",
		british_spelling = true,
		data = export.moroccan_regions,
	},

	-- provinces of the Netherlands
	{
		key_to_placename = chop(", Netherlands$"),
		placename_to_key = append(", Netherlands"),
		bare_label_setter = subpolity_bare_label_setter("the Netherlands"),
		value_transformer = subpolity_value_transformer("the Netherlands"),
		default_divtype = "province",
		default_poldiv = {{"municipalities", parent="municipalities of the Netherlands"}},
		british_spelling = true,
		data = export.netherlands_provinces,
	},

	-- counties of Norway
	{
		bare_label_setter = subpolity_bare_label_setter("Norway"),
		value_transformer = subpolity_value_transformer("Norway"),
		default_divtype = "county",
		british_spelling = true,
		data = export.norwegian_counties,
	},

	-- provinces of the Philippines
	{
		key_to_placename = chop(", Philippines$"),
		placename_to_key = append(", Philippines"),
		bare_label_setter = subpolity_bare_label_setter("the Philippines"),
		value_transformer = subpolity_value_transformer("the Philippines"),
		default_divtype = "province",
		default_poldiv = {{"municipalities", parent="municipalities of the Philippines"}},
		data = export.philippine_provinces,
	},

	-- counties of Romania
	{
		key_to_placename = chop(" County, Romania$"),
		placename_to_key = append(" County, Romania"),
		bare_label_setter = subpolity_bare_label_setter("Romania"),
		value_transformer = subpolity_value_transformer("Romania"),
		default_divtype = "county",
		british_spelling = true,
		data = export.romanian_counties,
	},

	-- federal subjects of Russia
	{
		-- No current need for key_to_placename because it's only used in subpolity_bare_label_setter
		-- and subpolity_value_transformer, and we override both handlers.
		placename_to_key = russian_placename_to_key,
		bare_label_setter = function(labels, group, key, value)
			local divtype = value.divtype or group.default_divtype
			if type(divtype) == "table" then
				divtype = divtype
			end
			local bare_key, linked_key = export.construct_bare_and_linked_version(key)
			labels = {
				type = "topic",
				description = "{{{langname}}} terms related to " .. construct_russian_federal_subject_keydesc(linked_key, divtype) .. ".",
				parents = {ucfirst(divtype) .. "s of Russia"},
			}
		end,
		value_transformer = function(group, key, value)
			value.containing_polity = "Russia"
			local divtype = value.divtype or group.default_divtype
			if type(divtype) == "table" then
				divtype = divtype
			end
			local bare_key, linked_key = export.construct_bare_and_linked_version(key)
			value.keydesc = construct_russian_federal_subject_keydesc(linked_key, divtype)
			return value
		end,
		default_divtype = "oblast",
		british_spelling = true,
		data = export.russian_federal_subjects,
	},

	-- autonomous communities of Spain
	{
		bare_label_setter = subpolity_bare_label_setter("Spain"),
		value_transformer = subpolity_value_transformer("Spain"),
		default_divtype = "autonomous community",
		british_spelling = true,
		data = export.spanish_autonomous_communities,
	},

	-- states of the United States
	{
		key_to_placename = chop(", USA$"),
		placename_to_key = append(", USA"),
		bare_label_setter = subpolity_bare_label_setter("the United States"),
		value_transformer = subpolity_value_transformer("the United States"),
		default_divtype = "state",
		default_poldiv = {
			{"counties", parent="counties of the United States"},
			{"county seats", parent="county seats of the United States"},
		},
		data = export.us_states,
	},

	-- constituent countries and provinces of the United Kingdom
	{
		bare_label_setter = subpolity_bare_label_setter("the United Kingdom"),
		value_transformer = subpolity_value_transformer("the United Kingdom"),
		default_divtype = {"constituent country", "country"},
		british_spelling = true,
		-- Don't create categories like 'Category:en:Towns in the United Kingdom'
		-- or 'Category:en:Places in the United Kingdom'.
		no_containing_polity_cat = true,
		data = export.uk_constituent_countries,
	},

	-- counties of England
	{
		key_to_placename = chop(", England$"),
		placename_to_key = append(", England"),
		bare_label_setter = subpolity_bare_label_setter("England"),
		value_transformer = subpolity_value_transformer({"constituent country", "England"}),
		default_divtype = "county",
		default_poldiv = {{"districts", parent="districts of England"}},
		british_spelling = true,
		data = export.english_counties,
	},

	-- counties of Northern Ireland
	{
		key_to_placename = northern_ireland_key_to_placename,
		placename_to_key = northern_ireland_placename_to_key,
		bare_label_setter = subpolity_bare_label_setter("Northern Ireland"),
		value_transformer = subpolity_value_transformer({"constituent country", "Northern Ireland"}),
		default_divtype = "county",
		british_spelling = true,
		data = export.northern_irish_counties,
	},

	-- council areas of Scotland
	{
		key_to_placename = chop(", Scotland$"),
		placename_to_key = append(", Scotland"),
		bare_label_setter = subpolity_bare_label_setter("Scotland"),
		value_transformer = subpolity_value_transformer({"constituent country", "Scotland"}),
		default_divtype = "council area",
		british_spelling = true,
		data = export.scottish_council_areas,
	},

	-- principal areas (cities, counties and county boroughs) of Wales
	{
		key_to_placename = chop(", Wales$"),
		placename_to_key = append(", Wales"),
		bare_label_setter = subpolity_bare_label_setter("Wales"),
		value_transformer = subpolity_value_transformer({"constituent country", "Wales"}),
		default_divtype = "county borough",
		british_spelling = true,
		data = export.welsh_principal_areas,
	},

}

return export