This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing.
This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing.
--[[ __ __ _ _ _ _ _ _ _ | \/ | ___ __| |_ _| | ___ _ / \ _ _| |_ ___ | |_ _ __ __ _ _ __ ___| | __ _| |_ ___ | |\/| |/ _ \ / _` | | | | |/ _ (_) / _ \| | | | __/ _ \| __| '__/ _` | '_ \/ __| |/ _` | __/ _ \ | | | | (_) | (_| | |_| | | __/_ / ___ \ |_| | || (_) | |_| | | (_| | | | \__ \ | (_| | || __/ |_| |_|\___/ \__,_|\__,_|_|\___(_)_/ \_\__,_|\__\___/ \__|_| \__,_|_| |_|___/_|\__,_|\__\___| Authors and maintainers:* User:Zolo - original version* User:Jarekt ]]-- local function to help normalize input argumentslocalfunctionnormalize_input_args(input_args,output_args)forname,valueinpairs(input_args)doifvalue~=''then-- nuke empty stringsiftype(name)=='string'thenname=string.lower(name)end-- convert to lower caseoutput_args[name]=valueendendreturnoutput_argsend-- initialize object to be returnedlocalp={}--[[autotranslateThis function is the core part of the Autotranslate template. Usage from a template:{{#invoke:autotranslate|autotranslate|base=|lang= }}Parameters: frame.args.base - base page name frame.args.lang - desired language (often user's native language) Error Handling:]]functionp.autotranslate(frame)-- switch to lowercase parameters to make them case independentlocalargs={}args=normalize_input_args(frame:getParent().args,args)args=normalize_input_args(frame.args,args)-- get language fallback listifnotargs.langornotmw.language.isSupportedLanguage(args.lang)thenargs.lang=frame:callParserFunction("int","lang")-- get user's chosen language endlocallangList=mw.language.getFallbacksFor(args.lang)table.insert(langList,1,args.lang)-- find base pagelocalbase=args.baseargs.base=nilassert(baseand#base>0,'Base page not provided for autotranslate')ifnotmw.ustring.find(base,':')then-- if base page does not indicate namespacebase='Template:'..base-- than assume it is a template end-- find base template language subpagelocalpage=args.default-- default page if provided or nil otherwisefor_,languageinipairs(langList)doifmw.title.new(base..'/'..language).existsthenpage=base..'/'..language-- returns only the pagebreakendendassert(page,string.format('No fallback page found for autotranslate (base=[[%s]], lang=%s)',base,args.lang))-- Transclude {{page |....}} with template arguments the same as the ones passed to {{autotranslate}} template.returnframe:expandTemplate{title=page,args=args}endreturnp