Module:NormalizationLanguage: Difference between revisions

// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
Tag: Reverted
Line 716: Line 716:
     isNativeFormCache[input] = nil
     isNativeFormCache[input] = nil
     return nil
     return nil
end
-- Format multiple languages with normalization using the centralized ListGeneration module
function p.formatLanguages(inputLanguages)
    if not inputLanguages or inputLanguages == "" then return "" end
    -- Define the item hook for language-specific formatting
    local function languageItemHook(lang)
        local trimmed = lang:match("^%s*(.-)%s*$")
        if trimmed == "" then return nil end
        -- Check if the input is a native form to preserve it
        local canonicalFromNative = p.isNativeForm(trimmed)
        local normalized, originalInput
        if canonicalFromNative then
            normalized = canonicalFromNative
            originalInput = trimmed
        else
            normalized = p.normalize(trimmed)
            originalInput = nil
        end
        -- Get the native form for the normalized language
        local nativeForm = originalInput or p.getNativeForm(normalized)
       
        -- Format with native name, except for English
        if nativeForm and config.showNativeForms and normalized ~= "English" then
            return string.format("%s<br/><span style=\"display:inline-block; width:0.1em; visibility:hidden;\">*</span><span style=\"font-size:75%%;\">%s</span>", normalized, nativeForm)
        else
            return normalized
        end
    end
    -- Set the options for the list generation
    local options = {
        mode = 'bullet',
        listClass = 'template-list-language',
        itemHook = languageItemHook
    }
    -- Use the centralized list generation function
    -- This will handle single vs. multiple items consistently.
    -- For a single item, it will correctly return a one-item list.
    return ListGeneration.createList(inputLanguages, options)
end
end