Module:Language screenshot filename

From Bonkipedia
Revision as of 18:20, 12 November 2022 by ManfredoDo (talk | contribs) (1 revision imported: Module Import)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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