Модул:Language section
Документация за този модул може да бъде създадена на Модул:Language section/doc
local p = {}
require('Module:No globals')
local Langs = require('Module:Langs')
local internationalNotationsPortal = 'Международна нотация'
local msgs
local allMsgs = {
bg = {
noLangCode = 'Не е зададен езиков код',
wrongLangCode = 'Грешен/неразпознат езиков код',
inter = 'Международна нотация'
},
en = {
noLangCode = 'No language code',
wrongLangCode = 'Wrong/unknown language code',
inter = 'International notation'
}
}
local function trimObjVals(args, list)
local r = {}
for i, v in ipairs(list) do
r[v] = mw.text.trim( args[v] or '' )
end
return r
end
local function capitalizeFirst(str)
if str == nil then return null end
return mw.ustring.upper( mw.ustring.sub(str, 1, 1) )
.. mw.ustring.sub(str, 2, #str)
end
function p.main(frame)
local a = trimObjVals( frame.args, { 'lang', 'userLang' } )
local langCode = a.lang
local userLang = a.userLang or 'bg'
msgs = allMsgs[userLang]
local currentTitle = mw.title.getCurrentTitle()
local inMainNS = ( currentTitle.namespace == 0 )
local langLabel, langPortalAddr, spanId
local langNameBg
-- spanId is the name of the lang in the other lang, that is not the userLang
-- That way, there will be a link anchor at that section for both the En and Bg name
assert( langCode ~= '', msgs.wrongLangCode )
if langCode == '0' then
langLabel = msgs.inter
langPortalAddr = internationalNotationsPortal
spanId = userLang == 'en' and allMsgs.bg.inter or allMsgs.en.inter
else
local langNameEn = capitalizeFirst( Langs.codeToName_({code = langCode, toLang = 'en'}) ) -- TODO: modif Module:Langs to return english names capitalized
assert(langNameEn ~= nil, msgs.wrongLangCode)
langNameBg = capitalizeFirst( Langs.codeToName_({code = langCode, toLang = 'bg'}) )
langLabel = userLang == 'en' and langNameEn or langNameBg
langPortalAddr = langNameBg
-- So that there is a link to the section in both En and Bg :
spanId = userLang == 'en' and langNameBg or langNameEn
end
return '<span id="' .. spanId .. '" class="langSectionHeadingSpan">' .. langLabel .. '</span>' .. (inMainNS and langNameBg and '[[Категория:' .. langNameBg .. ']]' or '')
end
return p