അജ്ഞാത ഉപയോക്താവ്
cleanup simplifying some things
(ചെ.) (ഒരു പതിപ്പ് ഇറക്കുമതി ചെയ്തു) |
(cleanup simplifying some things) |
||
വരി 14: | വരി 14: | ||
]=] | ]=] | ||
function language_subpages( frame, transform, options ) | local function language_subpages( frame, transform, options ) | ||
local args, pargs, options = frame.args, ( frame:getParent() or {} ).args or {}, options or {}; | local args, pargs, options = frame.args, ( frame:getParent() or {} ).args or {}, options or {}; | ||
local title = args.page or args[1] or pargs.page or pargs[1] or ""; | local title = args.page or args[1] or pargs.page or pargs[1] or ""; | ||
വരി 79: | വരി 79: | ||
end | end | ||
function cloneArgs(frame) | local function cloneArgs(frame) | ||
local args, pargs = {}, {} | local args, pargs = {}, {} | ||
for k,v in pairs( frame.args ) do args[k] = v end | for k,v in pairs( frame.args ) do args[k] = v end | ||
വരി 85: | വരി 85: | ||
for k,v in pairs( frame:getParent().args ) do pargs[k] = v end | for k,v in pairs( frame:getParent().args ) do pargs[k] = v end | ||
end | end | ||
return args, pargs | return args, pargs | ||
end | end | ||
വരി 97: | വരി 97: | ||
]=] | ]=] | ||
function p.internal(frame) | function p.internal(frame) | ||
return table.concat( | |||
language_subpages( frame, | |||
function( title, page, code, name ) | |||
return mw.ustring.format( | |||
'<bdi class="language lang-%s" lang="%s">[[%s/%s|%s]]</bdi>', | |||
code, code, | |||
title, page, | |||
name | |||
); | |||
end | |||
), | |||
' <b>·</b> ' | |||
); | |||
end | end | ||
വരി 110: | വരി 117: | ||
]=] | ]=] | ||
function p.external(frame) | function p.external(frame) | ||
return table.concat( | |||
language_subpages( frame, | |||
function( title, page, code, name ) | |||
return mw.ustring.format( | |||
'<bdi class="language lang-%s" lang="%s">[%s/%s %s]</bdi>', | |||
code, code, | |||
tostring( mw.uri.fullUrl( title ) ), page:gsub( ' ', '_' ), | |||
name | |||
); | |||
end | |||
), | |||
' <b>·</b> ' | |||
); | |||
end | end | ||
വരി 160: | വരി 174: | ||
-- =p.forEachLanguage({ args= { pattern = "$lc - $lnTrP\n", inLang = "en" } }) | -- =p.forEachLanguage({ args= { pattern = "$lc - $lnTrP\n", inLang = "en" } }) | ||
function p.forEachLanguage(frame) | function p.forEachLanguage(frame) | ||
local l = require( "Module:Languages/List" ) | local l = require("Module:Languages/List") | ||
local ret = {} | local ret = {} | ||
വരി 180: | വരി 194: | ||
local l = mw.language.fetchLanguageNames() -- autonyms | local l = mw.language.fetchLanguageNames() -- autonyms | ||
local lTr | local lTr | ||
local lcIdList = require( 'Module:Languages/List' ).getSortedList( l ) | local lcIdList = require('Module:Languages/List').getSortedList( l ) | ||
if langNameTranslatedReq then | if langNameTranslatedReq then | ||
വരി 231: | വരി 245: | ||
--[=[ | --[=[ | ||
Provide logic for [[Template:Lle]] (Language Links external, to be substituted, language names written exactly as #language would provide them) | Provide logic for [[Template:Lle]] (Language Links external, to be substituted, language names written exactly as #language would provide them) | ||
Warning: may expands too many costly #ifexist without limitation (if not substituted into a separate "/lang" template) | |||
]=] | ]=] | ||
function p.lle(frame) | function p.lle(frame) | ||
return frame:preprocess( | |||
p.forEachLanguage({ | |||
args = { | |||
pattern = '{{subst:#ifexist:{{{1}}}/$lc|[{{subst:fullurl:{{{1}}}/$lc}} <bdi class="language lang-$lc" lang="$lc">$lnP</bdi>] <b>∙</b> <!--\n-->}}' | |||
} | |||
}) | |||
) | |||
end | end | ||
--[=[ | --[=[ | ||
Provide logic for [[Template:Ll]] (Language Links, to be substituted) | Provide logic for [[Template:Ll]] (Language Links internal, to be substituted, language names written exactly as #language would provide them) | ||
Warning: may expands too many costly #ifexist without limitation (if not substituted into a separate "/lang" template) | |||
]=] | ]=] | ||
function p.ll(frame) | function p.ll(frame) | ||
return frame:preprocess( | |||
p.forEachLanguage({ | |||
args = { | |||
pattern = '{{subst:#ifexist:{{{1}}}/$lc|[[{{{1}}}/$lc|<bdi class="language lang-$lc" lang="$lc">$lnP</bdi>]] <b>∙</b> <!--\n-->}}' | |||
} | |||
}) | |||
) | |||
end | end | ||
വരി 274: | വരി 294: | ||
frame = mw.getCurrentFrame() | frame = mw.getCurrentFrame() | ||
end | end | ||
--[==[ | |||
local options = { abort= { time=3.5, on=function() | local options = { | ||
abort = { | |||
time = 3.5, | |||
local pages = language_subpages( frame, function( | on = function() | ||
pages2 = p.forEachLanguage({ | |||
args = { | |||
pattern = '{{#ifexist:' .. title .. '/$lc|[[' .. title .. '/$lc|<bdi lang="$lc">$lnP</bdi>]] <b>∙</b> }}' | |||
} | |||
}) | |||
end | |||
} | |||
} | |||
local pages = language_subpages( frame, | |||
function( title, page, code, langname ) | |||
return mw.ustring.format( | |||
'[[%s/%s|<bdi lang="%s">%s</bdi>]]</span> <b>∙</b> ', | |||
title, page, code, langname | |||
) | |||
end, options ); | |||
return pages2 and frame:preprocess(pages2) or table.concat(pages, ''); | return pages2 and frame:preprocess(pages2) or table.concat(pages, ''); | ||
--]==] | |||
return frame:preprocess( p.forEachLanguage({ args= { pattern = '{{#ifexist:' .. title .. '/$lc|[[' .. title .. '/$lc|$ | return frame:preprocess( | ||
p.forEachLanguage( { | |||
args = { | |||
pattern = '{{#ifexist:' .. title .. '/$lc|[[' .. title .. '/$lc|<bdi lang="$lc">$lnP</bdi>]] <b>∙</b> }}' | |||
} | |||
}) | |||
) | |||
end | end | ||
വരി 309: | വരി 347: | ||
end | end | ||
local base = args.base | local base = args.base | ||
local userlang = frame: | local userlang = frame:callParserFunction('int', 'lang') | ||
local tl, tlns = 'Template:', 10 | local tl, tlns = 'Template:', 10 | ||
local tlb, fallback1, currenttemplate | local tlb, fallback1, currenttemplate, currenttemplatepage | ||
local fallback, contentlang = mw.text.split( userlang, '-', true )[1], mw.language.getContentLanguage():getCode() | local fallback, contentlang = mw.text.split( userlang, '-', true )[1], mw.language.getContentLanguage():getCode() | ||
local createReturn | local function createReturn(title) | ||
local ret | local ret | ||
local tlargs = {} | local tlargs = {} | ||
വരി 328: | വരി 366: | ||
currenttemplate = tlb .. userlang | currenttemplate = tlb .. userlang | ||
currenttemplatepage = mw.title.new( currenttemplate, tlns ) | |||
if currenttemplatepage and currenttemplatepage.exists then | |||
if | |||
return createReturn(currenttemplate) | return createReturn(currenttemplate) | ||
end | end | ||
വരി 341: | വരി 377: | ||
currenttemplate = tlb .. fallback | currenttemplate = tlb .. fallback | ||
currenttemplatepage = mw.title.new( currenttemplate, tlns ) | |||
if currenttemplatepage and currenttemplatepage.exists then | |||
if | |||
return createReturn(currenttemplate) | return createReturn(currenttemplate) | ||
end | end | ||
currenttemplate = tlb .. contentlang | currenttemplate = tlb .. contentlang | ||
currenttemplatepage = mw.title.new( currenttemplate, tlns ) | |||
if currenttemplatepage and currenttemplatepage.exists then | |||
if | |||
return createReturn(currenttemplate) | return createReturn(currenttemplate) | ||
end | end | ||
വരി 374: | വരി 406: | ||
local ext_start, _ = string.find( original, '\.%w+$' ) | local ext_start, _ = string.find( original, '\.%w+$' ) | ||
local file_ext = string.sub( original, ext_start ) | local file_ext = string.sub( original, ext_start ) | ||
original = string.sub( original, 0, ext_start-1 ) | original = string.sub( original, 0, ext_start - 1 ) | ||
return frame:preprocess('<gallery>\n'..(table.concat(M_link.forEachLink( p.forEachLanguage( { args= { pattern = '[[$lc]]' } } ), | return frame:preprocess( | ||
'<gallery>\n' .. | |||
(table.concat( | |||
M_link.forEachLink( | |||
p.forEachLanguage({ | |||
args = { pattern = '[[$lc]]' } | |||
}), | |||
function( linkInfo ) | |||
local filename = mw.ustring.format( pattern, original, linkInfo.text ) .. file_ext | |||
local filepage = mw.title.new( filename, 6 ) | |||
if filepage and filepage.exists then | |||
return mw.ustring.format( '%s|%s', | |||
filename, | |||
mw.language.fetchLanguageName( linkInfo.text ) | |||
) | |||
else | |||
return nil | |||
end | |||
end | |||
), '\n' | |||
)) .. | |||
'\n</gallery>' | |||
) | |||
end | end | ||
function p.runTests() | function p.runTests() | ||
return p.langLinksNonExpensive({ args= { page='Module:Languages/testcases/test' }, getParent=function() end }) == | return p.langLinksNonExpensive({ | ||
args = { | |||
page = 'Module:Languages/testcases/test' | |||
}, | |||
getParent = function() end | |||
}) == | |||
'[[Module:Languages/testcases/test/de|<bdi lang="de">Deutsch</bdi>]] <b>∙</b> ' .. | |||
'[[Module:Languages/testcases/test/en|<bdi lang="en">English</bdi>]] <b>∙</b> ' | |||
end | end | ||
return p; | return p; |