Module:Finnish translation/Version link
Jump to navigation
Jump to search
local p = {}
local ll = require( 'Module:Language link' ).main
local function removePrefix( s, prefixes )
local final = s
for _, p in ipairs( prefixes ) do
final = final:gsub( '^' .. p, '' )
end
return mw.text.trim(final)
end
local function getLast( prefix )
return function( s )
local last = mw.ustring.match( s, '^.+%s+(%S+)$' )
return prefix .. last
end
end
local function getJava( s )
return 'Java Edition ' .. removePrefix( s, { '[Jj]ava', ' [Ee]dition', '[Jj][Ee]' } )
end
local function getBedrock( s )
return 'Bedrock Edition ' .. removePrefix( s, { '[Bb]edrock', ' [Ee]dition', '[Bb][Ee]' } )
end
local function getPocket( s )
if(s:match('Alpha') and not s:match('Realms')) then
return 'Pocket Edition ' .. mw.getCurrentFrame():callParserFunction( '#dplreplace', s, '/^(pocket edition|pocket|pe) (Alpha)? ?v?(\\d+\\.\\d+\\.\\d+)? ?(build \\d+)?/i', 'v\\3 alpha \\4' )
end
return 'Pocket Edition ' .. removePrefix( s, { '[Pp]ocket', ' [Ee]dition', '[Pp][Ee]' } )
end
local function getEducation( s )
return 'Minecraft Education ' .. removePrefix( s, { '[Ee]ducation', ' [Ee]dition', '[Ee][Dd][Uu]', '[Ee][Ee]' } )
end
local function getChinese()
return 'Minecraft China#History'
end
local function getLauncher( s )
return 'Minecraft launcher#' .. removePrefix( s, { '[Ll]auncher' } )
end
local function getPlayStation( s )
return removePrefix( s, { '[Pp]layStation', '[Pp][Ss]' } ) .. '#Legacy Console Edition'
end
local prefixFunctions = {
java = getJava,
je = getJava,
['pre-classic'] = getJava,
classic = getJava,
indev = getJava,
infdev = getJava,
alpha = getJava,
beta = getJava,
pe = getPocket,
pocket = getPocket,
be = getBedrock,
bedrock = getBedrock,
edu = getEducation,
education = getEducation,
ee = getEducation,
china = getChinese,
chinese = getChinese,
launcher = getLauncher,
earth = getLast( 'Minecraft Earth:' ),
dungeons = getLast( 'Minecraft Dungeons:' ),
['dungeons arcade'] = getLast( 'Minecraft Dungeons:' ),
legends = getLast( 'Minecraft Legends:' ),
realms = getLast( 'Realms#' ),
['360'] = getLast( 'Xbox 360 Edition ' ),
xbox360 = getLast( 'Xbox 360 Edition ' ),
xbone = getLast( 'Xbox One Edition ' ),
xb1 = getLast( 'Xbox One Edition ' ),
xbox1 = getLast( 'Xbox One Edition ' ),
ps = getPlayStation,
ps3 = getLast( 'PlayStation 3 Edition ' ),
ps4 = getLast( 'PlayStation 4 Edition ' ),
playstation = getLast( 'PlayStation 4 Edition ' ),
psv = getLast( 'PlayStation Vita Edition ' ),
psvita = getLast( 'PlayStation Vita Edition ' ),
wii = getLast( 'Wii U Edition Patch ' ),
wiiu = getLast( 'Wii U Edition Patch ' ),
switch = getLast( 'Nintendo Switch Edition ' ),
nswitch = getLast( 'Nintendo Switch Edition ' ),
['3ds'] = getLast( 'New Nintendo 3DS Edition ' ),
new = getLast( 'New Nintendo 3DS Edition ' ),
new3ds = getLast( 'New Nintendo 3DS Edition ' ),
minecraftedu = getLast( 'MinecraftEdu ' ),
launcher = getLast( 'Launcher ' ),
}
function p.version( s )
local v = s:gsub( '^[Mm]inecraft ', '' )
local prefix = mw.text.split( v, '%s' )[1]:lower()
local func = prefixFunctions[prefix]
if func then
return func( v )
else
return v
end
end
function p.main( f )
local args = f
local frame = mw.getCurrentFrame()
if f == frame then
args = require( [[Module:ProcessArgs]] ).merge( false )
end
local text
if args[2] == '' then
text = mw.ustring.match( args[1], '^.+%s+(%S+)$' )
else
text = args[2] or args[1]
end
return ll( p.version( args[1] ), text )
end
return p