Home
Random
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/Johnuniq/Wiktionary
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
-- Implement Template:Wiktionary. local function sideBox(args, items) -- Return simulated {{side box}} with parameters for {{wiktionary}}. local links = {} for i, item in ipairs(items) do local title = item.text if item.anchor then title = title .. '#' .. item.anchor end links[i] = -- "'''''[[wiktionary:" .. "'''[[wiktionary:" .. -- let {{lang}} control italics (item.isSearch and "Special:Search/" or "") .. title .. "|" .. item.langText .. -- "]]'''''" "]]'''" end local join1 = ', ' local join2 = #items > 2 and ', or ' or ' or ' local box = require('Module:Side box')._main return box({ metadata = 'no', position = args.position, image = (args.image or '') ~= 'none' and '[[File:Wiktionary-logo-en-v2.svg|40x40px|class=noviewer|alt=|link=]]' or nil, text = 'Look up ' .. mw.text.listToText(links, join1, join2) .. ' in Wiktionary, the free dictionary.', below = args.below, imageright = args.imageright, class = 'plainlinks sistersitebox', }) end local languageData local 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 end end 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, { lang = langCurrent, text = arg, anchor = nextAnchor }) lastWasSpecial = nil nextAnchor = nil end end end if items[1] then for _, item in ipairs(items) do -- local langText = frame:expandTemplate({title = 'lang', args = {item.lang, item.text, nocat = 'yes', italic = item.lang == 'en' and 'yes' or nil}}) langText = lang_mod._lang ({item.lang, item.text, cat = 'no', italic = item.lang == 'en' and 'yes' or nil }) -- let {{lang}} 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 ({langLocalWiki, title, cat = 'no'}) -- for consistency use {{lang}} for article title -- items[1] = { text = title, langText = title, isSearch = true } items[1] = { text = title, langText = langText, isSearch = true } -- don't break side box end return sideBox(args, items) end local function main(frame) -- Return wikitext to display {{wiktionary}} box. return _main(frame:getParent().args, frame) end return { main = main, _main = _main, }
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Sandbox/Johnuniq/Wiktionary/doc
(
edit
)