Module:Sandbox/Johnuniq/Wiktionary Explained

-- Implement Template:Wiktionary.

local function sideBox(args, items) -- Return simulated with parameters for . local links = for i, item in ipairs(items) do local title = item.text if item.anchor then title = title .. '#' .. item.anchor end links[i] =-- "" .. item.langText ..-- "]]" "" end local join1 = ', ' local join2 = #items > 2 and ', or ' or ' or ' local box = require('Module:Side box')._main return boxend

local languageDatalocal function setAnchor(item) if not item.anchor then languageData = languageData or require('Module:Language/data').languages local data = languageData[item.lang] if data then if data.name then item.anchor = data.name end end end if item.anchor then if item.anchor

then item.anchor = nil else item.anchor = item.anchor:gsub(' ', '_') end endend

local function _main(args, frame) -- Process given args; can be called from another module. frame = frame or mw.getCurrentFrame-- local langDefault = mw.language.getContentLanguage.code -- "en" at enwiki local langLocalWiki = mw.language.getContentLanguage.code -- "en" at enwiki-- local langCurrent = langDefault local langCurrent = 'und' -- until specified, we don't know the language local lastWasSpecial, nextAnchor local items = local lang_mod = require ('Module:lang') -- for direct access to the functions in Module:Lang local langText -- text and markup returned from Module:Lang.lang for _, arg in ipairs(args) do arg = mw.text.trim(arg) if arg ~= then if arg:sub(1, 1)

'_' then local special = mw.text.trim(arg:sub(2)) if lastWasSpecial then nextAnchor = special else if special

then-- langCurrent = langDefault langCurrent = langLocalWiki -- local wiki language only when specified; in effect until changed to another language or reset (how to reset?) else langCurrent = special end lastWasSpecial = true end else table.insert(items, ) lastWasSpecial = nil nextAnchor = nil end end end if items[1] then for _, item in ipairs(items) do-- local langText = frame:expandTemplate langText = lang_mod._lang -- let control italics if langText:match('class="error"') then error('Wiktionary error: language code "' .. item.lang .. '" is unknown', 0) end item.langText = langText setAnchor(item) end else local title = mw.ustring.lower(mw.title.getCurrentTitle.subpageText) langText = lang_mod._lang () -- for consistency use for article title-- items[1] = items[1] = -- don't break side box end return sideBox(args, items)end

local function main(frame) -- Return wikitext to display box. return _main(frame:getParent.args, frame)end

return