--  __  __           _       _        _                        _ _       _        
 -- |  \/  | ___   __| |_   _| | ___ _| |    __ _ _ __   __ _  | (_)_ __ | | _____ 
 -- | |\/| |/ _ \ / _` | | | | |/ _ (_) |   / _` | '_ \ / _` | | | | '_ \| |/ / __|
 -- | |  | | (_) | (_| | |_| | |  __/_| |__| (_| | | | | (_| | | | | | | |   <\__ \
 -- |_|  |_|\___/ \__,_|\__,_|_|\___(_)_____\__,_|_| |_|\__, | |_|_|_| |_|_|\_\___/
                                                     -- |___/                      
require('strict') -- used for debugging purposes as it detects cases of unintended global variables

local p = {}

function p.lang_links(frame)
	local title, subpage
	local output = {}
    local page    = frame.args[1]
    local max_num = tonumber(frame.args[2] or '70')
	if (page) then
		title = mw.title.new(page)
	else
		title = mw.title.getCurrentTitle()
		page  = title.basePageTitle
	end
	
	-- if /lang subpage found transclude it and we are done
	subpage = page .. '/lang'
	if mw.title.new(subpage).exists then
		return frame:expandTemplate{ title = subpage }
	end

	-- This list was generated by collecting all the sub-templates from 
	-- [[Category:Translated marker templates]] and [[Category:Translated license tags]], which hold
	-- subpages of 2400 templates, and counting how many sub-templates from each language we have. 
	-- Than we assigned a rank based on how many pages in a given language we had. 
	-- This list is sorted by the language code. Maximum rank is 118.
	local list = {'af/65', 'als/66', 'an/89', 'ar/15', 'arq/81', 'ast/84', 'az/54', 'bar/74', 
		'bcl/85', 'be/67', 'be-tarask/35', 'bg/41', 'bn/21', 'br/52', 'bs/79', 'ca/22', 'ce/103', 
		'cs/12', 'cy/56', 'da/37', 'dag/92', 'de/4', 'de-at/112', 'de-ch/113', 'de-formal/73', 
		'diq/64', 'el/43', 'en/1', 'en-ca/114', 'en-gb/88', 'eo/34', 'es/6', 'et/32', 'eu/48', 
		'fa/29', 'fi/23', 'fr/3', 'fy/72', 'ga/62', 'gl/30', 'gu/90', 'ha/107', 'he/40', 'hi/44', 
		'hr/39', 'hu/16', 'hy/45', 'id/28', 'io/71', 'is/97', 'it/10', 'ja/9', 'jv/98', 'ka/51', 
		'kk/77', 'km/94', 'kn/95', 'ko/26', 'ko-kp/99', 'ku/80', 'ky/82', 'lb/57', 'lt/55', 
		'lv/61', 'mg/75', 'min/116', 'mk/2', 'ml/18', 'mr/68', 'ms/46', 'mt/69', 'my/83', 'nb/47', 
		'nds/49', 'ne/59', 'nl/7', 'nn/60', 'ny/108', 'oc/93', 'or/100', 'pa/101', 'pl/13', 
		'ps/109', 'pt/8', 'pt-br/25', 'rm/104', 'ro/36', 'ru/5', 'scn/14', 'sd/110', 'se/86', 
		'sh/105', 'sk/50', 'sl/19', 'sq/58', 'sr/33', 'su/102', 'sv/24', 'sw/117', 'ta/70', 
		'te/118', 'test/115', 'th/38', 'tl/53', 'tr/27', 'tt/91', 'uk/11', 'ur/63', 'uz/111', 
		'vec/87', 'vi/42', 'yo/76', 'yue/106', 'zh/31', 'zh-cn/96', 'zh-hans/17', 'zh-hant/20', 'zh-tw/78'}
	local output = {}
	for _, key in pairs( list ) do
		local v = mw.text.split( key, '/' )
		local lang = v[1]
		local rank = tonumber(v[2])
		if rank<=max_num then
			subpage = page .. '/' .. lang
			if mw.title.new(subpage).exists then
				local lname = mw.language.fetchLanguageName( lang, lang )
				table.insert(output, '[[' .. subpage .. '|<bdi lang="'..lang..'">'.. lname..'</bdi>]]')
			elseif lang=='en' then -- some pages have English version in the main tenplate. Assume that is the case if /en subpage is missing.
				table.insert(output, '[[' .. page .. '|<bdi lang="en">English</bdi>]]')
			end
		end
	end 
	
	list = table.concat(output, '&nbsp;<b>∙</b>&#32;')
	return '<span class="plainlinks" style="font-size:small;line-height:1.4">'.. list.. '</span>'
end

return p
"https://si.wikibooks.org/w/index.php?title=Module:Lang_links&oldid=24252" වෙතින් සම්ප්‍රවේශනය කෙරිණි