Moduł:nagłówek języka
Wygląd
Moduł wykorzystywany przez szablon {{nagłówek języka}}. Zobacz też: /dane.
local p = {
main = function( frame )
local args = frame:getParent().args
local myTitle, myString, myLanguage, anchorEncode = mw.title, string, mw.language.new( 'pl' ), mw.uri.anchorEncode
local page = myTitle.getCurrentTitle() -- tworzy obiekt dla obecnej strony
local ns = page:inNamespace( 0 ) -- strona znajduje się w głównej przestrzeni?
local title = page.text
local kat = ''
local isDictPage = ((mw.ustring.find(title, 'Słownik ', 1, true)) == 1)
if ns and not isDictPage then
local pattern = "%({{" ..
myString.gsub( args[ 'długa' ], "[()-]", "%%%1" ) ..
".-}}%) ==.-{{znaczenia}}(.-)"
-- następne pole po "znaczeniach"
if args[ 'krótka' ] == "staroegipski" then
pattern = pattern .. "{{determinatywy}}"
elseif args[ 'krótka' ] == "znak chiński" then
pattern = pattern .. "{{etymologia}}"
else
pattern = pattern .. "{{odmiana}}"
end
-- pobiera zawartość pola "znaczenia"
local znaczenia = page.exists
and myString.match( page:getContent() or '', pattern )
or nil
local isFlex, notFlex = false, false
local kat_table = {}
if znaczenia then
local headers
-- wyłącznie nagłówki (wiersze nierozpoczynające się od znaku ":")
for w in myString.gfind( znaczenia, "\n'*([^:]+)\n: %(%d%.1%)" ) do
-- znaleziono szablon w postaci {{forma...}}
if myString.sub( w, 1, 7 ) == '{{forma' then
isFlex = true
else
notFlex = true
-- zob. [[Module:nagłówek języka/dane]]
headers = headers or require( 'Module:nagłówek języka/dane' )
for _, v in ipairs( headers ) do
-- nazwa kategorii dla danej części mowy
local kat_name = myLanguage:ucfirst( args[ 'długa' ] or '' ) .. ' - ' .. v[ 2 ]
if
myString.match( w, v[ 1 ] ) and
myTitle.new( kat_name, 'Kategoria' ).exists
then
kat_table[ #kat_table + 1 ] = '[[Kategoria:' .. kat_name .. ']]'
end
end
end
end
end
if isFlex and not notFlex then
local flex_kat = args[ 'krótka' ] .. ' (formy fleksyjne)'
kat = myTitle.new( flex_kat, 'Kategoria' ).exists
and '[[Kategoria:' .. flex_kat .. ']]'
or ''
else
local aTergo = require 'Moduł:a tergo'
kat = '[[Kategoria:' ..
( args.kat_indeks or args[ 'krótka' ] .. ' (indeks)' ) ..
']]' .. (
( args.a_tergo ~= 'nie' )
and aTergo.categorize( args[ 'krótka' ], title )
or ''
) .. (
( #kat_table ~= 0 )
and table.concat( kat_table )
or ''
)
end
end
local span_k1, span_k2, span_k3, span_k4
local span_a1, span_a2, span_a3
span_k1 = mw.html.create( 'span' )
:addClass(
'lang-code primary-lang-code lang-code-' ..
( args.kod or '' ) ..
( ( args.termin_obcy == 'tak' )
and ' no-headline-links'
or ''
)
)
:attr( 'id', anchorEncode( args.kod or '' ) )
if args.kod2 and args.kod2 ~= '' then
span_k2 = span_k1:tag( 'span' )
:addClass( 'lang-code' )
:attr( 'id', anchorEncode( args.kod2 ) )
if args.kod3 and args.kod3 ~= '' then
span_k3 = span_k2:tag( 'span' )
:addClass( 'lang-code' )
:attr( 'id', anchorEncode( args.kod3 ) )
if args.kod4 and args.kod4 ~= '' then
span_k4 = span_k3:tag( 'span' )
:addClass( 'lang-code' )
:attr( 'id', anchorEncode( args.kod4 ) )
end
end
end
if args.alias and args.alias ~= '' then
span_a1 = ( span_k4 or span_k3 or span_k2 or span_k1 )
:tag( 'span' )
:addClass( 'lang-alias' )
:attr( 'id', anchorEncode( title .. ' (' .. args.alias .. ')' ) )
if args.alias2 and args.alias2 ~= '' then
span_a2 = span_a1:tag( 'span' )
:addClass( 'lang-alias' )
:attr( 'id', anchorEncode( title .. ' (' .. args.alias2 .. ')' ) )
if args.alias3 and args.alias3 ~= '' then
span_a3 = span_a2:tag( 'span' )
:addClass( 'lang-alias' )
:attr( 'id', anchorEncode( title .. ' (' .. args.alias3 .. ')' ) )
end
end
end
( span_a3 or span_a2 or span_a1 or span_k4 or span_k3 or span_k2 or span_k1 )
:wikitext(
'[[' ..
( args.link or ':Kategoria:' .. myLanguage:ucfirst( args[ 'długa' ] or '' ) ) ..
'|' ..
( args[ 'tytuł' ] or args[ 'długa' ] or '' ) ..
']]'
)
return tostring( span_k1 ) .. kat
end }
return p