Jump to content

Module:Language screenshot filename

From mediawiki.org
Module documentation

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