if type(text_code[name]) ~= 'table' then
quit('m_ftl_table', cfg.text_title, name)
end
end
local translation = text_code.translation_table
if translation then
if translation.plural_suffix then
plural_suffix = translation.plural_suffix
end
local ts = translation.specials
if ts then
if ts.utype then
specials.utype = ts.utype
end
if ts.ucode then
specials.ucode = ts.ucode
end
end
local tm = translation.mtext
if tm then
if tm.section_names then
mtext.section_names = tm.section_names
end
if tm.titles then
mtext.titles = tm.titles
end
if tm.messages then
mtext.messages = tm.messages
end
end
end
local is_sandbox
local conversion_data_title = mtext.titles.conversion_data
if cfg.data_title and cfg.data_title ~= conversion_data_title then
if is_test_run then
is_sandbox = true
data_preamble = nil
data_postamble = nil
out_unit_prefix = 'local all_units = {'
out_unit_suffix = '}'
out_default_prefix = '\nlocal default_exceptions = {'
out_default_suffix = '}'
out_default_item = '\t["{symbol}"] = "{default}",'
out_link_prefix = '\nlocal link_exceptions = {'
out_link_suffix = '}'
out_link_item = '\t["{symbol}"] = "{link}",'
out_perunit_prefix = '\nlocal per_unit_fixups = {'
out_perunit_suffix = '}'
out_perunit_item = '\t["{lhs}"] = {rhs},'
end
else
cfg.data_title = conversion_data_title
end
local units, defaults, links, perunits = prepare_data(cfg, is_sandbox)
if data_preamble then
results:add(data_preamble)
end
results:add(out_unit_prefix)
for _, unit in ipairs(units) do
local spec
if unit.target then
spec = alias_specification
elseif unit.per then
spec = per_specification
unit.per = numbered_table_as_string(unit.per, unit)
elseif unit.shouldbe then
spec = shouldbe_specification
elseif unit.combination then
spec = combination_specification
unit.combination = numbered_table_as_string(unit.combination, unit)
if unit.multiple then
unit.multiple = numbered_table_as_string(unit.multiple, unit)
end
else
spec = unit_specification
end
add_unit_lines(results, unit, spec)
end
results:add(out_unit_suffix)
for _, t in ipairs({
{ defaults, out_default_prefix, out_default_item, out_default_suffix },
{ links , out_link_prefix , out_link_item , out_link_suffix },
{ perunits, out_perunit_prefix, out_perunit_item, out_perunit_suffix } }) do
local data, prefix, item, suffix = t[1], t[2], t[3], t[4]
if #data > 0 or not is_sandbox then
results:add(prefix)
for _, unit in ipairs(data) do
results:add((item:gsub('{([%w_]+)}', unit)))
end
results:add(suffix)
end
end
if data_postamble then
results:add(data_postamble)
end
end  
local function makeunits
local args = .args
local config = {
data_title = args[1],
text_title = args[2] or 'Module:Convert/text',
varcolumns = tonumber(args.varcolumns) or 5, -- #columns in "Variable names" section; slwiki uses 5
maxerrors = 20,
}
local results = collection
local ok, msg = pcall(_makeunits, config, results)
if not ok then
results:add(message('m_error'))
results:add('')
results:add(msg)
end
local warn = ''
if warnings.n > 0 then
warn = message('m_warning') .. '\n\n' .. warnings:join .. '\n\n'
end
-- Pre tags returned by a module are html tags, not like wikitext <pre>...</pre>.
-- The following renders the text as is, and preserves tab characters.
return '<pre>\n' .. mw.text.nowiki(warn .. results:join) .. '\n</pre>\n'
end  
return { makeunits = makeunits }