Module:TranslateThis

Sọn Wikipedia

Documentation for this module may be created at Module:TranslateThis/doc

return {
    main = function(frame)
		local myLang = frame:preprocess("{{Int:Lang}}") -- There's still no way to get the user's language from the MW API...
        local function shallowcopy(t)
            if type(t) ~= 'table' then
                return t
            end
            local c = {}
            for k, v in pairs(t) do
                c[k] = v
            end
            return c
        end
        local args = shallowcopy(frame:getParent().args)
        local result = args[myLang]
        if result and result ~= '' then
            result = '<bdi lang="' .. myLang .. '">' .. result .. '</bdi>'
        else
            local sep = ''
            result = ''
            for k, v in pairs(args) do
                if v ~= '' and k ~= 'source' then
                    result = result .. sep .. '<bdi lang="' .. k .. '">' .. v .. '</bdi><small>&nbsp;[' .. k .. ']</small>'
                    sep = '&nbsp;/ '
                end
            end
            if args.source then
                result = result .. ' – [[:' .. args.source .. '|Translate this message.]]'
            end
        end
        local anchor = args.anchor
        args.anchor = nil
        if anchor and args[anchor] then
            anchor = args[anchor]
        end
        anchor = anchor and frame:expandTemplate{title = 'Anchor', args = {anchor}} or ''
        return anchor .. result
    end
}