--Implements .
require ('strict');local local_wiki_tag = mw.language.getContentLanguage.code; -- 'en' at enwiki
--position=|project=wiktionary|text= }}
local function error_side_box (args_t, message, categories_t, frame) return string.format ('
%s: %s%s', -- render the error message with categories ' error: ', message, table.concat (categories_t) ); end--position=|project=wiktionary|text= }}
local function side_box (args_t, items_t, categories_t, frame) local links_t = ; -- holds a list of interwiki-linked terms for i, item_t in ipairs (items_t) do -- build an interwiki link to wiktionary local title = item_t.term; -- wiktionary article title if item_t.anchor then title = title .. item_t.anchor; -- add a language-specific anchor if language tag or #anchor supplied in template call end links_t[i] = string.format ('%s', -- create interwiki link for each individual term (item_t.isSearch and "Special:Search/" or ""), title, -- wiktionary article title + anchor item_t.lang_text -- term wrapped in -provided markup for display ); end local join1 = ', '; -- create appropriate separators for the list of terms local join2 = #items_t > 2 and ', or ' or ' or ';
return string.format ('Look up %s in Wiktionary, the free dictionary.%s', -- construct the text the goes inside the box mw.text.listToText (links_t, join1, join2), -- concatenate the list of terms table.concat (categories_t) -- add categories );end
--
local added_cats_t = ;
local function category_add (category, categories_t) if not mw.title.getCurrentTitle:inNamespace (0) then -- when not in mainspace return; -- abandon end if added_cats_t[category] then -- when we've already added this category return; -- abandon end local category_names_t =
table.insert (categories_t, table.concat);
added_cats_t[category] = true; -- remember that we've added this category to
----------------------------< S E T _ A N C H O R >----------------------------------------------------------
create a language-specific anchor (URI fragment) where the fragment is the wiktionary language name associatedwith the language tag prefixed to the 'term'.
local function set_anchor (item_t) local wikt_lang_data = mw.loadData ('Module:Wikt-lang/data'); -- load wiktionary supported languages list
if not item_t.anchor then if wikt_lang_data.redirects[item_t.tag] then item_t.tag = wikt_lang_data.redirects[item_t.tag]; end local data_t = wikt_lang_data.languages[item_t.tag]; -- primary wiktionary data source
local mw_lang_name; -- holds MediaWiki name for language tag if not [item_t.tag] then -- these are supported by MediaWiki but have no value here mw_lang_name = mw.language.fetchLanguageName (item_t.tag, local_wiki_tag); -- get MediaWiki's language name as fallback end if data_t and data_t.name then -- if wiktionary has name for language tag
if
----------------------------< M A I N >----------------------------------------------------------------------
Return wikitext to display box.
local function main (frame) local args_t = require ('Module:Arguments').getArgs (frame);
local items_t = ; local categories_t = ; local lang_mod = require ('Module:lang'); -- for direct access to the functions in Module:Lang local lang_text; -- term and markup returned from Module:Lang.lang for _, arg in ipairs (args_t) do arg = mw.text.trim (arg); if arg ~= then local tag, term, anchor; if arg:match ('^%a%a%a?:.+') then -- does this arg have language tag prefix and a term? tag, term = arg:match ('^(%a%a%a?):(.*)'); -- yep, then extract them else term = arg; -- nope, just a term end
if term:match ('.+#.+') then -- does
if items_t[1] then for _, item_t in ipairs (items_t) do local italic = (item_t.tag
----------------------------< E X P O R T E D F U N C T I O N S >------------------------------------------
return