Jump to content
Toggle menu
  • 3 articles
  • 75 files
  • 7 users
  • 37.9K edits
Neodyland Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Languages: Difference between revisions

From Neodyland Wiki
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|[[{{{1}}}/$lc|<bdi class="language lang-$lc" lang="$lc">$lnP</bdi>]]&nbsp;<b>∙</b>&#32;<!--\n-->}}'
                 pattern = '{{subst:#ifexist:{{{1}}}/$lc|[{{subst:fullurl:{{{1}}}/$lc}} <bdi class="language lang-$lc" lang="$lc">$lnP</bdi>]&nbsp;<b>∙</b>&#32;<!--\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">$lnUC1</bdi>]]&nbsp;<b>∙</b>&#32;<!--\n-->}}'
                 pattern = '{{subst:#ifexist:{{{1}}}/$lc|[[{{{1}}}/$lc|<bdi class="language lang-$lc" lang="$lc">$lnP</bdi>]]&nbsp;<b>∙</b>&#32;<!--\n-->}}'
             }
             }
         })
         })
Line 347: Line 347:
     end
     end
     local base = args.base
     local base = args.base
     local userlang = frame:preprocess( '{{Int:Lang}}' )
     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 = function(title)
     local function createReturn(title)
         local ret
         local ret
         local tlargs = {}
         local tlargs = {}
Line 366: Line 366:


     currenttemplate = tlb .. userlang
     currenttemplate = tlb .. userlang
     local ok, exists = pcall( function()
     currenttemplatepage = mw.title.new( currenttemplate, tlns )
        return mw.title.new( currenttemplate, tlns ).exists
     if currenttemplatepage and currenttemplatepage.exists then
    end )
     if ok and exists then
         return createReturn(currenttemplate)
         return createReturn(currenttemplate)
     end
     end
Line 379: Line 377:


     currenttemplate = tlb .. fallback
     currenttemplate = tlb .. fallback
     local ok, exists = pcall( function()
     currenttemplatepage = mw.title.new( currenttemplate, tlns )
        return mw.title.new( currenttemplate, tlns ).exists
     if currenttemplatepage and currenttemplatepage.exists then
    end )
     if ok and exists then
         return createReturn(currenttemplate)
         return createReturn(currenttemplate)
     end
     end


     currenttemplate = tlb .. contentlang
     currenttemplate = tlb .. contentlang
     local ok, exists = pcall( function()
     currenttemplatepage = mw.title.new( currenttemplate, tlns )
        return mw.title.new( currenttemplate, tlns ).exists
     if currenttemplatepage and currenttemplatepage.exists then
    end )
     if ok and exists then
         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 ok, exists = pcall( function()
                     local filepage = mw.title.new( filename, 6 )
                            return mw.title.new( filename, 6 ).exists
                     if filepage and filepage.exists then
                        end )
                     if ok and exists then
                         return mw.ustring.format( '%s|%s',
                         return mw.ustring.format( '%s|%s',
                             filename,
                             filename,
Cookies help us deliver our services. By using our services, you agree to our use of cookies.