<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="pt-BR">
		<id>https://www.doctorview.com.br/wiki/index.php?action=history&amp;feed=atom&amp;title=M%C3%B3dulo%3ATemplate_translation</id>
		<title>Módulo:Template translation - Histórico de revisão</title>
		<link rel="self" type="application/atom+xml" href="https://www.doctorview.com.br/wiki/index.php?action=history&amp;feed=atom&amp;title=M%C3%B3dulo%3ATemplate_translation"/>
		<link rel="alternate" type="text/html" href="https://www.doctorview.com.br/wiki/index.php?title=M%C3%B3dulo:Template_translation&amp;action=history"/>
		<updated>2026-04-05T20:19:53Z</updated>
		<subtitle>Histórico de revisões para esta página neste wiki</subtitle>
		<generator>MediaWiki 1.29.0</generator>

	<entry>
		<id>https://www.doctorview.com.br/wiki/index.php?title=M%C3%B3dulo:Template_translation&amp;diff=60&amp;oldid=prev</id>
		<title>Danilo: uma edição</title>
		<link rel="alternate" type="text/html" href="https://www.doctorview.com.br/wiki/index.php?title=M%C3%B3dulo:Template_translation&amp;diff=60&amp;oldid=prev"/>
				<updated>2017-08-18T12:23:36Z</updated>
		
		<summary type="html">&lt;p&gt;uma edição&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style='vertical-align: top;' lang='pt-BR'&gt;
				&lt;td colspan='1' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Edição anterior&lt;/td&gt;
				&lt;td colspan='1' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Edição das 12h23min de 18 de agosto de 2017&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan='2' style='text-align: center;' lang='pt-BR'&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(Sem diferença)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Danilo</name></author>	</entry>

	<entry>
		<id>https://www.doctorview.com.br/wiki/index.php?title=M%C3%B3dulo:Template_translation&amp;diff=59&amp;oldid=prev</id>
		<title>Tgr (WMF) em 16h22min de 22 de abril de 2016</title>
		<link rel="alternate" type="text/html" href="https://www.doctorview.com.br/wiki/index.php?title=M%C3%B3dulo:Template_translation&amp;diff=59&amp;oldid=prev"/>
				<updated>2016-04-22T16:22:03Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Página nova&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local this = {}&lt;br /&gt;
&lt;br /&gt;
function this.checkLanguage(subpage, default)&lt;br /&gt;
    --[[Check first if there's an any invalid character that would cause the&lt;br /&gt;
        mw.language.isKnownLanguageTag function() to throw an exception:&lt;br /&gt;
        - all ASCII controls in [\000-\031\127],&lt;br /&gt;
        - double quote (&amp;quot;), sharp sign (#), ampersand (&amp;amp;), apostrophe ('),&lt;br /&gt;
        - slash (/), colon (:), semicolon (;), lower than (&amp;lt;), greater than (&amp;gt;),&lt;br /&gt;
        - brackets and braces ([, ], {, }), pipe (|), backslash (\\)&lt;br /&gt;
        All other characters are accepted, including space and all non-ASCII&lt;br /&gt;
        characters (including \192, which is invalid in UTF-8).&lt;br /&gt;
    --]]&lt;br /&gt;
    if mw.language.isValidCode(subpage) and mw.language.isKnownLanguageTag(subpage)&lt;br /&gt;
    --[[However &amp;quot;SupportedLanguages&amp;quot; are too restrictive, as they discard many&lt;br /&gt;
        valid BCP47 script variants (only because MediaWiki still does not&lt;br /&gt;
        define automatic transliterators for them, e.g. &amp;quot;en-dsrt&amp;quot; or&lt;br /&gt;
        &amp;quot;fr-brai&amp;quot; for French transliteration in Braille), and country variants,&lt;br /&gt;
        (useful in localized data, even if they are no longer used for&lt;br /&gt;
        translations, such as zh-cn, also useful for legacy codes).&lt;br /&gt;
        We want to avoid matching subpagenames containing any uppercase letter,&lt;br /&gt;
        (even if they are considered valid in BCP 47, in which they are&lt;br /&gt;
        case-insensitive; they are not &amp;quot;SupportedLanguages&amp;quot; for MediaWiki, so&lt;br /&gt;
        they are not &amp;quot;KnownLanguageTags&amp;quot; for MediaWiki).&lt;br /&gt;
        To be more restrictive, we exclude any character&lt;br /&gt;
        * that is not ASCII and not a lowercase letter, minus-hyphen, or digit,&lt;br /&gt;
          or does not start by a letter or does not finish by a letter or digit;&lt;br /&gt;
        * or that has more than 8 characters between hyphens;&lt;br /&gt;
        * or that has two hyphens;&lt;br /&gt;
        * or with specific uses in template subpages and unusable as languages.&lt;br /&gt;
    --]]&lt;br /&gt;
    or  string.find(subpage, &amp;quot;^[%l][%-%d%l]*[%d%l]$&amp;quot;) ~= nil&lt;br /&gt;
    and string.find(subpage, &amp;quot;[%d%l][%d%l][%d%l][%d%l][%d%l][%d%l][%d%l][%d%l][%d%l]&amp;quot;) == nil&lt;br /&gt;
    and string.find(subpage, &amp;quot;%-%-&amp;quot;) == nil&lt;br /&gt;
    and subpage ~= &amp;quot;doc&amp;quot;&lt;br /&gt;
    and subpage ~= &amp;quot;layout&amp;quot;&lt;br /&gt;
    and subpage ~= &amp;quot;sandbox&amp;quot;&lt;br /&gt;
    and subpage ~= &amp;quot;testcases&amp;quot;&lt;br /&gt;
    then&lt;br /&gt;
        return subpage&lt;br /&gt;
    end&lt;br /&gt;
    -- Otherwise there's currently no known language subpage&lt;br /&gt;
    return default&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[Get the last subpage of the current page if it is a translation.&lt;br /&gt;
    ]]&lt;br /&gt;
function this.getLanguageSubpage()&lt;br /&gt;
	--[[This code does not work in all namespaces where the Translate tool works.&lt;br /&gt;
	--  It works in the main namespace on Meta because it allows subpages there&lt;br /&gt;
	--  It would not work in the main namespace of English Wikipedia (but the&lt;br /&gt;
	--  articles are monolignual on that wiki).&lt;br /&gt;
	--  On Meta-Wiki the main space uses subpages and its pages are translated.&lt;br /&gt;
	--  The Translate tool allows translatng pages in all namespaces, even if&lt;br /&gt;
	--  the namespace officially does not have subpages.&lt;br /&gt;
	--  On Meta-Wiki the Category namespace still does not have subpages enabled,&lt;br /&gt;
	--  even if they would be very useful for categorizing templates, that DO have&lt;br /&gt;
	--  subpages (for documentatio and tstboxes pages). This is a misconfiguration&lt;br /&gt;
	--  bug of Meta-Wiki. The work-around is to split the full title and then&lt;br /&gt;
	--  get the last titlepart.&lt;br /&gt;
	local subpage = mw.title.getCurrentTitle().subpageText&lt;br /&gt;
	--]]&lt;br /&gt;
    local titleparts = mw.text.split(mw.title.getCurrentTitle().fullText, '/')&lt;br /&gt;
    local subpage = titleparts[#titleparts]&lt;br /&gt;
    return this.checkLanguage(subpage, '')&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[Get the first part of the language code of the subpage, before the '-'.&lt;br /&gt;
    ]]&lt;br /&gt;
function this.getMainLanguageSubpage()&lt;br /&gt;
	parts = mw.text.split( this.getLanguageSubpage(), '-' )&lt;br /&gt;
	return parts[1]&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[Get the last subpage of the current frame if it is a translation.&lt;br /&gt;
    Not used locally.&lt;br /&gt;
    ]]&lt;br /&gt;
function this.getFrameLanguageSubpage(frame)&lt;br /&gt;
    local titleparts = mw.text.split(frame:getParent():getTitle(), '/')&lt;br /&gt;
    local subpage = titleparts[#titleparts]&lt;br /&gt;
    return this.checkLanguage(subpage, '')&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[Get the language of the current page.&lt;br /&gt;
    Not used locally.&lt;br /&gt;
    ]]&lt;br /&gt;
function this.getLanguage()&lt;br /&gt;
    local subpage = mw.title.getCurrentTitle().subpageText&lt;br /&gt;
    return this.checkLanguage(subpage, mw.language.getContentLanguage():getCode())&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[Get the language of the current frame.&lt;br /&gt;
    Not used locally.&lt;br /&gt;
    ]]&lt;br /&gt;
function this.getFrameLanguage(frame)&lt;br /&gt;
    local titleparts = mw.text.split(frame:getParent():getTitle(), '/')&lt;br /&gt;
    local subpage = titleparts[#titleparts]&lt;br /&gt;
    return this.checkLanguage(subpage, mw.language.getContentLanguage():getCode())&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function this.title(namespace, basepagename, subpage)&lt;br /&gt;
    local message, title&lt;br /&gt;
    local pagename = basepagename&lt;br /&gt;
    if (subpage or '') ~= ''&lt;br /&gt;
    then&lt;br /&gt;
        pagename = pagename .. '/' .. subpage&lt;br /&gt;
    end&lt;br /&gt;
    local valid, title = xpcall(function()&lt;br /&gt;
            return mw.title.new(pagename, namespace) -- costly&lt;br /&gt;
        end, function(msg) -- catch undocumented exception (!?)&lt;br /&gt;
            -- thrown when namespace does not exist. The doc still&lt;br /&gt;
            -- says it should return a title, even in that case...&lt;br /&gt;
            message = msg&lt;br /&gt;
        end)&lt;br /&gt;
    if valid and title ~= nil and (title.id or 0) ~= 0&lt;br /&gt;
    then&lt;br /&gt;
        return title&lt;br /&gt;
    end&lt;br /&gt;
    return { -- &amp;quot;pseudo&amp;quot; mw.title object with id = nil in case of error&lt;br /&gt;
        prefixedText = pagename, -- the only property we need below&lt;br /&gt;
        message = message -- only for debugging&lt;br /&gt;
    }&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[If on a translation subpage (like Foobar/de), this function returns&lt;br /&gt;
    a given template in the same language, if the translation is available.&lt;br /&gt;
    Otherwise, the template is returned in its default language, without&lt;br /&gt;
    modification.&lt;br /&gt;
    This is aimed at replacing the current implementation of Template:TNTN.&lt;br /&gt;
&lt;br /&gt;
    This version does not expand the returned template name: this solves the&lt;br /&gt;
    problem of self-recursion in TNT when translatable templates need themselves&lt;br /&gt;
    to transclude other translable templates (such as Tnavbar).&lt;br /&gt;
    ]]&lt;br /&gt;
function this.getTranslatedTemplate(frame, withStatus)&lt;br /&gt;
    local args = frame.args&lt;br /&gt;
    local pagename = args['template']&lt;br /&gt;
    &lt;br /&gt;
    --[[Check whether the pagename is actually in the Template namespace, or&lt;br /&gt;
        if we're transcluding a main-namespace page.&lt;br /&gt;
        (added for backward compatibility of Template:TNT)&lt;br /&gt;
        ]]&lt;br /&gt;
    local title&lt;br /&gt;
    local namespace = args['tntns'] or ''&lt;br /&gt;
    if (namespace ~= '') -- Checks for tntns parameter for custom ns.&lt;br /&gt;
    then&lt;br /&gt;
        title = this.title(namespace, pagename) -- Costly&lt;br /&gt;
    else -- Supposes that set page is in ns10.&lt;br /&gt;
    	namespace = 'Template'&lt;br /&gt;
        title = this.title(namespace, pagename) -- Costly&lt;br /&gt;
        if title.id == nil&lt;br /&gt;
        then -- not found in the Template namespace, assume the main namespace (for backward compatibility)&lt;br /&gt;
    	    namespace = ''&lt;br /&gt;
            title = this.title(namespace, pagename) -- Costly&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    -- Get the last subpage and check if it matches a known language code.&lt;br /&gt;
    local subpage = args['uselang'] or ''&lt;br /&gt;
    if (subpage == '')&lt;br /&gt;
    then&lt;br /&gt;
        subpage = this.getLanguageSubpage()&lt;br /&gt;
    end&lt;br /&gt;
    if (subpage == '')&lt;br /&gt;
    then&lt;br /&gt;
        -- Check if a translation of the pagename exists in English&lt;br /&gt;
        local newtitle = this.title(namespace, pagename, 'en') -- Costly&lt;br /&gt;
        -- Use the translation when it exists&lt;br /&gt;
        if newtitle.id ~= nil&lt;br /&gt;
        then&lt;br /&gt;
            title = newtitle&lt;br /&gt;
        end&lt;br /&gt;
    else&lt;br /&gt;
        -- Check if a translation of the pagename exists in that language&lt;br /&gt;
        local newtitle = this.title(namespace, pagename, subpage) -- Costly&lt;br /&gt;
        if newtitle.id == nil&lt;br /&gt;
        then&lt;br /&gt;
            -- Check if a translation of the pagename exists in English&lt;br /&gt;
            newtitle = this.title(namespace, pagename, 'en') -- Costly&lt;br /&gt;
        end&lt;br /&gt;
        -- Use the translation when it exists&lt;br /&gt;
        if newtitle.id ~= nil&lt;br /&gt;
        then&lt;br /&gt;
            title = newtitle&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    -- At this point the title should exist&lt;br /&gt;
    if withStatus then&lt;br /&gt;
    	-- status returned to Lua function below&lt;br /&gt;
        return title.prefixedText, title.id ~= nil&lt;br /&gt;
    else&lt;br /&gt;
    	-- returned directly to MediaWiki&lt;br /&gt;
        return title.prefixedText&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[If on a translation subpage (like Foobar/de), this function renders&lt;br /&gt;
    a given template in the same language, if the translation is available.&lt;br /&gt;
    Otherwise, the template is rendered in its default language, without&lt;br /&gt;
    modification.&lt;br /&gt;
    This is aimed at replacing the current implementation of Template:TNT.&lt;br /&gt;
    &lt;br /&gt;
    Note that translatable templates cannot transclude themselves other&lt;br /&gt;
    translatable templates, as it will recurse on TNT. Use TNTN instead&lt;br /&gt;
    to return only the effective template name to expand externally, with&lt;br /&gt;
    template parameters also provided externally.&lt;br /&gt;
    ]]&lt;br /&gt;
function this.renderTranslatedTemplate(frame)&lt;br /&gt;
	local title, found = this.getTranslatedTemplate(frame, true)&lt;br /&gt;
    -- At this point the title should exist prior to performing the expansion&lt;br /&gt;
    -- of the template, otherwise render a red link to the missing page&lt;br /&gt;
    -- (resolved in its assumed namespace). If we don't tet this here, a&lt;br /&gt;
    -- script error would be thrown. Returning a red link is consistant with&lt;br /&gt;
    -- MediaWiki behavior when attempting to transclude inexistant templates.&lt;br /&gt;
	if not found then&lt;br /&gt;
		return '[[' .. title .. ']]'&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
    -- Copy args pseudo-table to a proper table so we can feed it to expandTemplate.&lt;br /&gt;
    -- Then render the pagename.&lt;br /&gt;
    local args = frame.args&lt;br /&gt;
    local pargs = (frame:getParent() or {}).args&lt;br /&gt;
    local arguments = {}&lt;br /&gt;
    if (args['noshift'] or '') == ''&lt;br /&gt;
    then&lt;br /&gt;
        for k, v in pairs(pargs) do&lt;br /&gt;
            -- numbered args &amp;gt;= 1 need to be shifted&lt;br /&gt;
            local n = tonumber(k) or 0&lt;br /&gt;
            if (n &amp;gt; 0)&lt;br /&gt;
            then&lt;br /&gt;
                if (n &amp;gt;= 2)&lt;br /&gt;
                then&lt;br /&gt;
                    arguments[n - 1] = v&lt;br /&gt;
                end&lt;br /&gt;
            else&lt;br /&gt;
                arguments[k] = v&lt;br /&gt;
            end&lt;br /&gt;
        end&lt;br /&gt;
    else -- special case where TNT is used as autotranslate&lt;br /&gt;
    	-- (don't shift again what is shifted in the invokation)&lt;br /&gt;
        for k, v in pairs(pargs) do&lt;br /&gt;
            arguments[k] = v&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    arguments['template'] = title -- override the existing parameter of the base template name supplied with the full name of the actual template expanded&lt;br /&gt;
    arguments['tntns'] = nil -- discard the specified namespace override&lt;br /&gt;
    arguments['uselang'] = args['uselang'] -- argument forwarded into parent frame&lt;br /&gt;
    arguments['noshift'] = args['noshift'] -- argument forwarded into parent frame&lt;br /&gt;
    &lt;br /&gt;
    return frame:expandTemplate{title = ':' .. title, args = arguments}&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[A helper for mocking TNT in Special:TemplateSandbox. TNT breaks&lt;br /&gt;
    TemplateSandbox; mocking it with this method means templates won't be&lt;br /&gt;
    localized but at least TemplateSandbox substitutions will work properly.&lt;br /&gt;
    Won't work with complex uses.&lt;br /&gt;
    ]]&lt;br /&gt;
function this.mockTNT(frame)&lt;br /&gt;
    local pargs = (frame:getParent() or {}).args&lt;br /&gt;
    local arguments = {}&lt;br /&gt;
    for k, v in pairs(pargs) do&lt;br /&gt;
        -- numbered args &amp;gt;= 1 need to be shifted&lt;br /&gt;
        local n = tonumber(k) or 0&lt;br /&gt;
        if (n &amp;gt; 0)&lt;br /&gt;
        then&lt;br /&gt;
            if (n &amp;gt;= 2)&lt;br /&gt;
            then&lt;br /&gt;
                arguments[n - 1] = v&lt;br /&gt;
            end&lt;br /&gt;
        else&lt;br /&gt;
            arguments[k] = v&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    if not pargs[1]&lt;br /&gt;
    then&lt;br /&gt;
    	return ''&lt;br /&gt;
	end&lt;br /&gt;
    return frame:expandTemplate{title = 'Template:' .. pargs[1], args = arguments}&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return this&lt;/div&gt;</summary>
		<author><name>Tgr (WMF)</name></author>	</entry>

	</feed>