Jump to content

Module:Sandbox

From Meta, a Wikimedia project coordination wiki
Module documentation

Scribunto Testing Area

[edit]

This is not an actual Lua module. It exists to provide a convenient pseudo-namespace for code testing, hopefully preventing the main Module: namespace from becoming littered with experiments, as Lua modules cannot exist as subpages in the User: namespace.

Please name your experimental modules in the following format to help keep things tidy:

Module:Sandbox/Your User Name/Module name

You can use Special:PrefixIndex/Module:Sandbox to list modules in this area.

-- Placeholder-- THIS IS BETA SOFTWARE. USE CAREFULLY AND TEST EXTENSIVELY.localp={}functionp.assembleMessage(frame)--[[ This function takes existing translations for a given page translated using the translate extension and puts them together to generate the wikicode ready to be delivered by [Global message delivery] ]]-- Initialize the message's static contentlocalmessage='<pre>{{subst:#switch:{{subst:CONTENTLANG}}'--[[ Build the list of language codes for which there is a translation, and remove English if it was mistakenly added since we already include it as default. We can't automatically list all available translations of the issue, so we need to input them manually as part of the module's call. ]]translations={}forkey,valueinpairs(frame.args)doif(mw.language.isKnownLanguageTag(value)andvalue~='en')thentranslations[value]=valueendend-- Add English as defaulttranslations['#default']='en'-- Loop through the languages to assemble the available translationsforswitchKey,langCodeinpairs(translations)do--[[ TODO: add existence check of the translation in case of human error. Ignore the incorrect language code and give warning. ]]-- Add new switch key, and language and directionality metadatalocaldirection=mw.language.new(langCode):getDir()--[[ TODO: add switch keys for languages that have a fallback language for which we do have a translation, instead of English. ]]message=message..'|'..switchKey..'=<div class="plainlinks" lang="'..langCode..'" dir="'..direction..'">'-- Get the translation's contentlocalpage=frame.args['page']localcontent=mw.title.new(page..'/'..langCode):getContent()--[[ Clean up stuff we don't want to include (headers, footers, etc.) There's probably a cleaner way to do this but for now it'll work. TODO: add error checks. ]]returnstartIndexend-- Add footer static contentmessage=message..'}} ~~~~~</pre>'-- Hide nowiki tags from the preprocessormessage=mw.ustring.gsub(message,'<nowiki>(.-)</nowiki>','&lt;nowiki&gt;%1&lt;/nowiki&gt;')-- Preprocess to make <pre> workmessage=frame:preprocess(message)-- We're donereturnmessageendreturnp
close