Module:GetVerseTranslations

From Bodhicitta
Revision as of 17:39, 8 October 2026 by Jeremi (talk | contribs) (Mobile: hint says only "swipe" on phones (shift + scroll is a desktop gesture))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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|?TranslationPublishedYear|sort=TranslationPublishedYear|order=asc' )
	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 .. ']][[TransMemID::!' .. sourceTm .. ']]|?#-=page|?TransMemID|?RootTextChapVerseNum|?TranslationWikiPage#|?ShortTitle|?TranslationCitation|?English|?SegmentOrder|?DuplicateRootTranslation|?TranslationPublishedYear|sort=TranslationPublishedYear|order=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 ,
					duplicate = trVerseData.DuplicateRootTranslation
				}

			end

			outputVerseTrans = outputVerseTrans .. '<div id="' .. sourceTm .. '-translations' .. '" class="translations-box toggleable px-0 px-md-3 col-md mb-3"><div class="offwhite-bg h-100 shadow rounded p-3 pb-5 mb-4 position-relative"><div class="h5 red-header pb-0 mb-3">' .. SourceLabels[sourceTm] .. ' - Other translations</div><div class="d-flex flex-row overflow-auto pb-0 pr-5" style="scrollbar-width: none;">'	
			
			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

				if tostring(transData.duplicate) ~= 'true' then
					outputVerseTrans = outputVerseTrans .. frame:expandTemplate{ 
						title = 'VersionContent', 
						args = { 
							class = 'mr-5' ,
							styles = 'min-width: 400px; max-width: 400px;' ,
							content = transData.english , 
							source = transData.source,
							tmButton =  tmButton,
							id = id .. '-translation',
							shorttitle = transData.shorttitle,
							order = order
						}
					}
				end

			end

			outputVerseTrans = outputVerseTrans .. '</div><div class="position-absolute" style="right: 0; top: 0; width: 15%; height: 100%; background: linear-gradient(to right, transparent, rgb(255 252 245)); max-width: 100px; margin-right: 1em;"></div><div class="position-absolute w-100 text-center opac-80" style="bottom: 10px; left: 0;"><i class="fa-sharp-duotone fa-solid fa-angle-left"></i><span class="opac-50"><span class="d-none d-md-inline"> shift + scroll /</span> swipe </span><i class="fa-sharp-duotone fa-solid fa-angle-right"></i></div></div></div>'

		end

	end

	return outputVerseTrans

end

return p