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 = require('Module:TableTools').includes local ne = lib.isNotEmpty local ie = lib.isEmpty

function p.main(frame) local args = require('Module:Arguments').getArgs(frame, {		parentFirst = true,		removeBlanks = false,		wrappers = {'Template:Other Languages'}	}) 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) frame = frame or mw.getCurrentFrame local TLcol = false local NoSpan = lib.split(args.nospan or '',',') if type(NoSpan) == 'string' then NoSpan = {''} end --list to determine order of rows in table local langOrder = {'en', 'zhs', 'zht', 'ja', 'ko', 'es', 'fr', 'ru', 'th', 'vi', 'de', 'id', 'pt', 'tr', 'it'} --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 local categories = mw.html.create('') --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[langCode]) then if args['default_hidden'] then if ((ne(args[langCode .. '_tl']) or ne(args.zh_tl)) and TLcol == false) then tr:tag('th'):wikitext('Literal Meaning') TLcol = true end else if ((args[langCode .. '_tl'] or args.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[langCode] or nil local Tl = args[langCode .. '_tl'] or nil local Rm = args[langCode .. '_rm'] or nil local Loanword = args[langCode .. '_lang'] or nil local Note = args[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) end if search(NoSpan,langCode) then td:wikitext(displayTx) else td:node(SelectiveSpan(displayTx,(Lang.span or langCode))) end --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.zh_note) and (TLcol == false or (ie(args.zh_tl) and ie(Tl) and TLcol)) then td:wikitext( frame:extensionTag{ name = 'ref', content = i18n:msg('zh-ref') .. args.zh_note, args = { name = 'zh', group = '•' } } ) end --zhs, zht and ja special zhja note initialize if (langCode == 'zhs' or langCode == 'zht') and ne(args.zhja_note) and (TLcol == false or (ie(args.zh_tl) and ie(Tl) and TLcol)) then td:wikitext( frame:extensionTag{ name = 'ref', content = i18n:msg('zhja-ref') .. args.zhja_note, args = { name = 'zhja', group = '•' } } ) end if (langCode == 'ja') and ne(args.zhja_note) and ((ie(Tl) and TLcol) or TLcol == false) then td:wikitext( frame:extensionTag{ name = 'ref', content = i18n:msg('zhja-ref') .. args.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.ko_nn or nil, ni = args.ko_ni or nil, bcred = args.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.ko_nn or nil, ni = args.ko_ni or nil, bcred = args.ko_bcred or nil} if 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.ko_nn or nil, ni = args.ko_ni or nil, bcred = args.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 lib.isEmpty(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) 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.zh_note)) then td:wikitext(frame:extensionTag{ name = 'ref', content = i18n:msg('zh-ref') .. args.zh_note, args = { name = 'zh', group = '•' } }) end --special zhja note if (search({'zhs','zht','ja'},langCode) and ne(args.zhja_note)) then td:wikitext(frame:extensionTag{ name = 'ref', content = i18n:msg('zhja-ref') .. args.zhja_note, args = { name = 'zhja', group = '•' } }) end end if TLcol == true and ie(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.zh_tl and search({'zhs','zht'},langCode)) then if ne(args.zht) and langCode == 'zhs' then local td = tr:tag('td') td:attr('rowspan',2):wikitext(args.zh_tl) --zhs and zht special zh note if args.zh_note then td:wikitext(frame:extensionTag{ name = 'ref', content = i18n:msg('zh-ref') .. args.zh_note, args = { name = 'zh', group = '•' } }) end --zhs, zht and ja special zhja note initialize if args.zhja_note then td:wikitext(frame:extensionTag{ name = 'ref', content = i18n:msg('zhja-ref') .. args.zhja_note, args = { name = 'zhja', group = '•' } }) end elseif ne(args.zhs) and langCode == 'zht' then else local td = tr:tag('td') td:wikitext(args.zh_tl) --zhs and zht special zh note if args.zh_note then td:wikitext(frame:extensionTag{ name = 'ref', content = i18n:msg('zh-ref') .. args.zh_note, args = { name = 'zh', group = '•' } }) end --zhs, zht and ja special zhja note initialize if args.zhja_note then td:wikitext(frame:extensionTag{ name = 'ref', content = i18n:msg('zhja-ref') .. args.zhja_note, args = { name = 'zhja', group = '•' } }) end end if ie(args.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['default_hidden'] and TLcol == true then categories:wikitext('') elseif args['hide_tl'] then categories:wikitext('') end --return finished table with reflist and categories return tostring(articletable:node(require('Module:Namespace detect').main{["main"]=categories})) .. frame:extensionTag{ name = 'references', args = { group = '•' } } end return p