<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://pdkb.chivanet.org/wiki/index.php?action=history&amp;feed=atom&amp;title=Module%3ATemplate_translation%2Fsandbox</id>
		<title>Module:Template translation/sandbox - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://pdkb.chivanet.org/wiki/index.php?action=history&amp;feed=atom&amp;title=Module%3ATemplate_translation%2Fsandbox"/>
		<link rel="alternate" type="text/html" href="https://pdkb.chivanet.org/wiki/index.php?title=Module:Template_translation/sandbox&amp;action=history"/>
		<updated>2026-05-15T10:31:48Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.29.1</generator>

	<entry>
		<id>https://pdkb.chivanet.org/wiki/index.php?title=Module:Template_translation/sandbox&amp;diff=1959&amp;oldid=prev</id>
		<title>DavidWhitten: from: https://meta.wikimedia.org/w/index.php?title=Module:Template_translation/sandbox&amp;action=edit</title>
		<link rel="alternate" type="text/html" href="https://pdkb.chivanet.org/wiki/index.php?title=Module:Template_translation/sandbox&amp;diff=1959&amp;oldid=prev"/>
				<updated>2021-06-23T16:49:45Z</updated>
		
		<summary type="html">&lt;p&gt;from: https://meta.wikimedia.org/w/index.php?title=Module:Template_translation/sandbox&amp;amp;action=edit&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local this = {}&lt;br /&gt;
&lt;br /&gt;
function this.checkLanguage(subpage)&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 any character that is not&lt;br /&gt;
        ASCII and not a lowercase letter, minus-hyphen, or digit, and any code&lt;br /&gt;
        that does not start by a letter or does not finish by a letter or digit.&lt;br /&gt;
        of that has more than 8 characters between hyphens, or has two hyphens.&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;
    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 language of the given page, if it is a translation.&lt;br /&gt;
--]]&lt;br /&gt;
function this.getTitleLanguage(title, default)&lt;br /&gt;
    --[[This code does not work in all namespaces where the Translate tool works:&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, default)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[Get the language of the current page, if it is a translation.&lt;br /&gt;
--]]&lt;br /&gt;
function this.getCurrentLanguage(default)&lt;br /&gt;
    return this.getTitleLanguage(mw.title.getCurrentTitle(), default)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[Get the language of the current frame, if it is a translation.&lt;br /&gt;
--]]&lt;br /&gt;
function this.getFrameLanguage(frame)&lt;br /&gt;
    local args = frame.args&lt;br /&gt;
    local default = args[&amp;#039;default&amp;#039;] or &amp;#039;&amp;#039;&lt;br /&gt;
    return this.getTitleLanguage(frame:getParent():getTitle(), default)&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;
function this.renderTranslatedTemplate(frame)&lt;br /&gt;
    local args = frame.args&lt;br /&gt;
    local pagename = args[&amp;#039;template&amp;#039;]&lt;br /&gt;
    &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 title&lt;br /&gt;
    local namespace = args[&amp;#039;namespace&amp;#039;] or &amp;#039;&amp;#039;&lt;br /&gt;
    if namespace ~= &amp;#039;&amp;#039; -- Checks for namespace parameter for custom ns.&lt;br /&gt;
    then&lt;br /&gt;
        title = mw.title.new(pagename, namespace) or {} -- 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 = mw.title.new(pagename, namespace) or {} -- Costly&lt;br /&gt;
        if (title.id or 0) == 0&lt;br /&gt;
        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 = mw.title.new(pagename, namespace) or {} -- 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[&amp;#039;uselang&amp;#039;] or &amp;#039;&amp;#039;&lt;br /&gt;
    if subpage == &amp;#039;&amp;#039;&lt;br /&gt;
    then&lt;br /&gt;
        subpage = this.getFrameLanguage(frame)&lt;br /&gt;
    end&lt;br /&gt;
    if subpage == &amp;#039;&amp;#039;&lt;br /&gt;
    then&lt;br /&gt;
        -- Check if a translation of the pagename exists in English&lt;br /&gt;
        local newtitle = mw.title.new(pagename .. &amp;#039;/&amp;#039; .. &amp;#039;en&amp;#039;, namespace) or {} -- Costly&lt;br /&gt;
        -- Use the translation when it exists&lt;br /&gt;
        if (newtitle.id or 0) ~= 0&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 = mw.title.new(pagename .. &amp;#039;/&amp;#039; .. subpage, namespace) or {} -- Costly&lt;br /&gt;
        if (newtitle.id or 0) == 0&lt;br /&gt;
        then&lt;br /&gt;
            -- Check if a translation of the pagename exists in English&lt;br /&gt;
            newtitle = mw.title.new(pagename .. &amp;#039;/&amp;#039; .. &amp;#039;en&amp;#039;, namespace) or {} -- Costly&lt;br /&gt;
        end&lt;br /&gt;
        -- Use the translation when it exists&lt;br /&gt;
        if (newtitle.id or 0) ~= 0&lt;br /&gt;
        then&lt;br /&gt;
            title = newtitle&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    -- At this point the title should exist, otherwise render a red link to the missing page (resolved in its assumed namespace)&lt;br /&gt;
    if (title.id or 0) == 0&lt;br /&gt;
    then&lt;br /&gt;
    	return &amp;#039;[[&amp;#039; .. title.prefixedText .. &amp;#039;]]&amp;#039;&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 arguments = {}&lt;br /&gt;
    for k, v in pairs((frame:getParent() or {}).args) 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;
    arguments[&amp;#039;template&amp;#039;] = title.prefixedText -- 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;namespace&amp;#039;] = nil -- discard the specified namespace override&lt;br /&gt;
    &lt;br /&gt;
    return frame:expandTemplate{title = &amp;#039;:&amp;#039; .. title.prefixedText, args = arguments}&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return this&lt;/div&gt;</summary>
		<author><name>DavidWhitten</name></author>	</entry>

	</feed>