Module:CountryData: Difference between revisions

// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
-- Module:CountryData
--[[
-- Unified module for country data management.
* Name: CountryData
--
* Author: Mark W. Datysgeld
-- Features:
* Description: Unified module for country data management with JSON loading, normalization, region mapping, and Semantic MediaWiki integration
--  * Loads country data from JSON stored in Data:CountryDataset.json
* Notes: Loads from Data:CountryDataset.json; normalizes country names to canonical forms; maps countries to ICANN regions; provides extensible property access; formats country lists with region-specific emoji styling; processes countries for category assignment
--  * Normalizes country names to canonical forms
]]
--  * Maps countries to ICANN regions
--  * Provides extensible property access
--  * Integrates with Semantic MediaWiki
--  * Formats country lists with region-specific emoji styling
--  * Processes countries for category assignment


-- Dependencies
-- Dependencies
Line 525: Line 520:


     local ListGeneration = require('Module:ListGeneration')
     local ListGeneration = require('Module:ListGeneration')
    local itemsToProcess = {}
    -- First, check if the entire string is a single, valid country.
    -- This correctly handles names like "Trinidad and Tobago".
    local singleCountryName = CountryData.normalizeCountryName(value)
    if singleCountryName ~= "(Unrecognized)" then
        -- If it's a valid country, treat it as a single item.
        table.insert(itemsToProcess, value)
    else
        -- If not a single country, assume it's a list and split ONLY by semicolon.
        -- This is safer than letting ListGeneration guess the delimiter.
        for item in string.gmatch(value, "[^;]+") do
            local trimmed = item:match("^%s*(.-)%s*$")
            if trimmed and trimmed ~= "" then
                table.insert(itemsToProcess, trimmed)
            end
        end
    end


     -- Define the item hook for country-specific formatting
     -- Define the item hook for country-specific formatting
Line 547: Line 560:
     }
     }


     return ListGeneration.createList(value, options)
    -- Pass the pre-processed table of items to the list generator.
     return ListGeneration.createList(itemsToProcess, options)
end
end