Module:TranslateThis

local insert = table.insert local remove = table.remove local myFrame = mw.getCurrentFrame local myLang = myFrame:callParserFunction('Int', 'Lang'):lower:gsub('_', '-') local myLangObj = mw.language.new(myLang) local myFallbacks = myLangObj:getFallbackLanguages for i, lang in ipairs(myFallbacks) do   lang = lang:lower:gsub('_', '-') if lang == myLang then remove(myFallbacks, i)       break end end insert(myFallbacks, 1, myLang)

local p = {}

function p.main(frame) local source, anchor local args = {} for k, v in pairs(frame:getParent.args) do       if type(k) == 'string' and type(v) == 'string' then v = v:gsub('^%s+(.-)%s+$', '%1') -- Trim texts given in argument values. -- Split argument keys by language code (separated by any non-letter non-digit character); -- this allows setting the same value for multiple languages. for lang in k:lower:gsub('_', '-'):gfind('[-0-9a-z]+') do               if lang == 'source' then source = v               elseif lang == 'anchor' then anchor = v               else -- if not args[lang] then args[lang] = v               end end end end for i, lang in ipairs(myFallbacks) do       local result = args[lang] if result and result ~= '' then if lang == myLang then return result end return '' .. result .. ' ' ..               (source and ' &#91;Translate this message&#93; ' or '') end end return source and ' &#91;Translate this message&#93; ' or '' end

return p