Jump to content

Module:ForeignLanguageTextTable: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Created page with 'local p = {} function p.generateTable(frame) -- Get parameters from the template call local args = frame:getParent().args -- Base of the table local tableStart = '{| class="wikitable"\n|+\n' local tableHeader = '!{{ISO 639 name|' .. args.lang1 .. '}}\n!{{ISO 639 name|' .. args.lang2 .. '}}\n|-\n' local tableBody = '' -- Function to add a row for text and translation local function addRow(text, translation) if text...'
 
No edit summary
Line 4: Line 4:
-- Get parameters from the template call
-- Get parameters from the template call
local args = frame:getParent().args
local args = frame:getParent().args

-- Handle args explicitly to ensure parameters are properly retrieved
local lang1 = args['lang1'] or 'unknown'
local lang2 = args['lang2'] or 'unknown'


-- Base of the table
-- Base of the table
local tableStart = '{| class="wikitable"\n|+\n'
local tableStart = '{| class="wikitable"\n|+\n'
local tableHeader = '!{{ISO 639 name|' .. args.lang1 .. '}}\n!{{ISO 639 name|' .. args.lang2 .. '}}\n|-\n'
local tableHeader = '!{{ISO 639 name|' .. lang1 .. '}}\n!{{ISO 639 name|' .. lang2 .. '}}\n|-\n'
local tableBody = ''
local tableBody = ''


Line 13: Line 17:
local function addRow(text, translation)
local function addRow(text, translation)
if text and translation and text ~= '' and translation ~= '' then
if text and translation and text ~= '' and translation ~= '' then
tableBody = tableBody .. '|{{Langx|' .. args.lang1 .. '|' .. text .. '|label=none}}\n'
tableBody = tableBody .. '|{{Langx|' .. lang1 .. '|' .. text .. '|label=none}}\n'
tableBody = tableBody .. '|{{Langx|' .. args.lang2 .. '|' .. translation .. '|label=none|italic=' .. (args.useitalic or 'no') .. '}}\n|-\n'
tableBody = tableBody .. '|{{Langx|' .. lang2 .. '|' .. translation .. '|label=none|italic=' .. (args.useitalic or 'no') .. '}}\n|-\n'
end
end
end
end


-- Add the first two rows (mandatory ones)
-- Add the first two rows (mandatory ones)
addRow(args.text1, args.translation1)
addRow(args['text1'], args['translation1'])
addRow(args.text2, args.translation2)
addRow(args['text2'], args['translation2'])


-- Check optional text/translation fields dynamically (text3, text4, etc.)
-- Check optional text/translation fields dynamically (text3, text4, etc.)

Revision as of 17:42, 17 October 2024

local p = {}

function p.generateTable(frame)
    -- Get parameters from the template call
    local args = frame:getParent().args

    -- Handle args explicitly to ensure parameters are properly retrieved
    local lang1 = args['lang1'] or 'unknown'
    local lang2 = args['lang2'] or 'unknown'

    -- Base of the table
    local tableStart = '{| class="wikitable"\n|+\n'
    local tableHeader = '!{{ISO 639 name|' .. lang1 .. '}}\n!{{ISO 639 name|' .. lang2 .. '}}\n|-\n'
    local tableBody = ''

    -- Function to add a row for text and translation
    local function addRow(text, translation)
        if text and translation and text ~= '' and translation ~= '' then
            tableBody = tableBody .. '|{{Langx|' .. lang1 .. '|' .. text .. '|label=none}}\n'
            tableBody = tableBody .. '|{{Langx|' .. lang2 .. '|' .. translation .. '|label=none|italic=' .. (args.useitalic or 'no') .. '}}\n|-\n'
        end
    end

    -- Add the first two rows (mandatory ones)
    addRow(args['text1'], args['translation1'])
    addRow(args['text2'], args['translation2'])

    -- Check optional text/translation fields dynamically (text3, text4, etc.)
    for i = 3, 10 do  -- Adjust the loop limit based on how many pairs you want to support
        local text = args['text' .. i]
        local translation = args['translation' .. i]
        addRow(text, translation)
    end

    -- Combine the table parts
    local tableEnd = '|}\n'
    return tableStart .. tableHeader .. tableBody .. tableEnd
end

return p