Module:CountryData: Difference between revisions

// via Wikitext Extension for VSCode
Tag: Reverted
// via Wikitext Extension for VSCode
Tag: Manual revert
Line 248: Line 248:
     -- Normalize the input
     -- Normalize the input
     local normalized = NormalizationText.normalizeText(name)
     local normalized = NormalizationText.normalizeText(name)
   
    -- Debug: Show normalization steps
    local ErrorHandling = require('Module:ErrorHandling')
    local debugContext = ErrorHandling.createContext("CountryDataLookup")
    ErrorHandling.addError(debugContext, "LookupDebug",
        string.format("Looking up '%s' -> normalized: '%s'", name, normalized),
        "", false)
      
      
     -- Look up the code
     -- Look up the code
     local code = nameLookup[normalized]
     local code = nameLookup[normalized]
   
    ErrorHandling.addError(debugContext, "FirstLookupDebug",
        string.format("First lookup '%s' -> code: '%s'", normalized, code or "nil"),
        "", false)
      
      
     local result = nil
     local result = nil
     if code and data.countries[code] then
     if code and data.countries[code] then
         result = data.countries[code]
         result = data.countries[code]
        ErrorHandling.addError(debugContext, "FirstLookupSuccessDebug",
            string.format("First lookup successful: '%s' -> '%s'", normalized, code),
            "", false)
     else
     else
         -- Try with diacritics removed
         -- Try with diacritics removed
         local stripped = DiacriticNormalization.removeDiacritics(normalized)
         local stripped = DiacriticNormalization.removeDiacritics(normalized)
        ErrorHandling.addError(debugContext, "StrippedDebug",
            string.format("Stripped diacritics: '%s' -> '%s'", normalized, stripped),
            "", false)
       
         if stripped ~= normalized then
         if stripped ~= normalized then
             code = nameLookup[stripped]
             code = nameLookup[stripped]
            ErrorHandling.addError(debugContext, "SecondLookupDebug",
                string.format("Second lookup '%s' -> code: '%s'", stripped, code or "nil"),
                "", false)
           
             if code and data.countries[code] then
             if code and data.countries[code] then
                 result = data.countries[code]
                 result = data.countries[code]
                ErrorHandling.addError(debugContext, "SecondLookupSuccessDebug",
                    string.format("Second lookup successful: '%s' -> '%s'", stripped, code),
                    "", false)
             end
             end
         end
         end