Module:Multilingual description: Difference between revisions
From Neodyland Wiki
More actions
m split some logic so we can run a simple test |
m be prepared for all cases |
||
| Line 14: | Line 14: | ||
for k, v in pairs( pargs ) do | for k, v in pairs( pargs ) do | ||
if not processed[k] and mw.language.isSupportedLanguage(k) then | if not processed[k] and type(k) == 'string' and mw.language.isSupportedLanguage(k) then | ||
table.insert(ret, '{{ls|' .. k .. '|' .. v .. '|classes=description}}') | table.insert(ret, '{{ls|' .. k .. '|' .. v .. '|classes=description}}') | ||
end | end | ||
Revision as of 22:47, 27 February 2014
This documentation is transcluded from Module:Multilingual description/doc.
local p = {}
function mld(pargs)
local sorting = require('Module:Multilingual description/sort')
local processed = {}
local ret = {}
for k, v in pairs( sorting ) do
if pargs[v] then
table.insert(ret, '{{ls|' .. v .. '|' .. pargs[v] .. '|classes=description}}')
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
table.insert(ret, '{{ls|' .. k .. '|' .. v .. '|classes=description}}')
end
end
return table.concat(ret)
end
function p.mld(frame)
local pargs = ( frame:getParent() or {} ).args or {}
return frame:preprocess( 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