Module:Wt/ksh/Lang


Beijschpelle för Oprohve
{{#invoke:Wt/ksh/Lang|lookup_language|eng|adjective|1|def||m|Künning}}
{{#invoke:Wt/ksh/Lang|lookup_language|eng|adjective||ind|Dat|m|Künning}}  *
{{#invoke:Wt/ksh/Lang|lookup_language|eng|adjective||ind|Dat|f|Künnejen}}
{{#invoke:Wt/ksh/Lang|lookup_language|eng|adjective||ind|Vok|n|Auto}}
{{#invoke:Wt/ksh/Lang|lookup_language|azb|adjective||ind|Vok|p|Wööter|Key}}
{{#invoke:Wt/ksh/Lang|lookup_language|en|nahme}}
{{#invoke:Wt/ksh/Lang|lookup_language|nds-NL|nahme|3}}
{{#invoke:Wt/ksh/Lang|splitcode||language}}}
{{#invoke:Wt/ksh/Lang|splitcode|ksh|Script|lookup|verify}}
{{#invoke:Wt/ksh/Lang|splitcode|nds-NL|region}}
{{#invoke:Wt/ksh/Lang|splitcode|be-tarask|Orthogrfie|nä|verify}}
{{#invoke:Wt/ksh/Lang|splitcode|sr-Latn-resi|Variant||Veri}}
{{#invoke:Wt/ksh/Lang|lookup_orthography|nahme|(code)|(Lookup/Key/?}}
{{#invoke:Wt/ksh/Lang | lookup_orthography | nahme | code | Link
Key
söns
}}


{{ #invoke:Wt/ksh/Lang lookup_orthography code nahme Link
Key
söns
}}


{{ #invoke:Wt/ksh/Lang splitcode code Language
Script
Region
Area
Country
Orthography
Transliteration
Variants
1
2
3
4
5
6
7
8
9
Lookup
söns
Verify
söns
}}

-- Op Schprooche betrocke Projrammdeile - https://incubator.wikimedia.org/wikiModule:Wt/ksh/Lang

function lower(retval)
	return mw.ustring.lower(retval)
end

function upper(retval)
	return mw.ustring.upper(retval)
end

function lcfirst(retval)
	return lower(mw.ustring.sub(retval,1,1))..mw.ustring.sub(retval, 2)
end

function ucfirst(retval)
	return upper(mw.ustring.sub(retval,1,1))..mw.ustring.sub(retval, 2)
end

function tokeyL(retval) -- deaccented base characters only, lower case
	retval = mw.ustring.gsub(retval, '[ÐĐðđĦħ]', 'd')
	retval = mw.ustring.gsub(retval, '[ÐĐðđ]', 'h')
	retval = mw.ustring.gsub(retval, '[ı]', 'i')
	retval = mw.ustring.gsub(retval, '[ĸ]', 'k')
	retval = mw.ustring.gsub(retval, '[ĿŁŀł]', 'l')
	retval = mw.ustring.gsub(retval, '[Ŋʼnŋ]', 'n')
	retval = mw.ustring.gsub(retval, '[Øø]', 'o')
	retval = mw.ustring.gsub(retval, '[ẞßſ]', 's')
	retval = mw.ustring.gsub(retval, '[ÞŦþŧ]', 't')
	-- these go to digraphs:
	retval = mw.ustring.gsub(retval, '[Ææ]', 'ae')
	retval = mw.ustring.gsub(retval, '[IJij]', 'ij')
	retval = mw.ustring.gsub(retval, '[Œœ]', 'oe')
	return lower(mw.ustring.gsub(mw.ustring.toNFD(retval), '[^%w]+', ''))
end

function tokey(retval) -- deaccented base characters, all lower but 1st upper
	return ucfirst(tokeyL(retval))
end

function finalize(item, retval, mode, suffix) -- Link, Code, Key, All, Nothing
    mode = string.upper((mode.."L"):sub(1,1))
    suffix = suffix or ''
	if mode == "L" then
		retval = '[[Wt/ksh/'..item..'|'..retval..']]'..suffix
	elseif mode == "C" then
		retval = item..'<code>'..retval..'</code>'..suffix
	elseif mode == "K" then
		retval = tokey(retval..suffix)
	elseif mode == "A" then
		retval = item..retval..suffix
	end
	return retval
end

function finalice(txt0, code, txt1, fina)
	if fina == 'C' then
		return txt0..'<code>'..code..'</code>'..txt1
	end
	return txt0..code..txt1
end

local export = {}

-- Look up an item from the table of language data, and return it.
-- This function allows templates to access this data.
-- Returns an empty string if the item does not exist.
function export.lookup_language(frame)
    local languages = mw.loadData("Module:Wt/ksh/languages")
    local args = frame.args
    local lang = args[1] or error('Language code has not been specified. '..
    			'Please pass parameter 1 to the module invocation.')
  -- if 1 then return lang end
    local langinfo = languages[lang] or error("The language code \""
    												.. lang .. "\" is not valid.")
    -- The item that the caller wanted to look up
    local itemname = args[2] or error("The type of information to look up was not specified."
    								.." Please pass parameter 2 to the module invocation.")
    
    if itemname == "adjective" then
    	local item = langinfo['nahme'] or ""
    	local gram = langinfo['grama'] or ""
    	local indx = math.max(1, tonumber(args[3]) or 0)
    	if type(item) == "table" then
	    	item = item[indx] or "-keine Nahme-"
	    end
    	if type(gram) == "table" then
	    	gram = gram[indx] or ''
	    end
    	local separ = ' '
	    local grammar = ''
	    local retval = item
	    if gram == '-' then
	    	separ = '-'
	    else
		    grammar = string.lower((args[4].."d"):sub(1,1)..(args[5].."N"):sub(1,1)
		    												..(args[6].."n"):sub(1,1))
   	 		if grammar == 'inn' or grammar == 'ian' or grammar == 'ivn' or 
   	 		   grammar == 'dvn' or grammar == 'ivp' or grammar == 'dvp' then
				grammar = ''
			else
				grammar = 'e'
			end
			retval = item:lower()..grammar
		end
		retval = finalize( item, retval, args[8] or '' )
		return retval..separ..(args[7] or '')
    else
    	local item = langinfo[itemname] or ""
    	if type(item) == "table" then
	        return item[tonumber(args[3] or 1)] or ""
	    else
    	    return item or ""
    	end
    end
end	

function export.splitcodebcp47old(frame)
    local languages = mw.loadData("Module:Wt/ksh/languages")
--	local regions = mw.loadData("Module:Wt/ksh/regions")
	local scripts = mw.loadData("Module:Wt/ksh/scripts")
--	local ortographies = mw.loadData("Module:Wt/ksh/ortographies")
--	local variants = mw.loadData("Module:Wt/ksh/variants")
    local args = frame.args
	local tmpl = args[1]
	local code = args[2]
	local mode = args[3]
	local language = code:gsub('-.*$','')
	local area = ''
	local script = ''
	local orthography = ''
	local variant = ''
    local langinfo = languages[language] or 'error'
    if type(langinfo) == 'table' then
		if script == '' then
			script = langinfo['scripts'][1] or ''
		end
	end
--	local m_languages = mw.loadData("Module:Wt/ksh/languages")
--	return code
	return ( '{{'..tmpl..'|'..code..'|'..language..'|'..area..'|'..script..'|'
								..orthography..'|'..variant..'|'..mode..'}}' )
end

-- {{#invoke:Wt/ksh/Lang|splitcode|(code)|(Lang|Script|Reg=Area=Country|Orthog=Translit
--						|Variants|1|2|3|4|5|6|7|8|9)|(Lookup|?}|(Verify|?}
function export.splitcode(frame)
    local args = frame.args
	local code = args[1] or '' ; if code == '' then code = 'ksh' end
	local order = ((args[2] or '')..'L'):sub(1,1):upper() -- L, S, R/A O/T, V/1/2/3/4...
	local lookup = ((args[3] or '')..'L'):sub(1,1):upper() == 'L' -- lookup
	local verify = ((args[4] or '')..'V'):sub(1,1):upper() == 'V' -- verify
	local langinfo = 'error0'
	-- extlang code ?
		-- not yet
	-- language code ?
	local language = code:gsub('-.*$','')
	if lookup or verify then
	    local languages = mw.loadData("Module:Wt/ksh/languages")
		langinfo = languages[language] or 'error1'
		if verify and type(langinfo) ~= 'table' then
			return langinfo
		end
	end
	if order == "L" then
		return language
	end
	local rest = (code..'-'):gsub('^[^-]*-','') or ''
	local test = ''
	local vrip = 0
	while rest ~= '' do
		test = rest:gsub('-.*$','') or ''
	-- script code ?
		if test:match('^[A-Z][a-z][a-z][a-z]$') then
			if order == "S" then
				if verify then
					local scripts = mw.loadData("Module:Wt/ksh/scripts") 	
					local scriptinfo = scripts[test] or 'errorS'
					if type(scriptinfo) ~= 'table' then
						test = scriptinfo
					end
				end
				return test
			end
	-- country code or region code or area code ?
		elseif test:match('^[A-Z][A-Z]$') or test:match('^[0-9][0-9][0-9]$') then
			if order == "C" or order == "R" or order == "A" then
			    if verify then
					local regions = mw.loadData("Module:Wt/ksh/regions") 	
					local regioninfo = regions[test] or 'errorA'
					if type(regioninfo) ~= 'table' then
						test = regioninfo
					end
				end
				return test
			end
	-- orthography code ?
		elseif (order == "O" or order == "T" )
			and ( test == '1901' or test == '1959acad' or test == '1994'
								or test == '1996' or test == 'baku1926'
				or test == 'hognorsk' or test == 'kkcor' or test == 'kscor'
								or test == 'luna1918' or test == 'petr1708'
				or test == 'tarask' or test == 'uccor' or test == 'ucrcor'
				-- the rest are deprecated or not in the standard:
				or test == 'bok' or test == 'nyn' or test == 'xakad' ) then
--		    if verify then
--				local orthographies = mw.loadData("Module:Wt/ksh/orthographies") 	
--				local orthographyinfo = orthographies[test] or 'errorO'
--				if type(orthographyinfo) ~= 'table' then
--					test = orthographyinfo
--				end
				return test
	-- variant codes (all) ?
		elseif order == "V" then
			return rest:sub(1,-2)
	-- variant codes 1-9 ?
		elseif order:match('^[1-9]$') and test:match('^[A-Za-z0-9]+$') then
			vrip = 1 + vrip
			if ( order - vrip ) == 0 then
			    if verify then
--					local variants = mw.loadData("Module:Wt/ksh/variants")
--					local variantinfo = variants[test] or 'error'
--					if type(variantinfo) ~= 'table' then
--						test = variantinfo
--					end
				end 	
				return test
			end
		end
		rest = rest:gsub('^[^-]*-','') or ''
--		if trip >= 2 then return '('..test..'||'..rest..')' end
--	if 1 then return '?' end
	end
	if lookup then
		if order == "S" then
			return langinfo['scripts'][1] or 'error(S)' -- default script
		end
		if order == "C" or order == "R" or order == "A" then
--			return langinfo['regions'][1] or '001' -- default region is 'world'
		end
		if order == "O" or order == "T" then
			local info = langinfo['orthographies'] or ''
			if type(info) == 'table' then
				return info[1] or '' -- default orthography is none, that is standard
			else	
				return info -- default orthography is none, that is standard
			end
		end
		if order == "V" then
--			return langinfo['variants'][1] or '' -- default variant is none, or standard
		end
	end
	return ''
end

-- {{#invoke:Wt/ksh/Lang|lookup_orthography|nahme|(code)|(Lookup|Key|?}}
function export.lookup_orthography(frame)
	local orthographies = mw.loadData("Module:Wt/ksh/orthographies")
	local args = frame.args
	local code = args[1] or error('Orthography code not specified. '..
						'Please pass parameter 1 to the module invocation.')
	local info = orthographies[code] or error("The orthography code \""
												.. code .. "\" is not valid.")
	local retval = args[2] or error("The type of information to look up was not specified. "..
									"Please pass parameter 2 to the module invocation.")
	retval = info[retval]
	return finalize( retval, retval, args[3] or '' )
end


function adjective(item, grama, grammar, final, word)
--		grammar = DNN (def/ind, Nom/Dat/Acc/Voc, Masc/Fem/Neut/Plur) final=L/K/N
--		grammar = string.lower((args[4].."d"):sub(1,1)
--								..(args[5].."N"):sub(1,1)..(args[6].."n"):sub(1,1))
	local separ = ' '
	local retval = item
	if grama:sub(-1) == '-' then
		separ = '-'
		retval = retval:gsub(' ', '-')
		grammar = ''
	else
		if grama:sub(-1) == 'L' then
			item = item..'lesch'
		end
		if grammar == 'inn' or grammar == 'ian' or grammar == 'ivn' or
					grammar == 'dvn' or grammar == 'ivp' or grammar == 'dvp' then
			grammar = ''
		else
			grammar = 'e'
		end
		retval = lower(item)..grammar
	end
	if final == "K" then
		separ = ''
		word = tokeyL(word)
	end
	retval = finalize( item, retval, final )
	return retval..separ..word
end

function Sjn_Wm_Schproochek(code, fina)
	return finalize('Wööter mem Schprohcheköözel ', code, fina)
end

function Sjn_Wm_Schreffk(code, fina)
	return finalize('Wööter mem Schreffköözel ', code, fina)
end

function Sjn_Wm_Ottojrafihk(code, fina)
	if code:len() == 0 then
		return 'Wööter der ohne Ottojrafihköözel'
	end
	return finalize('Wööter mem Ottojrafihköözel ', code, fina)
end

--function Sjn_Wen_Schprooch(nahme, grama, region, dialect, fina)
function Sjn_Wen_Schprooch(nahme, grama, fina)
	return adjective(nahme, grama, 'dnp', fina, 'Wööter')
end

function Sjn_Wen_Schreff(nahme, grama, fina)
	local g1 = grama:sub(1,1)
	if g1 == 'x' then
		g1 = ' jeschrevve en '
	elseif g1 == 'e' then
		g1 = ' en ene '
	else
		g1 = ' en de '
	end
	return 'Wööter '..g1..finalize(nahme, nahme, fina)
end

function Sjn_Wen_Ottojrafih(nahme, grama, fina)
	if nahme:len(0) == 0 then
		nahme = 'jewöhnlejje Ottojrafih'
	 else
		nahme = finalize( nahme, nahme, fina)
	end
	return "Wööter en de "..nahme
end

function wordcatgroup(list, code, nahmefun, nahmefina, codefun, codefina, cal)
	local cal = cal or ( '['..'[Category:Wt/ksh/' )
	local car = ']]'
	local retval = ''
	if code ~= '' then
		local items = mw.loadData('Module:Wt/ksh/'..list) or ''
		local entry = ''
		local nahme = ''
		local grama = ''
		local n = ''
		local g = ''
		if items ~= '' then
			entry = items[code] or ''
			if entry ~= '' then
				nahme = entry['nahme'] or ''
				n = nahme
				if nahme ~= '' then
					grama = entry['grama'] or ''
					g = grama
					if type(nahme) == 'table' then
						for indx in pairs(nahme) do
							n = nahme[indx]
							if type(grama) == 'table' then
								g = grama[indx]
							end
							if nahmefun then
								retval = retval..cal
										..ucfirst(nahmefun(n, g, nahmefina))..car
							end
						end
					elseif nahmefun then
						retval = retval..cal
									..ucfirst(nahmefun(n, g, nahmefina))..car
					end
				end
			end
		end
	 elseif nahmefun then
		retval = retval..cal..ucfirst(nahmefun('', '', nahmefina))..car
	end
	if codefun then
		retval = retval..cal..codefun(code, codefina)..car
	end
	return retval
end

function export.wordcats(frame)
--	local cat = '[:Category:Wt/ksh/'
	local cat = ' ['..'[:Category:Wt/ksh/'
	local languages = mw.loadData("Module:Wt/ksh/languages")
	local orthographies = mw.loadData("Module:Wt/ksh/orthographies") 
	local retval = ''
	local args = frame.args
    local code = args[1] or ''
    if code == '' then
    	code = 'ksh'
    end
	local lang = code:gsub('-.*$', '')
	local scrp = ''
	local regi = ''
	local orth = ''
	local tran = ''
	local vari = {}
	local rest = (code..'-'):gsub('^[^-]*-','') or ''
	if rest ~= '' then
		local test = ''
		local vrip = 0
		while rest ~= '' do
			test = rest:gsub('-.*$','') or ''
			-- script code ?
			if test:match('^[A-Z][a-z][a-z][a-z]$') then
				scrp = test
			-- country code or region code or area code ?
			elseif test:match('^[A-Z][A-Z]$') or test:match('^[0-9][0-9][0-9]$') then
				regi = test
			-- orthography code ?
			elseif orthographies[test] then
				orth = test
			elseif test ~= '' then
				vari[vrip] = test
			end
			rest = rest:gsub('^[^-]*-','') or ''
		end
	end
	
	local item = languages[code] or ''
	if item == '' then
		item = languages[lang] or ''
	end
-- dat es noch nit jenohch!

	if scrp == '' and item ~= '' then
		scrp = item['scripts'] or ''
		if type(scrp) == 'table' then
			scrp = scrp[1] or ''
		end
	end
	retval = retval..wordcatgroup('scripts', scrp,
										Sjn_Wen_Schreff, 'N',
										Sjn_Wm_Schreffk, 'A', cat)
	retval = retval..wordcatgroup('languages', lang,
										Sjn_Wen_Schprooch, 'N',
										Sjn_Wm_Schproochek, 'A', cat)
	if orth == '' and item ~= '' then
		orth = item['orthographies'] or ''
		if type(orth) == 'table' then
			orth = orth[1] or ''
		end
	end
	retval = retval..wordcatgroup('orthographies', orth,
										Sjn_Wen_Ottojrafih, 'N',
										Sjn_Wm_Ottojrafihk, 'A', cat)
-- Wööter en de jewöhnlejje Ottojrafih !
	if regi == '' and item ~= '' then
		regi = item['regions'] or ''
		if type(regi) == 'table' then
			regi = regi[1] or ''
		end
	end
	if regi ~= '' then
		retval = retval..wordcatgroup('regions', regi,
										Sjn_Wen_Rejohn, 'N',
										Sjn_Wm_Rejohn, 'A', cat)
	end
-- Wööter en de Wält?
	if tran == '' and item ~= '' then
		tran = item['transliterations'] or ''
		if type(tran) == 'table' then
			tran = tran[1] or ''
		end
	end
	if tran ~= '' then
		retval = retval..wordcatgroup('transliterations', tran,
										Sjn_Wen_Translit, 'N',
										Sjn_Wm_Translit, 'A', cat)
	end
-- Wööter der ohne Translit?
	if #vari == 0 and item ~= '' then
		vari = item['variants'] or ''
		if type(vari) == 'table' then
			vari = vari[1] or ''
		end
	end
	if vari ~= '' then
		retval = retval..wordcatgroup('variants', vari,
										Sjn_Wen_Varejante, 'N',
										Sjn_Wm_Varejant, 'A', cat)
	else
-- Wööter der ohne Varejante?
	end
	return retval
end

function langtestline(key, idx1, idx2, nahme, grama)
	return key..': '..idx1..' '..idx2..': '..nahme..' '..grama..' &nbsp;—&nbsp; '
					..adjective(nahme, grama, 'dnp', 'L', 'Wööter')..' &nbsp;—&nbsp; '
--					..adjective(nahme, grama, 'dnp', 'N', '')..' &nbsp;—&nbsp; '
					..adjective(nahme, grama, 'dnp', 'K', 'wooter')
					..'<br />'
end
						
function export.langtest(frame)
	local args = frame.args
	local nahme = ''
	local grama = ''
	local retval = '\n== Schprooche ==\n'
	local languages = mw.loadData("Module:Wt/ksh/languages")
	for key, entry in pairs(languages) do
		nahme = entry['nahme'] or ''
		if nahme ~= '' then
			retval = retval..'\n#'
			grama = entry['grama'] or 'S'
			if type(nahme) == 'table' then
				for indx in pairs(nahme) do
					if type(grama) == 'table' then
						local g = grama[indx] or 'fählt'
						retval = retval..langtestline(key, indx, indx, nahme[indx], g)
					else
						retval = retval..langtestline(key, indx, 0, nahme[indx], grama)
					end
				end
			else
				retval = retval..langtestline(key, 0, 0, nahme, grama)	
			end
		end
	end
	return retval
end

local regiograma = {
	[''] = '',
	['f'] = 'de ',
	['m'] = 'der ',
	['n'] = 'et ',
	['p'] = 'de ',
	}

function export.regiotest(frame)
--	local args = frame.args
	local c = 0
	local colle = {}
	local items = mw.loadData("Module:Wt/ksh/regions")
-- items = {}
	for key in pairs(items) do
		c = 1 + c
		colle[c] = key
	end
	local retval = '\n== Rejohne ==\n'
	local nahme = ''
	local grama = ''
	local n = ''
	local g = ''
	local d = 1 -- count one too many making encoding easier after loop.
	table.sort(colle)
	for i = 1 , #colle do
		key = colle[i]
		entry = items[key]
		nahme = entry['nahme'] or ''
		if nahme ~= '' then
			d = 1 + d
			n = nahme
			retval = retval..'\n#'
			grama = entry['grama'] or ''
			g = grama
			if type(nahme) == 'table' then
				for indx in pairs(nahme) do
					n = nahme[indx] or ''
					if type(grama) == 'table' then
						g = grama[indx] or ''
					end
					retval = retval..' <code>'..key..'</code> &nbsp;—&nbsp; '
							..(regiograma[g] or missing)..finalize( n, n, 'L' )
							..'<br />'
				end
			else
				retval = retval..' <code>'..key..'</code> &nbsp;—&nbsp; '
							..(regiograma[g] or missing)..finalize( n, n, 'L' )
			end
		end
	end
	if d > c then
		d = 'es keine'
	elseif d == c then
		d = 'es eine'
	else
		d = 'sinner '..(c - d + 1)
	end
	return retval..'\n\nEn dä Leß sin ävver '..c..' Enndrääsch, alsu '
											..d..' der ohne ene Nahme.'
end

function techlistsummary( c, d, k )
	if d > c then
		if k then
			d = 'es keine'
		else
			return ''
		end
	elseif d == c then
		d = 'es eine'
	else
		d = 'sinner '..(c - d + 1)
	end
	retval = '\nEn dä Leß sin ävver '..c..' Enndrääsch, alsu '
										..d..' der ohne ene Nahme.'
	return retval
end

function langtechlistcmp( k1, k2)
	return k1:len() < k2:len() or ( k1:len() == k2:len() and k1 < k2 )
end

function langtechlistline( idx1, idx2, key, n, g , c, d, k )
	return idx1..' '..idx2..': <code>'..key..'</code>: '
				..n..' <b>'..g..'</b> &nbsp;—&nbsp; '
				..adjective(n, g, 'dnp', 'L', 'Wööter')..' &nbsp;—&nbsp; '
--				..adjective(n, g, 'dnp', 'N', '')..' &nbsp;—&nbsp; '
				..adjective(n, g, 'dnp', 'K', 'wooter')
				..'<br />'
end

function scriptechlistline( idx1, idx2, key, n, g , c, d, k )
	return ' <code>'..key..'</code> &nbsp;—&nbsp; '
						..finalize( n, n, 'L' )
						..'<br />'
end

function regiotechlistline( idx1, idx2, key, n, g , c, d, k )
	return ' <code>'..key..'</code> &nbsp;—&nbsp; '
						..(regiograma[g] or missing)..finalize( n, n, 'L' )
						..'<br />'
end

function orthotechlistline( idx1, idx2, key, n, g , c, d, k )
	return ' <code>'..key..'</code> &nbsp;—&nbsp; '
						..finalize( n, n, 'L' )..'<br />'
end

function translitechlistline( idx1, idx2, key, n, g , c, d, k )
	return ' <code>'..key..'</code> &nbsp;—&nbsp; '
						..finalize( n, n, 'L' )..'<br />'
end

function variantechlistline( idx1, idx2, key, n, g , c, d, k )
	return ' <code>'..key..'</code> &nbsp;—&nbsp; '
						..finalize( n, n, 'L' )..'<br />'
end

function techlist( list, head, sortfunc, linefunc, summaryfunc, k )
	if summaryfunc == nil then
		summaryfunc = techlistsummary
	end
	local c = 0
	local colle = {}
	local items = mw.loadData( 'Module:Wt/ksh/'..list )
	for key in pairs(items) do
		c = 1 + c
		colle[c] = key
	end
	local retval = '\n== '..head..' ==\n'
	local key
	local nahme
	local grama
	local n
	local g
	local x
	local d = 1 -- count one too many making encoding easier after loop.
	table.sort(colle, sortfunc)
	for i = 1 , #colle do
		key = colle[i]
		entry = items[key]
		nahme = entry['nahme'] or ''
		if nahme ~= '' then
			d = 1 + d
			retval = retval..'\n#'
			grama = entry['grama'] or ''
			g = grama
			x = 0
			if type(nahme) == 'table' then
				for indx in pairs(nahme) do
					n = nahme[indx] or ''
					if type(grama) == 'table' then
						g = grama[indx] or ''
						x = indx
					end
					retval = retval..linefunc( indx, x, key, n, g , c, d, k )
				end
			else
				n = nahme
				retval = retval..linefunc( 0, 0, key, n, g , c, d, k )
			end
		end
	end
	return retval..summaryfunc( c, d, k )
end

function export.langtechlist( frame )
	return techlist( 'languages', 'Schprohche', langtechlistcmp, langtechlistline)
end

function export.scriptechlist( frame )
	return techlist( 'scripts', 'Schreffte', nil, scriptechlistline)
end

function export.regiotechlist( frame )
	return techlist( 'regions', 'Rejohne', nil, regiotechlistline)
end

function export.orthotechlist( frame )
	return techlist( 'orthographies', 'Ottojrafihje', nil, orthotechlistline)
end

function export.variantechlist( frame )
	return techlist( 'variants', 'Varejante', nil, variantechlistline)
end

function export.translitechlist( frame )
	return techlist( 'transliterations', 'Ömschreffte', nil, translitechlistline)
end

function export.tokey( frame )
	return tokeyL( frame.args[1])
end

function variantestcollect( colle, lang, key )
	if lang == '' then
		lang = 'mul'
	end
	colle[lang] = ''
	colle[lang..'-'..key] = ''
end

function export.variantest(frame)
--	local args = frame.args
	local todo = {}
		todo['orthographies'] = 'O'
		todo['transliterations'] = 'Ö'
		todo['variants'] = 'D/V'
	local items
	local colle = {}
	local sorte = {}
	local count = 0
	local lang
	local retval = '== Dijalägde, Varejante, Ömschreffte, Ottojrafihje =='
	for list in pairs( todo ) do
		items = mw.loadData('Module:Wt/ksh/'..list) or ''
		if items ~= '' then
			for key, entry in pairs(items) do
				lang = entry['lang'] or ''
				if type(lang) == 'table' then
					for ind, pref in pairs(lang) do
						variantestcollect( colle, pref, key )
					end
				else
					variantestcollect( colle, lang, key )
				end
			end
		end
	end
	for lang in pairs(colle) do
		count = 1 + count
		sorte[count] = lang
	end
	table.sort(sorte)
	for index = 1, #sorte do
		lang = sorte[index]
		retval = retval..'\n#<code>'..lang..':</code> &nbsp;—&nbsp; '
	end
	return retval
end

function gramatestcollect( grama, nahme, colle, count )
	colle[grama] = nahme
	count[grama] = 1 + (count[grama] or 0)
end

function export.gramatest(frame)
--	local args = frame.args
	local todo = {}
		todo['languages'] = 'Schprohche'
		todo['scripts'] = 'Schreffte'
		todo['regions'] = 'Rejohne'
		todo['orthographies'] = 'Ottojrafihje'
		todo['transliterations'] = 'Ömschreffte'
		todo['variants'] = 'Varejante'
	local miss = ' <i>fählt</i> '
	local items = ''
	local colle = {}
	local count = {}
	local sorte = {}
	local nahme = ''
	local grama = ''
	local retval = ''
	for list, head in pairs( todo ) do
		items = mw.loadData('Module:Wt/ksh/'..list) or ''
		if items ~= '' then
			for key, entry in pairs(items) do
				nahme = entry['nahme'] or ''
				if nahme ~= '' then
					grama = entry['grama'] or miss
					if type(nahme) == 'table' then
						for indx in pairs(nahme) do
							if type(grama) == 'table' then
								gramatestcollect( grama[indx] or miss,
											nahme[indx], colle, count )
							else
								gramatestcollect( grama,
											nahme[indx], colle, count )
							end
						end
					else
						gramatestcollect( grama, nahme, colle, count )
					end
				end
			end
			retval = retval..'\n== <code>grama</code> för '..head..' ==\n'
			for grama in pairs(count) do
				table.insert( sorte, grama )
			end
			table.sort(sorte)
			for index = 1, #sorte do
				grama = sorte[index]
				nahme = colle[grama]
				retval = retval..'\n#'..grama..' &nbsp;—&nbsp; '..nahme
								..' &nbsp;<small>('..count[grama]..'×)</small>'
			end
		end
		colle = {}
		count = {}
		sorte = {}
	end
	return retval
end

return export