Module:GetVerseTranslations

From Bodhicitta
Revision as of 19:17, 4 April 2025 by Jeremi (talk | contribs) ((by SublimeText.Mediawiker))

Documentation for this module may be created at Module:GetVerseTranslations/doc

local p = {}

function p.main(frame)

	local outputVerseTrans = ''

	local pargs = frame:getParent().args

	local verse = ''
	if pargs.verse then
		verse = pargs.verse
	else
		verse = mw.title.getCurrentTitle().subpageText
	end

	local SourcesData = mw.smw.ask( '[[Category:Translation Memories]][[TransMemID::+]][[RootTextVerseNumPadmaK::' .. verse .. ']][[SourceVersionLabel::+]][[SegmentFormat::Root]][[TransMemType::Root verses]]|?TransMemID|?SourceVersionLabel' )
	local RootSourceTransMems = {}
	local SourceLabels = {}
	if SourcesData and #SourcesData then
		for _, data in ipairs( SourcesData ) do
			table.insert( RootSourceTransMems, data.TransMemID )
			SourceLabels[data.TransMemID] = data.SourceVersionLabel
		end
	end

	for _, sourceTm in ipairs( RootSourceTransMems ) do

		local TransVersesData = mw.smw.ask( '[[Category:Translation Memories]][[RootSourceTransMem::' .. sourceTm .. ']][[SegmentFormat::Root]][[RootTextVerseNumPadmaK::' .. verse .. ']]|?#-=page|?TransMemID|?RootTextChapVerseNum|?TranslationWikiPage#|?ShortTitle|?TranslationCitation|?English|?SegmentOrder|sort=TransMemID,SegmentOrder|order=asc,asc|limit=10000' )

		if TransVersesData and #TransVersesData then

			local transTbl = {}
			local pages = ''
			local englishContent = ''
			local tmid = ''

			for num, trVerseData in ipairs( TransVersesData ) do

				tmid = trVerseData.TransMemID
				if type(transTbl[tmid]) == 'table' then else
					transTbl[tmid] = {}
				end
				if transTbl[tmid]['page'] then
					pages = transTbl[tmid]['page'] .. ';' .. trVerseData.page
				else
					pages = trVerseData.page
				end

				if transTbl[tmid]['english'] then
					englishContent = transTbl[tmid]['english'] .. '\n' .. trVerseData.English
				else
					englishContent = trVerseData.English
				end

				transTbl[tmid] = {
					page = pages ,
					shorttitle = trVerseData.ShortTitle ,
					english = englishContent ,
					source = trVerseData.TranslationWikiPage
				}

			end

			outputVerseTrans = outputVerseTrans .. '<div class="w-100 offwhite-bg shadow py-3"><div class="h3 col-12 px-0 pb-1 mb-2">' .. SourceLabels[sourceTm] .. ' - Translations</div><div class="d-flex flex-row pt-2 pb-4">'	
			
			for id, transData in pairs(transTbl) do

				local tmButton = frame:expandTemplate{ 
					title = 'InternalLink', 
					args = { 
						wikipage = transData.page , 
						label = 'TM <i class="fa-duotone fa-angle-right fa-sm"></i>'
					} 
				}
				tmButton = '<span class="tsdwiki-top-actions text-70 pl-4 font-style-normal">' .. tmButton .. '</span>'

				local order = ''
				if id == '001-Tsadra-BCA-Root-Padmakara' or id == '005-Tsadra-BCA-Root-Dunhuang' then
					order = 'order-first'
				end

				outputVerseTrans = outputVerseTrans .. frame:expandTemplate{ 
					title = 'VersionContent', 
					args = { 
						class = 'col-md-6 col-lg-4 col-xl-3' ,
						content = transData.english , 
						source = transData.source,
						tmButton =  tmButton,
						id = id .. '-translation',
						shorttitle = transData.shorttitle,
						order = order
					}
				}

			end

			outputVerseTrans = outputVerseTrans .. '</div></div>'

		end

	end

	return outputVerseTrans

end

return p