Module:TranslateThis: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
(6 intermediate revisions by the same user not shown) | |||
Line 15: | Line 15: | ||
end | end | ||
local lang = 'en' -- I don't know of any other way to get the user's language... | |||
local args = shallowcopy(frame:getParent().args) | local args = shallowcopy(frame:getParent().args) | ||
local anchor = args.anchor | local anchor = args.anchor | ||
Line 33: | Line 32: | ||
for i, v in pairs( args ) do | for i, v in pairs( args ) do | ||
if v ~= "" then | if v ~= "" then | ||
default = default .. ' / <span lang="' .. i .. '">' .. v .. '</span> <small>(' .. i .. ')</small>' | |||
end | |||
end | |||
default = default:sub( 4 ) | |||
args.default=default | |||
local newlang | local newlang | ||
result, newlang = fb._langSwitch(args, lang) | result, newlang = fb._langSwitch(args, lang) | ||
if not newlang then | if not newlang then | ||
result = '' | result = '' | ||
elseif newlang~='default' then | |||
result = '<span lang="' .. newlang .. '">' .. result .. '</span> <small>(' .. newlang .. ')</small>' | |||
end | |||
local langname = mw.language.fetchLanguageName( lang, lang ) | |||
if langname ~= "" and newlang then | |||
result = result .. " – " .. frame:expandTemplate( { title = "Help translate", args = { langname } } ) | |||
end | |||
end | end | ||
return anchor .. result | return anchor .. result | ||
end} | end} |
Latest revision as of 14:07, 13 May 2020
Documentation for this module may be created at Module:TranslateThis/doc
local fb = require('Module:Fallback')
return { main = function( frame )
function shallowcopy(orig)
if type(orig) ~= 'table' then
return orig
end
local result = {}
for key, value in pairs(orig) do
result[key] = value
end
return result
end
local lang = 'en' -- I don't know of any other way to get the user's language...
local args = shallowcopy(frame:getParent().args)
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 ''
local result = args[ lang ]
if result and result ~= '' then
result = '<span lang="' .. lang .. '">' .. result .. '</span>'
else
local default = {}
for i, v in pairs( args ) do
if v ~= "" then
default = default .. ' / <span lang="' .. i .. '">' .. v .. '</span> <small>(' .. i .. ')</small>'
end
end
default = default:sub( 4 )
args.default=default
local newlang
result, newlang = fb._langSwitch(args, lang)
if not newlang then
result = ''
elseif newlang~='default' then
result = '<span lang="' .. newlang .. '">' .. result .. '</span> <small>(' .. newlang .. ')</small>'
end
local langname = mw.language.fetchLanguageName( lang, lang )
if langname ~= "" and newlang then
result = result .. " – " .. frame:expandTemplate( { title = "Help translate", args = { langname } } )
end
end
return anchor .. result
end}