<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="hu">
	<id>https://wikisfiam.kristofgonczo.dev/index.php?action=history&amp;feed=atom&amp;title=Modul%3ATemplate_translation</id>
	<title>Modul:Template translation - Laptörténet</title>
	<link rel="self" type="application/atom+xml" href="https://wikisfiam.kristofgonczo.dev/index.php?action=history&amp;feed=atom&amp;title=Modul%3ATemplate_translation"/>
	<link rel="alternate" type="text/html" href="https://wikisfiam.kristofgonczo.dev/index.php?title=Modul:Template_translation&amp;action=history"/>
	<updated>2026-04-04T16:01:42Z</updated>
	<subtitle>Az oldal laptörténete a wikiben</subtitle>
	<generator>MediaWiki 1.44.2</generator>
	<entry>
		<id>https://wikisfiam.kristofgonczo.dev/index.php?title=Modul:Template_translation&amp;diff=483&amp;oldid=prev</id>
		<title>KristofAdmin: 1 változat importálva</title>
		<link rel="alternate" type="text/html" href="https://wikisfiam.kristofgonczo.dev/index.php?title=Modul:Template_translation&amp;diff=483&amp;oldid=prev"/>
		<updated>2024-01-24T07:53:09Z</updated>

		<summary type="html">&lt;p&gt;1 változat importálva&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;hu&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Régebbi változat&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;A lap 2024. január 24., 07:53-kori változata&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;4&quot; class=&quot;diff-notice&quot; lang=&quot;hu&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(Nincs különbség)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;!-- diff cache key mediawiki:diff:1.41:old-482:rev-483 --&gt;
&lt;/table&gt;</summary>
		<author><name>KristofAdmin</name></author>
	</entry>
	<entry>
		<id>https://wikisfiam.kristofgonczo.dev/index.php?title=Modul:Template_translation&amp;diff=482&amp;oldid=prev</id>
		<title>mediawiki&gt;Billinghurst: 1 revision imported from :meta:Module:Template_translation</title>
		<link rel="alternate" type="text/html" href="https://wikisfiam.kristofgonczo.dev/index.php?title=Modul:Template_translation&amp;diff=482&amp;oldid=prev"/>
		<updated>2023-07-07T03:55:34Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported from &lt;a href=&quot;/index.php?title=Meta:Module:Template_translation&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Meta:Module:Template translation (a lap nem létezik)&quot;&gt;meta:Module:Template_translation&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Új lap&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&amp;#039;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 (&amp;#039;),&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 tags&lt;br /&gt;
        * for specific uses in template subpages and unusable as language tags;&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 subtags with more than 8 characters between hyphens;&lt;br /&gt;
        * or that has two hyphens.&lt;br /&gt;
    --]]&lt;br /&gt;
    or  subpage ~= &amp;quot;doc&amp;quot;&lt;br /&gt;
    and subpage ~= &amp;quot;layout&amp;quot;&lt;br /&gt;
    and subpage ~= &amp;quot;button&amp;quot;&lt;br /&gt;
    and subpage ~= &amp;quot;buttons&amp;quot;&lt;br /&gt;
    and subpage ~= &amp;quot;sandbox&amp;quot;&lt;br /&gt;
    and subpage ~= &amp;quot;testcase&amp;quot;&lt;br /&gt;
    and subpage ~= &amp;quot;testcases&amp;quot;&lt;br /&gt;
    and 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 then&lt;br /&gt;
        return subpage&lt;br /&gt;
    end&lt;br /&gt;
    -- Otherwise there&amp;#039;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 an arbitrary page if it is a translation.&lt;br /&gt;
    To be used from templates.&lt;br /&gt;
    ]]&lt;br /&gt;
function this.getLanguageSubpage(frame)&lt;br /&gt;
	local title = frame and frame.args[1]&lt;br /&gt;
	if not title or title == &amp;#039;&amp;#039; then&lt;br /&gt;
		title = mw.title.getCurrentTitle()&lt;br /&gt;
	end&lt;br /&gt;
	return this._getLanguageSubpage(title)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[Get the last subpage of an arbitrary page if it is a translation.&lt;br /&gt;
    To be used from Lua.&lt;br /&gt;
    ]]&lt;br /&gt;
function this._getLanguageSubpage(title)&lt;br /&gt;
	if type(title) == &amp;#039;string&amp;#039; then&lt;br /&gt;
		title = mw.title.new(title)&lt;br /&gt;
	end&lt;br /&gt;
	if not title then&lt;br /&gt;
		-- invalid title&lt;br /&gt;
		return nil&lt;br /&gt;
	end&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 = title.subpageText&lt;br /&gt;
	--]]&lt;br /&gt;
	local titleparts = mw.text.split(title.fullText, &amp;#039;/&amp;#039;)&lt;br /&gt;
	local subpage = titleparts[#titleparts]&lt;br /&gt;
	return this.checkLanguage(subpage, &amp;#039;&amp;#039;)&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.getCurrentLanguageSubpage()&lt;br /&gt;
	return this._getLanguageSubpage(mw.title.getCurrentTitle())&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[Get the first part of the language code of the subpage, before the &amp;#039;-&amp;#039;.&lt;br /&gt;
--]]&lt;br /&gt;
function this.getMainLanguageSubpage()&lt;br /&gt;
	parts = mw.text.split(this.getCurrentLanguageSubpage(), &amp;#039;-&amp;#039;)&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;
	return this._getLanguageSubpage(frame:getParent():getTitle())&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[Get the language of the current page. 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. Not used locally.&lt;br /&gt;
--]]&lt;br /&gt;
function this.getFrameLanguage(frame)&lt;br /&gt;
    local titleparts = mw.text.split(frame:getParent():getTitle(), &amp;#039;/&amp;#039;)&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 &amp;#039;&amp;#039;) ~= &amp;#039;&amp;#039; then&lt;br /&gt;
        pagename = pagename .. &amp;#039;/&amp;#039; .. 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 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[&amp;#039;template&amp;#039;]&lt;br /&gt;
    --[[Check whether the pagename is actually in the Template namespace, or&lt;br /&gt;
        if we&amp;#039;re transcluding a main-namespace page.&lt;br /&gt;
        (added for backward compatibility of Template:TNT)&lt;br /&gt;
        ]]&lt;br /&gt;
    local namespace, title = args[&amp;#039;tntns&amp;#039;] or &amp;#039;&amp;#039;&lt;br /&gt;
    if namespace ~= &amp;#039;&amp;#039; then -- Checks for tntns parameter for custom ns.&lt;br /&gt;
        title = this.title(namespace, pagename) -- Costly&lt;br /&gt;
    else -- Supposes that set page is in ns10.&lt;br /&gt;
    	namespace = &amp;#039;Template&amp;#039;&lt;br /&gt;
        title = this.title(namespace, pagename) -- Costly&lt;br /&gt;
        if title.id == nil then -- not found in the Template namespace, assume the main namespace (for backward compatibility)&lt;br /&gt;
    	    namespace = &amp;#039;&amp;#039;&lt;br /&gt;
            title = this.title(namespace, pagename) -- Costly&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    -- Get the last subpage and check if it matches a known language code.&lt;br /&gt;
    local subpage = args[&amp;#039;uselang&amp;#039;] or &amp;#039;&amp;#039;&lt;br /&gt;
    if subpage == &amp;#039;&amp;#039; then&lt;br /&gt;
        subpage = this.getCurrentLanguageSubpage()&lt;br /&gt;
    end&lt;br /&gt;
    if subpage == &amp;#039;&amp;#039; then&lt;br /&gt;
        -- Check if a translation of the pagename exists in English&lt;br /&gt;
        local newtitle = this.title(namespace, pagename, &amp;#039;en&amp;#039;) -- Costly&lt;br /&gt;
        -- Use the translation when it exists&lt;br /&gt;
        if newtitle.id ~= nil 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 then&lt;br /&gt;
            -- Check if a translation of the pagename exists in English&lt;br /&gt;
            newtitle = this.title(namespace, pagename, &amp;#039;en&amp;#039;) -- Costly&lt;br /&gt;
        end&lt;br /&gt;
        -- Use the translation when it exists&lt;br /&gt;
        if newtitle.id ~= nil 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&amp;#039;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 &amp;#039;[[&amp;#039; .. title .. &amp;#039;]]&amp;#039;&lt;br /&gt;
	end&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[&amp;#039;noshift&amp;#039;] or &amp;#039;&amp;#039;) == &amp;#039;&amp;#039; then&lt;br /&gt;
        for k, v in pairs(pargs) do&lt;br /&gt;
            local n = tonumber(k) or 0&lt;br /&gt;
            if n &amp;lt;= 0 then -- unnumbered args&lt;br /&gt;
                arguments[k] = v&lt;br /&gt;
            elseif n &amp;gt;= 2 then -- numbered args &amp;gt;= 2 need to be shifted&lt;br /&gt;
                arguments[n - 1] = 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&amp;#039;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[&amp;#039;template&amp;#039;] = title -- override the existing parameter of the base template name supplied with the full name of the actual template expanded&lt;br /&gt;
    arguments[&amp;#039;tntns&amp;#039;] = nil -- discard the specified namespace override&lt;br /&gt;
    arguments[&amp;#039;uselang&amp;#039;] = args[&amp;#039;uselang&amp;#039;] -- argument forwarded into parent frame&lt;br /&gt;
    arguments[&amp;#039;noshift&amp;#039;] = args[&amp;#039;noshift&amp;#039;] -- argument forwarded into parent frame&lt;br /&gt;
    return frame:expandTemplate{title = &amp;#039;:&amp;#039; .. 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&amp;#039;t be&lt;br /&gt;
    localized but at least TemplateSandbox substitutions will work properly.&lt;br /&gt;
    Won&amp;#039;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;
        local n = tonumber(k) or 0&lt;br /&gt;
        if n &amp;lt;= 0 then -- unnumbered args&lt;br /&gt;
            arguments[k] = v&lt;br /&gt;
        elseif n &amp;gt;= 2 then -- numbered args &amp;gt;= 2 need to be shifted&lt;br /&gt;
            arguments[n - 1] = v&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    if not pargs[1] then&lt;br /&gt;
    	return &amp;#039;&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
    return frame:expandTemplate{title = &amp;#039;Template:&amp;#039; .. pargs[1], args = arguments}&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return this&lt;/div&gt;</summary>
		<author><name>mediawiki&gt;Billinghurst</name></author>
	</entry>
</feed>