Module:Other Languages

local p 			= {} local lib			= require('Module:Feature') local KOrm			= require('Module:Ko-rm') local i18n			= require('Module:I18n').loadMessages('Other Languages') local SelectiveSpan	= require('Module:Lang').SelectiveSpan local search		= lib.inArray local ne			= lib.isNotEmpty local ie			= lib.isEmpty local langOrder 	= {'en', 'zhs', 'zht', 'ja', 'ko', 'es', 'fr', 'ru', 'th', 'vi', 'de', 'id', 'pt', 'tr', 'it'} local categories	= mw.html.create local noCat        = {}

function p.main(frame) local args = require('Module:Arguments').getArgs(frame, {		parentFirst = true,		removeBlanks = false,		wrappers = {'Template:Other Languages'}	}) if ne(args['Transclude']) then local new_index = lib.split(args['Transclude'], '#') local transclude = lib.split(new_index[1], ';') p.Transclude(args, transclude[1], transclude[2], new_index[2]) else local Y = 1 while ne(args['Transclude_' .. tostring(Y)]) or ne(args[Y]) do local new_index = lib.split((args['Transclude_' .. tostring(Y)] or args[Y]), '#') local transclude = lib.split(new_index[1], ';') p.Transclude(args, transclude[1], transclude[2], new_index[2]) Y = Y + 1 end end return p._main(args, frame) end

--- Entry point for other modules. --	@param args The table of arguments for which to generate an HTML table --	@param frame Optional argument to specify a frame, which will be used for its extensionTag. --		If not specified, the current frame will be used. function p._main(args, frame) local out if ne(args['1_en']) then out = mw.html.create('div'):css{['display']='flex', ['column-gap'] = '15px', ['flex-direction'] = 'row', ['flex-wrap'] = 'wrap'} local Y = 1 local y = tostring(Y) while args[y .. '_en'] do			local entry = out:tag('div') entry:tag('h3'):wikitext(args[y .. '_header'] or args[y .. '_en']) entry:node(p.Table(args, frame, (y .. '_'))) --continue loop Y = Y+1 y = tostring(Y) end else out = p.Table(args, frame) end return tostring(out:node(require('Module:Namespace detect').main{["main"]=categories})) .. (not args.noref and frame:extensionTag{ name = 'references', args = { group = '•' } } or '') end

function p.Table(args, frame, prefix) prefix = prefix or '' local TLcol = false --list to determine order of rows in table --list of all lang codes and some settings used in the loop	['lang_code'] = {		rm = setting for the loop to check if lang should have rm,		span = lang code to use in the transcript span if different from base lang code	}	-- local lang = { ['zhs'] = { rm = true, span = 'zh-Hans' }, ['zht'] = { rm = true, span = 'zh-Hant' }, ['ja'] = { rm = true }, ['ko'] = { rm = true }, ['ru'] = { rm = true }, ['th'] = { rm = true } }	--initialize the table in html syntax and the category variable local articletable = mw.html.create('table'):addClass('article-table'):newline --header row local tr = articletable:tag('tr') tr:tag('th'):wikitext('Language') tr:tag('th'):wikitext(args.name or 'Official Name') --check if any [lang]_tl exists to show tl column if true for _, langCode in ipairs(langOrder) do if ne(args[prefix .. langCode]) then if args[prefix .. 'default_hidden'] or args['default_hidden'] then if ((ne(args[prefix .. langCode .. '_tl']) or ne(args[prefix .. 'zh_tl'])) and TLcol == false) then tr:tag('th'):wikitext('Literal Meaning') TLcol = true end else if ((args[prefix .. langCode .. '_tl'] or args[prefix .. 'zh_tl']) and TLcol == false) then tr:tag('th'):wikitext('Literal Meaning') TLcol = true end end end end --start loop to create the lang rows with langOrder as iterator list to determine the order of the rows for i, langCode in ipairs(langOrder) do		--variables for ease of use local Tx = args[prefix .. langCode] or nil local Tl = args[prefix .. langCode .. '_tl'] or nil local Rm = args[prefix .. langCode .. '_rm'] or nil local Loanword = args[prefix .. langCode .. '_lang'] or nil local Note = args[prefix .. langCode .. '_note'] or nil local Lang = lang[langCode] or {} --default to pagename if en transcript is not given if langCode == 'en' then if Tx then if ie(Tx) then Tx = mw.title.getCurrentTitle.text end else Tx = mw.title.getCurrentTitle.text end end --do a check for if transcript for the lang exists and is not blank, move on to next lang if false if Tx then if ne(Tx) then local tr = articletable:tag('tr') --open and close "Language" column cell with value and open "Official Name" column cell with transcript tr:tag('td'):wikitext(i18n:msg(langCode)) local td = tr:tag('td') local displayTx = Tx				if langCode == 'ko' then displayTx = KOrm.strip(Tx) -- strip TX from keywords used in Module:Ko-rm elseif langCode == 'fr' then displayTx = Tx								:gsub(' !', ' !') -- add  after/before punctuation so it does not break from the text it relates to								:gsub(' %?', ' ?') -- :gsub(' :', ' :') -- :gsub(' ~', ' ~') -- :gsub(' %-', ' -') -- :gsub(' &', ' &') -- :gsub(' »', ' »') -- :gsub('« ', '« ') -- elseif langCode == 'ru' then displayTx = Tx								:gsub('%-', '- ') -- add after hyphens as chromium based browsers do not support Russian properly :gsub('UNIQ%- %- (%w+)%- (%x+)%- QINU', 'UNIQ--%1-%2-QINU') --remove from strip markers as for some reason they're affected :gsub('(<[^>]+)%- ', '%1-') --remove from html tags as for some reason they're affected elseif langCode == 'th' then displayTx = Tx :gsub('%.%.%.', '... ') -- add after elipses as they do not break properly due to not spacing in Thai, making scroll horizontally elseif langCode == 'de' then displayTx = Tx :gsub('%.%.%.', '... ') -- add after elipses as they do not break properly due to not spacing in German, making scroll horizontally end local code = Lang.span or langCode td:node(SelectiveSpan(displayTx,code,(code == 'vi' and true or false))) --lang notes next to transcript if corresponding translation parameter is blank or translation column is not shown --general lang note if ne(Note) and ((ie(Tl) and TLcol) or TLcol == false) then td:wikitext( frame:extensionTag{ name = 'ref', content = i18n:msg((langCode .. '-ref')) .. Note, args = { name = langCode, group = '•' } } ) end --zhs and zht special zh note if (langCode == 'zhs' or langCode == 'zht') and ne(args[prefix .. 'zh_note']) and (TLcol == false or (ie(args[prefix .. 'zh_tl']) and ie(Tl) and TLcol)) then td:wikitext( frame:extensionTag{ name = 'ref', content = i18n:msg('zh-ref') .. args[prefix .. 'zh_note'], args = { name = 'zh', group = '•' } } ) end --zhs, zht and ja special zhja note initialize if (langCode == 'zhs' or langCode == 'zht') and ne(args[prefix .. 'zhja_note']) and (TLcol == false or (ie(args[prefix .. 'zh_tl']) and ie(Tl) and TLcol)) then td:wikitext( frame:extensionTag{ name = 'ref', content = i18n:msg('zhja-ref') .. args[prefix .. 'zhja_note'], args = { name = 'zhja', group = '•' } } ) end if (langCode == 'ja') and ne(args[prefix .. 'zhja_note']) and ((ie(Tl) and TLcol) or TLcol == false) then td:wikitext( frame:extensionTag{ name = 'ref', content = i18n:msg('zhja-ref') .. args[prefix .. 'zhja_note'], args = { name = 'zhja', group = '•' } } ) end -- romanization section if Lang.rm then --automatic russian romanization through Module:Ru-rm if langCode == 'ru' then local ru_rm = mw.text.unstrip(Tx) ru_rm = require('Module:Ru-rm')._main{ru_rm} --display romanization only if it differs from transcript if mw.text.unstrip(Tx) ~= ru_rm then td:wikitext(' '):tag('small'):tag('i'):wikitext(ru_rm) end --automatic korean romanization through Module:Ko-rm elseif langCode == 'ko' then local ko_rm = mw.text.unstrip(Tx) local ko_mode = args.ko_mode or '1' --if manual rm exists, use it, otherwise automatic, and add category if param exists but no manual rm was given if ko_mode == '2' then ko_rm = KOrm._main{ko_rm, capi = 1, nn = args[prefix .. 'ko_nn'] or nil, ni = args[prefix .. 'ko_ni'] or nil, bcred = args[prefix .. 'ko_bcred'] or nil} td:wikitext(' Auto-Rm: ['):tag('small'):tag('i'):wikitext(ko_rm):done:wikitext(']') td:wikitext(' Manual-Rm: ['):tag('small'):tag('i'):wikitext((Rm or '')):done:wikitext(']') elseif (Rm and ne(Rm) and ko_mode == '1') then td:wikitext(' '):tag('small'):tag('i'):wikitext(Rm) elseif ko_mode == '1' then ko_rm = KOrm._main{ko_rm, capi = 1, nn = args[prefix .. 'ko_nn'] or nil, ni = args[prefix .. 'ko_ni'] or nil, bcred = args[prefix .. 'ko_bcred'] or nil} if Rm == '' and not noCat[prefix .. 'ko_rm'] then categories:wikitext('') end --display romanization only if it differs from transcript if mw.text.unstrip(Tx) ~= ko_rm then td:wikitext(' '):tag('small'):tag('i'):wikitext(ko_rm) end end if Rm ~= nil then ko_rm2 = require('Module:Ko-rm')._main{ko_rm, capi = 1, nn = args[prefix .. 'ko_nn'] or nil, ni = args[prefix .. 'ko_ni'] or nil, bcred = args[prefix .. 'ko_bcred'] or nil} if Rm == ko_rm2 then categories:wikitext('') else categories:wikitext('') end end --general romanization inclusion elseif Rm then td:wikitext(' '):tag('small'):tag('i'):wikitext(Rm) if ie(Rm) and not noCat[prefix .. langCode .. '_rm'] then categories:wikitext('') end end end --translation section if Tl and TLcol then --special format for translations which are loanwords local td = tr:tag('td') if Loanword then local CODE = mw.loadData('Module:Lang/code')[Loanword] or nil if CODE then td:wikitext(' ', CODE, ' : ', Tl) end if ie(Tl) and not noCat[prefix .. langCode .. '_tl'] then categories:wikitext('') end --general [lang]_tl formatting else td:wikitext(Tl) end if ne(Tl) then --general [lang]_note formatting if ne(Note) then td:wikitext(frame:extensionTag{ name = 'ref', content = i18n:msg((langCode .. '-ref')) .. Note, args = { name = langCode, group = '•' } }) end --zhs and zht special zh note if (search({'zhs','zht'},langCode) and ne(args[prefix .. 'zh_note'])) then td:wikitext(frame:extensionTag{ name = 'ref', content = i18n:msg('zh-ref') .. args[prefix .. 'zh_note'], args = { name = 'zh', group = '•' } }) end --special zhja note if (search({'zhs','zht','ja'},langCode) and ne(args[prefix .. 'zhja_note'])) then td:wikitext(frame:extensionTag{ name = 'ref', content = i18n:msg('zhja-ref') .. args[prefix .. 'zhja_note'], args = { name = 'zhja', group = '•' } }) end end if TLcol == true and ie(Tl) and not noCat[prefix .. langCode .. '_tl'] then categories:wikitext('') end --default behaviour if no [lang]_tl but shown "Literal Meaning" column elseif TLcol then --special zh_tl when zhs logic if (args[prefix .. 'zh_tl'] and search({'zhs','zht'},langCode)) then if ne(args[prefix .. 'zht']) and langCode == 'zhs' then local td = tr:tag('td') td:attr('rowspan',2):wikitext(args[prefix .. 'zh_tl']) --zhs and zht special zh note if args[prefix .. 'zh_note'] then td:wikitext(frame:extensionTag{ name = 'ref', content = i18n:msg('zh-ref') .. args[prefix .. 'zh_note'], args = { name = 'zh', group = '•' } }) end --zhs, zht and ja special zhja note initialize if args[prefix .. 'zhja_note'] then td:wikitext(frame:extensionTag{ name = 'ref', content = i18n:msg('zhja-ref') .. args[prefix .. 'zhja_note'], args = { name = 'zhja', group = '•' } }) end elseif ne(args[prefix .. 'zhs']) and langCode == 'zht' then else local td = tr:tag('td') td:wikitext(args[prefix .. 'zh_tl']) --zhs and zht special zh note if args[prefix .. 'zh_note'] then td:wikitext(frame:extensionTag{ name = 'ref', content = i18n:msg('zh-ref') .. args[prefix .. 'zh_note'], args = { name = 'zh', group = '•' } }) end --zhs, zht and ja special zhja note initialize if args[prefix .. 'zhja_note'] then td:wikitext(frame:extensionTag{ name = 'ref', content = i18n:msg('zhja-ref') .. args[prefix .. 'zhja_note'], args = { name = 'zhja', group = '•' } }) end end if ie(args[prefix .. 'zh_tl']) and not noCat[prefix .. 'zh_tl'] then categories:wikitext('') end --default behaviour if "Literal Meaning" column is shown but no [lang]_tl else tr:tag('td'):wikitext('&mdash;') end end else categories:wikitext('') end end --end of loop end --check for administrative categories if (args[prefix .. 'default_hidden'] or args['default_hidden']) and TLcol == true then categories:wikitext('') end if args['hide_tl'] or args['multi'] then categories:wikitext('') end if ne(args['revise']) then categories:wikitext('') end --return finished table return articletable end

function p.Transclude(retArgs, page, og_index, new_index) local Parser = require('Module:Parser').getTemplateArgs local frame = mw.getCurrentFrame local og_prefix = '' local new_index = new_index or og_index or 0 if ne(og_index) then og_prefix = tostring(og_index) .. '_'	end local params = Parser(page, {only='Other Languages'}) local at_least_one = false if params == nil then categories:wikitext('') return end local new_prefix = tostring(new_index) .. '_'	if new_prefix == '0_' then new_prefix = '' end for param, value in pairs(params) do		local retParam = param if retParam:find('^%d_') then retParam = param:gsub('^%d+_', new_prefix, 1) elseif new_prefix ~= '' then retParam = new_prefix .. retParam end if retArgs[retParam] == nil and (not param:find('revise')) then if (og_prefix ~= '' and param:find('^' .. og_prefix)) or (og_prefix == '' and (not param:find('^%d+_'))) then retArgs[retParam] = frame:preprocess(value) noCat[retParam] = true at_least_one = true end elseif retArgs[retParam] == '{nil}' then retArgs[retParam] = nil end end if not at_least_one then categories:wikitext('') else categories:wikitext('') end

end

return p