Modul:place/shared-data

Üdvözlöm, Ön a Modul:place/shared-data szó jelentését keresi. A DICTIOUS-ban nem csak a Modul:place/shared-data szó összes szótári jelentését megtalálod, hanem megismerheted az etimológiáját, a jellemzőit és azt is, hogyan kell a Modul:place/shared-data szót egyes és többes számban mondani. Minden, amit a Modul:place/shared-data szóról tudni kell, itt található. A Modul:place/shared-data szó meghatározása segít abban, hogy pontosabban és helyesebben fogalmazz, amikor beszélsz vagy írsz. AModul:place/shared-data és más szavak definíciójának ismerete gazdagítja a szókincsedet, és több és jobb nyelvi forráshoz juttat.

A modult a Modul:place/shared-data/doc lapon tudod dokumentálni

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")

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

-- Recognized political and misc. subdivisions. The key is the plural
-- subdivision and the value is the equivalent description, with links.
export.political_subdivisions = {
	 = "] ]s",
	 = "]s",
	 = "]s",
	 = "]s",
	 = "]",
	 = "] ]s",
	 = "]s",
	 = "]s",
	 = "] ]s",
	 = "]s",
	 = "]s",
	 = "]s",
	 = "]s",
	 = "]s",
	 = "]s",
	 = "]es",
	 = "]",
	 = "]",
	 = "] ]",
	 = "]s",
	 = "]",
	 = "]s",
	 = "]s",
	 = "]",
	 = "]s",
	 = "]s",
	 = "]",
	 = "]s",
	 = "]s and ]s",
	 = "]s",
	 = "]s",
	 = "]",
	 = "] ]s",
	 = "] ]",
	 = "] ]",
	 = "]s",
	 = "]s",
	 = "]s",
	 = "]s",
	 = "]s",
	 = "]",
	 = "]s",
	 = "]s",
	 = "]",
	 = "]s",
	 = "]es",
	 = "]s",
	 = "]s",
	 = "]s",
	 = "]s",
	 = "]s",
	 = "]",
	 = "]",
	 = "]s",
	 = "]",
	 = "]s",
	 = "]s",
	 = "]s",
	 = "]",
	 = "]s",
	 = "]s",
	 = "]",
	 = "]s",
	 = "]s",
	 = "]s",
	 = "]s",
	 = "]",
	 = "]",
	 = "]",
	 = "]s",
	 = "]",
	 = "]s",
	 = "]s",
}

-- 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",
	 = "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 topical categories for cities/towns/rivers/etc. in a given polity,
   e.g. 'fr:Cities in Alabama, USA' for French terms for cities in Alabama. Note that each
   such category (this in fact applies to all topical categories) has a parent category such as
   'Cities in Alabama, USA' that groups all language-specific topic categories together.
2. To generate the text of topical categories for political subdivisions of a given polity,
   e.g. 'de:Provinces of the Netherlands', 'es:Counties of Alabama', or
   'pt:Municipalities of Amazonas, Brazil'.
3. To generate the text of a "bare label" topical category directly associated with the polity,
   such as 'de:Netherlands', 'es:Alabama, USA', or 'pt:Amazonas, Brazil'.
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 'en:Cities in Alabama, USA'.

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
'de:Provinces of the Netherlands' or 'fr:Cities in Alabama, USA' (hence, they should include
prefixes such as "the" and suffixes such as ", USA"). Transforming these keys to the form that
appears in the bare label category (e.g. 'de:Netherlands'), 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 'de:Provinces of
  the Netherlands' and 'pt:Municipalities of the Netherlands' to be created. These categories have a
  primary parent "Political subdivisions" (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 'pl:Provinces of Ireland' to be
  created. These categories differ from political subdivision categories in that their primary parent
  is the country name rather than "Political subdivisions".

- 'nocities': If 'true', don't recognize categories such as 'en:Cities in Monaco' or 'fr:Rivers in the
  Soviet Union'. NOTE: This key is often 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 label category. For example, if 'parents = {"Europe", "Asia"}'
  is specified for "Turkey", bare label categories such as 'en:Turkey' will have parent categories
  'en:Europe' and 'en:Asia'. 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_label_desc': String specifying the description used in the bare label 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
  'en:Cities in Guangdong" will have its primary parent (i.e. the parent that appears in the breadcrumbs at
  the top of the category page) as "Cities in China". If containing_polity is omitted, as in top-level
  polities, the primary parent will simply be "Cities" (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 = {"regions", "provinces"}, 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},
	 = {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"}},
	 = {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"}, british_spelling = true},
	 = {parents = {"Africa"}, poldiv = {"provinces", "territories"}},
	 = {parents = {"Europe"}, poldiv = {"regions", "municipalities", "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 = {"Africa"}, 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"}, 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 = {"regions", "departments", "collectivities", "municipalities",
		"territories"}, miscdiv = {"provinces"}, british_spelling = true},
	 = {parents = {"Africa"}, poldiv = {"provinces", "departments"}},
	 = {parents = {"Africa"}, poldiv = {"divisions", "districts"}, british_spelling = true},
	 = {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 = {"Europe", "Asia"}, 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 = {"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"}, british_spelling = true},
	 = {parents = {"Europe"}, nocities = 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"}, british_spelling = true},
	 = {parents = {"Polynesia"}, poldiv = {"regions", "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", "dependencies"},
		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"}, 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 = {"Africa"}, british_spelling = true},
	 = {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", "dependencies"},
		keydesc = "the ] of Great Britain and Northern Ireland", british_spelling = true},
	 = {parents = {"North America"},
		poldiv = {"counties", "county seats", "states", "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"}, nocities = 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"}},
	-- 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},
	-- 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", "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", "territory"}, parents = {"British Isles", "Europe"}, british_spelling = true},
	-- self-governing British Crown dependency; technically called the Bailiwick of Jersey
	 = {divtype = {"crown dependency", "dependency", "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"}},
	-- 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},
	-- 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"},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
}

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

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_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.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.mexican_states = {
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
	 = {},
}

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 = {
	 = {},
	 = {},
	 = {nocities = true},
	 = {},
	 = {},
	 = {},
	 = {nocities = true},
	 = {},
}

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 = {"Brazil", divtype="country"},
		data = {
			-- This only lists cities, not metro areas, over 1,000,000 inhabitants.
			 = {"São Paulo"},
			 = {"Rio de Janeiro"},
			 = {"Distrito Federal"},
			 = {"Bahia"},
			 = {"Ceará"},
			 = {"Minas Gerais"},
			 = {"Amazonas"},
			 = {"Paraná"},
			 = {"Pernambuco"},
			 = {"Goiás"},
			 = {"Pará"},
			 = {"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"},
			 = {"Ontario"},
		},
	},
	{
		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"},
			 = {"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 = "region",
		containing_polities = {"France", divtype="country"},
		data = {
			 = {"Île-de-France"},
			 = {"Auvergne-Rhône-Alpes"},
			 = {"Provence-Alpes-Côte d'Azur"},
			 = {"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"}, -- 1,373,630
			 = {"Saitama"}, -- 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"}, -- 938,695
			 = {"Osaka"}, -- 835,333
			 = {"Niigata"}, -- 813,053
			 = {"Shizuoka"}, -- 811,431
			 = {"Shizuoka"}, -- 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"},
			 = {"Krasnoyarsk Krai", divtype="krai"},
			 = {"Voronezh Oblast"},
			 = {"Perm Krai", divtype="krai"},
			 = {"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"}},
		},
	},
	-- cities in the US
	{
		default_divtype = "state",
		containing_polities = {"the United States", divtype="country"},
		data = {
			-- top 50 CSA's by population, with the top and sometimes 2nd or 3rd city listed
			 = {"New York"},
			 = {"New Jersey"},
			 = {"California"},
			 = {"California"},
			 = {"California"},
			 = {"Illinois"},
			 = {},
			 = {"Maryland"},
			 = {"California"},
			 = {"California"},
			 = {"California"},
			 = {"Massachusetts"},
			 = {"Rhode Island"},
			 = {"Texas"},
			 = {"Texas"},
			 = {"Pennsylvania"},
			 = {"Texas"},
			 = {"Florida"},
			 = {"Georgia"},
			 = {"Michigan"},
			 = {"Arizona"},
			 = {"Arizona"},
			 = {"Washington"},
			 = {"Florida"},
			 = {"Minnesota"},
			 = {"Ohio"},
			 = {"Colorado"},
			 = {"California"},
			 = {"Oregon"},
			 = {"Florida"},
			 = {"Missouri"},
			 = {"North Carolina"},
			 = {"California"},
			 = {"Pennsylvania"},
			 = {"Utah"},
			 = {"Texas"},
			 = {"Ohio"},
			 = {"Missouri"},
			 = {"Indiana"},
			 = {"Nevada"},
			 = {"Ohio"},
			 = {"Texas"},
			 = {"Wisconsin"},
			 = {"North Carolina"},
			 = {"Tennessee"},
			 = {"Virginia"},
			 = {"Virginia"},
			 = {"North Carolina"},
			 = {"North Carolina"},
			 = {"Florida"},
			 = {"Louisiana"},
			 = {"Kentucky"},
			 = {"South Carolina"},
			 = {"Connecticut"},
			 = {"Oklahoma"},
			 = {"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 = {
			 = {"Austria"},
			 = {"Belarus"},
			 = {"Belgium"},
			 = {"Belgium"},
			 = {"Bulgaria"},
			 = {"Croatia"},
			 = {"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"}},
			 = {{"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"},
			 = {"Sweden"},
			 = {"Switzerland"},
			 = {alias_of="Zürich"},
			 = {"Turkey"},
			 = {"Ukraine"},
			 = {"Ukraine"},
			 = {"Ukraine"},
		},
	},
}

-----------------------------------------------------------------------------------
--                              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

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
		labels = {
			description = value.bare_label_desc or "{{{langname}}} terms related to the people, culture, or territory of " .. keydesc .. ".",
			parents = value.parents,
		}
	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

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 = {
			description = value.bare_label_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
		return value
	end
end

local function default_place_cat_handler()
	return function(group, placetype, holonym_placetype, holonym_placename)
		if group.placename_to_key then
			holonym_placename = group.placename_to_key(holonym_placename)
		end
		local spec = group.data
		if not spec then
			holonym_placename = "the " .. holonym_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 dt == holonym_placetype then
					return holonym_placename
				end
			end
			return nil
		else
			return divtype == holonym_placetype and holonym_placename or nil
		end
	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 consists of one or more 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 labels
for the following types of categories:

1. A bare label category, e.g. 'en:Netherlands'. Labels for these are created by the
   'bare_label_setter' handler of a given group.
2. Normally, several categories of the form 'fr:Cities in the Netherlands',
   'es:Rivers in New Mexico, USA', etc., for the place types listed above in 'generic_place_types'.
   There is a top-level handler that will automatically create labels for such categories,
   although it can be disabled by specifying 'nocities = true' in the data for a given item.
   (This is used for city-states such as Monaco and Vatican City.) One of the groups below,
   the one for former countries and empires, has a handler that specifies 'nocities = 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 will have their cities, towns, rivers
   and such will be listed under the current entities occupying the same area.
3. Optionally, one or more categories of the form 'de:Provinces of the Netherlands',
   'pt:Counties of Wales', etc. These are for political subdivisions, and for historic/popular
   subdivisions that have no current political significance (e.g. 'nl:Provinces of Ireland',
   'zh:Regions of the United States'). 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 "en:Political subdivisions" as their primary parent, whereas
we often want a different primary parent for second-level political subdivisions, such as
"en:Counties of the United States" 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 'de:Provinces of the Netherlands' or 'fr:Cities in Alabama, USA'
	 (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 'nocities = 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 bare label
     categories such as 'en:Netherlands', 'fr:Alabama, USA' or 'ru:Republic of Tatarstan'.
	 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.
     Given four arguments (GROUP, the spec for a given group; PLACENAME, the placename for
	 a given place; HOLONYM_PLACETYPE, the placetype of a holonym of a place [e.g. "country" for
	 a location in a country]; and HOLONYM_PLACENAME, the name of a holonym of a place [e.g.
	 "France" for a location in France]), return the key in DATA correponding to HOLONYM_PLACENAME,
	 but only if the placetype of that key matches HOLONYM_PLACETYPE.

   * '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,
		place_cat_handler = default_place_cat_handler(),
		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,
		place_cat_handler = default_place_cat_handler(),
		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.nocities = true
			return value
		end,
		place_cat_handler = default_place_cat_handler(),
		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"),
		place_cat_handler = default_place_cat_handler(),
		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"),
		place_cat_handler = default_place_cat_handler(),
		default_divtype = "state",
		british_spelling = true,
		default_poldiv = {{"municipalities", parent="municipalities of Austria"}},
		data = export.austrian_states,
	},

	-- 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"),
		place_cat_handler = default_place_cat_handler(),
		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"),
		place_cat_handler = default_place_cat_handler(),
		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"),
		place_cat_handler = default_place_cat_handler(),
		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"),
		place_cat_handler = default_place_cat_handler(),
		default_divtype = "region",
		default_poldiv = {{"municipalities", parent="municipalities of Finland"}},
		british_spelling = true,
		data = export.finnish_regions,
	},

	-- regions of France
	{
		bare_label_setter = subpolity_bare_label_setter("France"),
		value_transformer = subpolity_value_transformer("France"),
		place_cat_handler = default_place_cat_handler(),
		default_divtype = "region",
		british_spelling = true,
		data = export.french_regions,
	},

	-- states of Germany
	{
		bare_label_setter = subpolity_bare_label_setter("Germany"),
		value_transformer = subpolity_value_transformer("Germany"),
		place_cat_handler = default_place_cat_handler(),
		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"),
		place_cat_handler = default_place_cat_handler(),
		default_divtype = "state",
		british_spelling = true,
		data = export.indian_states_and_union_territories,
	},

	-- 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"),
		place_cat_handler = default_place_cat_handler(),
		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"),
		place_cat_handler = default_place_cat_handler(),
		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 = {
				description = "{{{langname}}} terms related to ], a ] of ].",
				parents = {"Prefectures of Japan"},
			}
		end,
		value_transformer = subpolity_value_transformer("Japan"),
		place_cat_handler = default_place_cat_handler(),
		default_divtype = "prefecture",
		data = export.japanese_prefectures,
	},

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

	-- counties of Norway
	{
		bare_label_setter = subpolity_bare_label_setter("Norway"),
		value_transformer = subpolity_value_transformer("Norway"),
		place_cat_handler = default_place_cat_handler(),
		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"),
		place_cat_handler = default_place_cat_handler(),
		default_divtype = "province",
		default_poldiv = {{"municipalities", parent="municipalities of the Philippines"}},
		data = export.philippine_provinces,
	},

	-- 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 = {
				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,
		place_cat_handler = default_place_cat_handler(),
		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"),
		place_cat_handler = default_place_cat_handler(),
		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"),
		place_cat_handler = default_place_cat_handler(),
		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 = function(group, key, value)
			value = subpolity_value_transformer("the United Kingdom")(group, key, value)
			-- Don't create categories like 'Category:en:Towns in the United Kingdom'
			-- or 'Category:en:Places in the United Kingdom'.
			value.no_containing_polity_cat = true
			return value
		end,
		place_cat_handler = default_place_cat_handler(),
		default_divtype = {"constituent country", "country"},
		british_spelling = 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"}),
		place_cat_handler = default_place_cat_handler(),
		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"}),
		place_cat_handler = default_place_cat_handler(),
		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"}),
		place_cat_handler = default_place_cat_handler(),
		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"}),
		place_cat_handler = default_place_cat_handler(),
		default_divtype = "county borough",
		british_spelling = true,
		data = export.welsh_principal_areas,
	},

}

return export