Module:Language screenshot filename: Difference between revisions

From Bonkipedia
[[mw:]]>Amire80
(simpler)
 
m (1 revision imported: Module Import)
 
(No difference)

Latest revision as of 18:20, 12 November 2022

This is a module for finding out the file name of a language screenshot in the VisualEditor user guide. In the future it may be used on other pages.


local this = {}

function this.getFilename(frame)
	scenario = frame.args['scenario']
	language = frame:expandTemplate{ title = 'CURRENTCONTENTLANGUAGE' }
	
	-- Get the appropriate Chinese variant.
	-- The translation is under /zh, but the screenshots are named with
	-- zh-hans and zh-hant.
	-- XXX: Until a way to handle variants in Lua is found,
	-- this is hardcoded as 'zh-hans'.
	languageParts = mw.text.split( language, '-' )
	if languageParts[1] == 'zh'
	then
		-- This doesn't actually work :(
		-- Commented out until better days.
		-- See https://bugzilla.wikimedia.org/show_bug.cgi?id=71366
		-- language = frame:preprocess('-{zh-hans:zh-hans;zh-hant:zh-hant;}-')
		
		language = 'zh-hans' -- XXX remove this line when variants are handled
	end

	filename = scenario .. '-' .. language .. '.png'
	fileTitle = mw.title.new(filename, 'Media')
	
	if not fileTitle.fileExists
	then
		filename = scenario .. '-en' .. '.png'
	end

	return 'File:' .. filename
end

return this