Module:Multilingual description: Difference between revisions
From Neodyland Wiki
More actions
m be prepared for all cases |
m Fix: Failed on pages passing pipes chars (|) as arguments |
||
| Line 2: | Line 2: | ||
function mld(pargs) | function mld(pargs) | ||
local frame = mw.getCurrentFrame() | |||
local sorting = require('Module:Multilingual description/sort') | local sorting = require('Module:Multilingual description/sort') | ||
local processed = {} | local processed = {} | ||
local ret = {} | local ret = {} | ||
local addDesc = function(langcode, val) | |||
table.insert( ret, frame:expandTemplate{ title = 'ls', args = { langcode, val, classes = 'description' } } ) | |||
end | |||
for k, v in pairs( sorting ) do | for k, v in pairs( sorting ) do | ||
if pargs[v] then | if pargs[v] then | ||
addDesc(v, pargs[v]) | |||
end | end | ||
processed[v] = 1 | processed[v] = 1 | ||
| Line 15: | Line 20: | ||
for k, v in pairs( pargs ) do | for k, v in pairs( pargs ) do | ||
if not processed[k] and type(k) == 'string' and mw.language.isSupportedLanguage(k) then | if not processed[k] and type(k) == 'string' and mw.language.isSupportedLanguage(k) then | ||
addDesc(k, v) | |||
end | end | ||
end | end | ||
| Line 25: | Line 30: | ||
local pargs = ( frame:getParent() or {} ).args or {} | local pargs = ( frame:getParent() or {} ).args or {} | ||
return | return mld(pargs) | ||
end | end | ||
function p.runTests() | --function p.runTests() | ||
local expected = '{{ls|de|Leipzig ist|classes=description}}{{ls|en|Leipzig is|classes=description}}{{ls|fr|Leipzig est|classes=description}}{{ls|hsb|Lipsk je|classes=description}}{{ls|oc|Leipzig es|classes=description}}' | --local expected = '{{ls|de|Leipzig ist|classes=description}}{{ls|en|Leipzig is|classes=description}}{{ls|fr|Leipzig est|classes=description}}{{ls|hsb|Lipsk je|classes=description}}{{ls|oc|Leipzig es|classes=description}}' | ||
local input = { ['fr'] = 'Leipzig est', ['en'] = 'Leipzig is', ['hsb'] = 'Lipsk je', ['de'] = 'Leipzig ist', ['oc'] = 'Leipzig es' } | --local input = { ['fr'] = 'Leipzig est', ['en'] = 'Leipzig is', ['hsb'] = 'Lipsk je', ['de'] = 'Leipzig ist', ['oc'] = 'Leipzig es' } | ||
return mld(input) == expected | --return mld(input) == expected | ||
end | --end | ||
return p | return p | ||
Revision as of 07:33, 2 March 2014
This documentation is transcluded from Module:Multilingual description/doc.
local p = {}
function mld(pargs)
local frame = mw.getCurrentFrame()
local sorting = require('Module:Multilingual description/sort')
local processed = {}
local ret = {}
local addDesc = function(langcode, val)
table.insert( ret, frame:expandTemplate{ title = 'ls', args = { langcode, val, classes = 'description' } } )
end
for k, v in pairs( sorting ) do
if pargs[v] then
addDesc(v, pargs[v])
end
processed[v] = 1
end
for k, v in pairs( pargs ) do
if not processed[k] and type(k) == 'string' and mw.language.isSupportedLanguage(k) then
addDesc(k, v)
end
end
return table.concat(ret)
end
function p.mld(frame)
local pargs = ( frame:getParent() or {} ).args or {}
return mld(pargs)
end
--function p.runTests()
--local expected = '{{ls|de|Leipzig ist|classes=description}}{{ls|en|Leipzig is|classes=description}}{{ls|fr|Leipzig est|classes=description}}{{ls|hsb|Lipsk je|classes=description}}{{ls|oc|Leipzig es|classes=description}}'
--local input = { ['fr'] = 'Leipzig est', ['en'] = 'Leipzig is', ['hsb'] = 'Lipsk je', ['de'] = 'Leipzig ist', ['oc'] = 'Leipzig es' }
--return mld(input) == expected
--end
return p