https://wiki.hisgis.nl/index.php?title=Module:Template_translation&feed=atom&action=historyModule:Template translation - Bewerkingsoverzicht2024-03-29T09:59:31ZBewerkingsoverzicht voor deze pagina op de wikiMediaWiki 1.38.2https://wiki.hisgis.nl/index.php?title=Module:Template_translation&diff=793&oldid=prevThomas: 1 versie geïmporteerd2019-11-05T10:39:08Z<p>1 versie geïmporteerd</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<tr class="diff-title" lang="nl">
<td colspan="1" style="background-color: #fff; color: #202122; text-align: center;">← Oudere versie</td>
<td colspan="1" style="background-color: #fff; color: #202122; text-align: center;">Versie van 5 nov 2019 11:39</td>
</tr><tr><td colspan="2" class="diff-notice" lang="nl"><div class="mw-diff-empty">(geen verschil)</div>
</td></tr></table>Thomashttps://wiki.hisgis.nl/index.php?title=Module:Template_translation&diff=792&oldid=previnterwiki>DannyS712: Changed protection level for "Module:Template translation": Fully protected via cascading protection, autoconfirmed protection is misleading ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite))2019-10-05T17:07:46Z<p>Changed protection level for "<a href="/wiki/Module:Template_translation" title="Module:Template translation">Module:Template translation</a>": Fully protected via cascading protection, autoconfirmed protection is misleading ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite))</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<tr class="diff-title" lang="nl">
<td colspan="1" style="background-color: #fff; color: #202122; text-align: center;">← Oudere versie</td>
<td colspan="1" style="background-color: #fff; color: #202122; text-align: center;">Versie van 5 okt 2019 18:07</td>
</tr><tr><td colspan="2" class="diff-notice" lang="nl"><div class="mw-diff-empty">(geen verschil)</div>
</td></tr></table>interwiki>DannyS712https://wiki.hisgis.nl/index.php?title=Module:Template_translation&diff=790&oldid=prevThomas: 1 versie geïmporteerd2019-09-02T13:28:31Z<p>1 versie geïmporteerd</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<tr class="diff-title" lang="nl">
<td colspan="1" style="background-color: #fff; color: #202122; text-align: center;">← Oudere versie</td>
<td colspan="1" style="background-color: #fff; color: #202122; text-align: center;">Versie van 2 sep 2019 14:28</td>
</tr><tr><td colspan="2" class="diff-notice" lang="nl"><div class="mw-diff-empty">(geen verschil)</div>
</td></tr></table>Thomashttps://wiki.hisgis.nl/index.php?title=Module:Template_translation&diff=791&oldid=previnterwiki>AKlapper (WMF): 40 revisions imported from :meta:Module:Template_translation: See phab:T2310012019-09-02T12:39:18Z<p>40 revisions imported from <a href="/index.php?title=Meta:Module:Template_translation&action=edit&redlink=1" class="new" title="Meta:Module:Template translation (de pagina bestaat niet)">meta:Module:Template_translation</a>: See <a href="/index.php?title=Phab:T231001&action=edit&redlink=1" class="new" title="Phab:T231001 (de pagina bestaat niet)">phab:T231001</a></p>
<p><b>Nieuwe pagina</b></p><div>local this = {}<br />
<br />
function this.checkLanguage(subpage, default)<br />
--[[Check first if there's an any invalid character that would cause the<br />
mw.language.isKnownLanguageTag function() to throw an exception:<br />
- all ASCII controls in [\000-\031\127],<br />
- double quote ("), sharp sign (#), ampersand (&), apostrophe ('),<br />
- slash (/), colon (:), semicolon (;), lower than (<), greater than (>),<br />
- brackets and braces ([, ], {, }), pipe (|), backslash (\\)<br />
All other characters are accepted, including space and all non-ASCII<br />
characters (including \192, which is invalid in UTF-8).<br />
--]]<br />
if mw.language.isValidCode(subpage) and mw.language.isKnownLanguageTag(subpage)<br />
--[[However "SupportedLanguages" are too restrictive, as they discard many<br />
valid BCP47 script variants (only because MediaWiki still does not<br />
define automatic transliterators for them, e.g. "en-dsrt" or<br />
"fr-brai" for French transliteration in Braille), and country variants,<br />
(useful in localized data, even if they are no longer used for<br />
translations, such as zh-cn, also useful for legacy codes).<br />
We want to avoid matching subpagenames containing any uppercase letter,<br />
(even if they are considered valid in BCP 47, in which they are<br />
case-insensitive; they are not "SupportedLanguages" for MediaWiki, so<br />
they are not "KnownLanguageTags" for MediaWiki).<br />
To be more restrictive, we exclude any character<br />
* that is not ASCII and not a lowercase letter, minus-hyphen, or digit,<br />
or does not start by a letter or does not finish by a letter or digit;<br />
* or that has more than 8 characters between hyphens;<br />
* or that has two hyphens;<br />
* or with specific uses in template subpages and unusable as languages.<br />
--]]<br />
or string.find(subpage, "^[%l][%-%d%l]*[%d%l]$") ~= nil<br />
and string.find(subpage, "[%d%l][%d%l][%d%l][%d%l][%d%l][%d%l][%d%l][%d%l][%d%l]") == nil<br />
and string.find(subpage, "%-%-") == nil<br />
and subpage ~= "doc"<br />
and subpage ~= "layout"<br />
and subpage ~= "sandbox"<br />
and subpage ~= "testcases"<br />
and subpage ~= "init"<br />
and subpage ~= "preload"<br />
then<br />
return subpage<br />
end<br />
-- Otherwise there's currently no known language subpage<br />
return default<br />
end<br />
<br />
--[[Get the last subpage of an arbitrary page if it is a translation.<br />
To be used from templates.<br />
]]<br />
function this.getLanguageSubpage(frame)<br />
local title = frame and frame.args[1]<br />
if not title or title == '' then<br />
title = mw.title.getCurrentTitle()<br />
end<br />
return this._getLanguageSubpage(title)<br />
end<br />
<br />
--[[Get the last subpage of an arbitrary page if it is a translation.<br />
To be used from Lua.<br />
]]<br />
function this._getLanguageSubpage(title)<br />
if type(title) == 'string' then<br />
title = mw.title.new(title)<br />
end<br />
if not title then<br />
-- invalid title<br />
return nil<br />
end<br />
--[[This code does not work in all namespaces where the Translate tool works.<br />
-- It works in the main namespace on Meta because it allows subpages there<br />
-- It would not work in the main namespace of English Wikipedia (but the<br />
-- articles are monolignual on that wiki).<br />
-- On Meta-Wiki the main space uses subpages and its pages are translated.<br />
-- The Translate tool allows translatng pages in all namespaces, even if<br />
-- the namespace officially does not have subpages.<br />
-- On Meta-Wiki the Category namespace still does not have subpages enabled,<br />
-- even if they would be very useful for categorizing templates, that DO have<br />
-- subpages (for documentatio and tstboxes pages). This is a misconfiguration<br />
-- bug of Meta-Wiki. The work-around is to split the full title and then<br />
-- get the last titlepart.<br />
local subpage = title.subpageText<br />
--]]<br />
local titleparts = mw.text.split(title.fullText, '/')<br />
local subpage = titleparts[#titleparts]<br />
return this.checkLanguage(subpage, '')<br />
end<br />
<br />
--[[Get the last subpage of the current page if it is a translation.<br />
]]<br />
function this.getCurrentLanguageSubpage()<br />
return this._getLanguageSubpage(mw.title.getCurrentTitle())<br />
end<br />
<br />
--[[Get the first part of the language code of the subpage, before the '-'.<br />
]]<br />
function this.getMainLanguageSubpage()<br />
parts = mw.text.split( this.getCurrentLanguageSubpage(), '-' )<br />
return parts[1]<br />
end<br />
<br />
--[[Get the last subpage of the current frame if it is a translation.<br />
Not used locally.<br />
]]<br />
function this.getFrameLanguageSubpage(frame)<br />
return this._getLanguageSubpage(frame:getParent():getTitle())<br />
end<br />
<br />
--[[Get the language of the current page.<br />
Not used locally.<br />
]]<br />
function this.getLanguage()<br />
local subpage = mw.title.getCurrentTitle().subpageText<br />
return this.checkLanguage(subpage, mw.language.getContentLanguage():getCode())<br />
end<br />
<br />
--[[Get the language of the current frame.<br />
Not used locally.<br />
]]<br />
function this.getFrameLanguage(frame)<br />
local titleparts = mw.text.split(frame:getParent():getTitle(), '/')<br />
local subpage = titleparts[#titleparts]<br />
return this.checkLanguage(subpage, mw.language.getContentLanguage():getCode())<br />
end<br />
<br />
function this.title(namespace, basepagename, subpage)<br />
local message, title<br />
local pagename = basepagename<br />
if (subpage or '') ~= ''<br />
then<br />
pagename = pagename .. '/' .. subpage<br />
end<br />
local valid, title = xpcall(function()<br />
return mw.title.new(pagename, namespace) -- costly<br />
end, function(msg) -- catch undocumented exception (!?)<br />
-- thrown when namespace does not exist. The doc still<br />
-- says it should return a title, even in that case...<br />
message = msg<br />
end)<br />
if valid and title ~= nil and (title.id or 0) ~= 0<br />
then<br />
return title<br />
end<br />
return { -- "pseudo" mw.title object with id = nil in case of error<br />
prefixedText = pagename, -- the only property we need below<br />
message = message -- only for debugging<br />
}<br />
end<br />
<br />
--[[If on a translation subpage (like Foobar/de), this function returns<br />
a given template in the same language, if the translation is available.<br />
Otherwise, the template is returned in its default language, without<br />
modification.<br />
This is aimed at replacing the current implementation of Template:TNTN.<br />
<br />
This version does not expand the returned template name: this solves the<br />
problem of self-recursion in TNT when translatable templates need themselves<br />
to transclude other translable templates (such as Tnavbar).<br />
]]<br />
function this.getTranslatedTemplate(frame, withStatus)<br />
local args = frame.args<br />
local pagename = args['template']<br />
<br />
--[[Check whether the pagename is actually in the Template namespace, or<br />
if we're transcluding a main-namespace page.<br />
(added for backward compatibility of Template:TNT)<br />
]]<br />
local title<br />
local namespace = args['tntns'] or ''<br />
if (namespace ~= '') -- Checks for tntns parameter for custom ns.<br />
then<br />
title = this.title(namespace, pagename) -- Costly<br />
else -- Supposes that set page is in ns10.<br />
namespace = 'Template'<br />
title = this.title(namespace, pagename) -- Costly<br />
if title.id == nil<br />
then -- not found in the Template namespace, assume the main namespace (for backward compatibility)<br />
namespace = ''<br />
title = this.title(namespace, pagename) -- Costly<br />
end<br />
end<br />
<br />
-- Get the last subpage and check if it matches a known language code.<br />
local subpage = args['uselang'] or ''<br />
if (subpage == '')<br />
then<br />
subpage = this.getCurrentLanguageSubpage()<br />
end<br />
if (subpage == '')<br />
then<br />
-- Check if a translation of the pagename exists in English<br />
local newtitle = this.title(namespace, pagename, 'en') -- Costly<br />
-- Use the translation when it exists<br />
if newtitle.id ~= nil<br />
then<br />
title = newtitle<br />
end<br />
else<br />
-- Check if a translation of the pagename exists in that language<br />
local newtitle = this.title(namespace, pagename, subpage) -- Costly<br />
if newtitle.id == nil<br />
then<br />
-- Check if a translation of the pagename exists in English<br />
newtitle = this.title(namespace, pagename, 'en') -- Costly<br />
end<br />
-- Use the translation when it exists<br />
if newtitle.id ~= nil<br />
then<br />
title = newtitle<br />
end<br />
end<br />
-- At this point the title should exist<br />
if withStatus then<br />
-- status returned to Lua function below<br />
return title.prefixedText, title.id ~= nil<br />
else<br />
-- returned directly to MediaWiki<br />
return title.prefixedText<br />
end<br />
end<br />
<br />
--[[If on a translation subpage (like Foobar/de), this function renders<br />
a given template in the same language, if the translation is available.<br />
Otherwise, the template is rendered in its default language, without<br />
modification.<br />
This is aimed at replacing the current implementation of Template:TNT.<br />
<br />
Note that translatable templates cannot transclude themselves other<br />
translatable templates, as it will recurse on TNT. Use TNTN instead<br />
to return only the effective template name to expand externally, with<br />
template parameters also provided externally.<br />
]]<br />
function this.renderTranslatedTemplate(frame)<br />
local title, found = this.getTranslatedTemplate(frame, true)<br />
-- At this point the title should exist prior to performing the expansion<br />
-- of the template, otherwise render a red link to the missing page<br />
-- (resolved in its assumed namespace). If we don't tet this here, a<br />
-- script error would be thrown. Returning a red link is consistant with<br />
-- MediaWiki behavior when attempting to transclude inexistant templates.<br />
if not found then<br />
return '[[' .. title .. ']]'<br />
end<br />
<br />
-- Copy args pseudo-table to a proper table so we can feed it to expandTemplate.<br />
-- Then render the pagename.<br />
local args = frame.args<br />
local pargs = (frame:getParent() or {}).args<br />
local arguments = {}<br />
if (args['noshift'] or '') == ''<br />
then<br />
for k, v in pairs(pargs) do<br />
-- numbered args >= 1 need to be shifted<br />
local n = tonumber(k) or 0<br />
if (n > 0)<br />
then<br />
if (n >= 2)<br />
then<br />
arguments[n - 1] = v<br />
end<br />
else<br />
arguments[k] = v<br />
end<br />
end<br />
else -- special case where TNT is used as autotranslate<br />
-- (don't shift again what is shifted in the invokation)<br />
for k, v in pairs(pargs) do<br />
arguments[k] = v<br />
end<br />
end<br />
arguments['template'] = title -- override the existing parameter of the base template name supplied with the full name of the actual template expanded<br />
arguments['tntns'] = nil -- discard the specified namespace override<br />
arguments['uselang'] = args['uselang'] -- argument forwarded into parent frame<br />
arguments['noshift'] = args['noshift'] -- argument forwarded into parent frame<br />
<br />
return frame:expandTemplate{title = ':' .. title, args = arguments}<br />
end<br />
<br />
--[[A helper for mocking TNT in Special:TemplateSandbox. TNT breaks<br />
TemplateSandbox; mocking it with this method means templates won't be<br />
localized but at least TemplateSandbox substitutions will work properly.<br />
Won't work with complex uses.<br />
]]<br />
function this.mockTNT(frame)<br />
local pargs = (frame:getParent() or {}).args<br />
local arguments = {}<br />
for k, v in pairs(pargs) do<br />
-- numbered args >= 1 need to be shifted<br />
local n = tonumber(k) or 0<br />
if (n > 0)<br />
then<br />
if (n >= 2)<br />
then<br />
arguments[n - 1] = v<br />
end<br />
else<br />
arguments[k] = v<br />
end<br />
end<br />
if not pargs[1]<br />
then<br />
return ''<br />
end<br />
return frame:expandTemplate{title = 'Template:' .. pargs[1], args = arguments}<br />
end<br />
<br />
return this</div>interwiki>AKlapper (WMF)