Module:GetVerseTranslations: Difference between revisions

From Bodhicitta
((by SublimeText.Mediawiker))
((by SublimeText.Mediawiker))
Line 62: Line 62:
end
end


outputVerseTrans = outputVerseTrans .. '<div id="' .. sourceTm .. '-translations' .. '" class="toggleable col-12 col-md" style="min-width: 750px;"><div class="offwhite-bg shadow rounded p-3 mb-4 position-relative"><div class="h5 red-header pb-0 mb-1">' .. SourceLabels[sourceTm] .. ' - Translations</div><div class="d-flex flex-row overflow-auto pb-0 pr-5" style="scrollbar-width: none;">'
outputVerseTrans = outputVerseTrans .. '<div id="' .. sourceTm .. '-translations' .. '" class="toggleable col-12 col-md" style="min-width: 700px;"><div class="offwhite-bg shadow rounded p-3 mb-4 position-relative"><div class="h5 red-header pb-0 mb-1">' .. SourceLabels[sourceTm] .. ' - 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
for id, transData in pairs(transTbl) do

Revision as of 20:05, 4 April 2025

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 id="' .. sourceTm .. '-translations' .. '" class="toggleable col-12 col-md" style="min-width: 700px;"><div class="offwhite-bg shadow rounded p-3 mb-4 position-relative"><div class="h5 red-header pb-0 mb-1">' .. SourceLabels[sourceTm] .. ' - 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

				outputVerseTrans = outputVerseTrans .. frame:expandTemplate{ 
					title = 'VersionContent', 
					args = { 
						styles = 'min-width: 400px;' ,
						content = transData.english , 
						source = transData.source,
						tmButton =  tmButton,
						id = id .. '-translation',
						shorttitle = transData.shorttitle,
						order = order
					}
				}

			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));"></div><div class="w-100 text-center opac-80"><i class="fa-sharp-duotone fa-solid fa-angle-left"></i><span class="opac-50"> shift + scroll / swipe </span><i class="fa-sharp-duotone fa-solid fa-angle-right"></i></div></div></div>'

		end

	end

	return outputVerseTrans

end

return p