Module:Languages: Difference between revisions
From Neodyland Wiki
More actions
No edit summary |
m 80 revisions imported |
||
| (3 intermediate revisions by 2 users not shown) | |||
| Line 14: | Line 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 ""; | ||
| Line 79: | Line 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 | ||
| Line 245: | Line 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 | 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) | ||
| Line 251: | Line 251: | ||
p.forEachLanguage({ | p.forEachLanguage({ | ||
args = { | args = { | ||
pattern = '{{subst:#ifexist:{{{1}}}/$lc| | pattern = '{{subst:#ifexist:{{{1}}}/$lc|[{{subst:fullurl:{{{1}}}/$lc}} <bdi class="language lang-$lc" lang="$lc">$lnP</bdi>] <b>∙</b> <!--\n-->}}' | ||
} | } | ||
}) | }) | ||
| Line 258: | Line 258: | ||
--[=[ | --[=[ | ||
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 | 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) | ||
| Line 265: | Line 265: | ||
p.forEachLanguage({ | p.forEachLanguage({ | ||
args = { | args = { | ||
pattern = '{{subst:#ifexist:{{{1}}}/$lc|[[{{{1}}}/$lc|<bdi class="language lang-$lc" lang="$lc">$ | pattern = '{{subst:#ifexist:{{{1}}}/$lc|[[{{{1}}}/$lc|<bdi class="language lang-$lc" lang="$lc">$lnP</bdi>]] <b>∙</b> <!--\n-->}}' | ||
} | } | ||
}) | }) | ||
| Line 347: | Line 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 = {} | ||
| Line 366: | Line 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 | ||
| Line 379: | Line 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 | ||
| Line 422: | Line 416: | ||
function( linkInfo ) | function( linkInfo ) | ||
local filename = mw.ustring.format( pattern, original, linkInfo.text ) .. file_ext | local filename = mw.ustring.format( pattern, original, linkInfo.text ) .. file_ext | ||
local | local filepage = mw.title.new( filename, 6 ) | ||
if filepage and filepage.exists then | |||
if | |||
return mw.ustring.format( '%s|%s', | return mw.ustring.format( '%s|%s', | ||
filename, | filename, | ||