Modul:înterwîkî-çêke

Ji Wîkîferhengê
--Ev modul li gorî navê kategoriyekê lînka înterwîkiyê lê zêde dike. Bi şablona {{înterwîkî-çêke}} tê bikaranîn bi vî awayî {{subst:înterwîkî-çêke}}
-- [[Bikarhêner:Balyozxane/addAutoCat.js]] vê modulê bi kar tîne ji bo lêzêdekirina înterwîkiyê. 
local k = {}
local b = require("Modul:bingeh")
local bibine = mw.ustring.find

local daneTerms = {
		{"compound terms", ".*pêkhatî$"},
		{"multiword terms", ".*hevedudanî$"},
}


local daneTermsBi = {
		{"terms with usage examples", "Mînak.*"},
		{"terms with audio links", "Deng bi.*"},
		{"terms with IPA pronunciation", "Bilêvkirina IPAyê.*"},
		{"terms with unknown etymologies", "Etîmolojî nayê zanîn.*"},
		{"terms with unknown homophones", "Hevdeng.*"},
		{"terms with unknown quotations", "Jêgirtin.*"},
		{"terms by etymology", "Etîmolojî.*"},
		{"doublets", "Cotreh.*"},
		{"internationalisms", "Navneteweyîtî.*"},
		{"clippings", "Qusandin.*"},
		{"calques", "Wergerandinên yekser.*"},
		{"term requests", "Daxwazên peyvan.*"},
		{"compound terms", ".*pêkhatî.*"},
		{"dialectal terms", "Devokî.*"},
		{"metonyms", "Metonîm.*"},
}

local daneMane = {
		{"derogatory terms", ".*biçûkxister.*"},
		{"humorous terms", ".*henekî.*"},
		{"formal terms", ".*fermî.*"},
		{"colloquialisms", ".*kolankî.*"},

}

local daneDawi = {
		{"Requests concerning", "Gotarên bi şaşî û kêmasî.*"},

}

local daneKodDawi = {
		{"Terms with redundant transliterations", "Transliterasyona nepêwîst.*"},

}
local daneZterms = {
		{"Requests for native script for", "Daxwazên skrîpta peyvê.*"},

}
local function getObj(name, family)
	if not family then
		return require("Modul:ziman").getByCanonicalName(name)
			or require("Module:etymology languages").getByCanonicalName(name)
	else
		return require("Module:families").getByCanonicalName(name)
	end
end

function k.ziman_en(kod)
	Enziman = mw.getCurrentFrame():expandTemplate{title = "navê zimanî/en", args = {kod}}
	return Enziman
end

function k.get_rezimani(label)
	local m_labeldataRezimani = mw.loadData("Modul:dara kategoriyan/ferhengokkatbike/dane/rêzimanî")
	
	if m_labeldataRezimani.interwiki[label] then
		return m_labeldataRezimani.interwiki[label]
	else
		return nil
	end
end

function k.get_label_info(label)
	local m_labeldata = mw.loadData("Modul:dara kategoriyan/ferhengokkatbike/dane/ferhengok")
	
	if m_labeldata.interwiki[label] then
		return m_labeldata.interwiki[label]
	else
		return nil
	end
end

local function splitLabelLang(rupel)
	local getByCanonicalName = require("Modul:ziman").getByCanonicalName
	local canonicalName
	local lang
	
	-- Progressively add another word to the potential canonical name until it
	-- matches an actual canonical name.
	local words = mw.text.split(rupel, " ")
	for i = #words - 1, 1, -1 do
		canonicalName = table.concat(words, " ", 1, i)
		lang = getByCanonicalName(canonicalName)
		if lang then
			break
		end
	end
	
	local label = lang and rupel:sub(#canonicalName + 2)
		or rupel
	
	return label, lang
end
function k.interwiki_ceke(rupel)
-- terms 
	for _, terms_regex in ipairs(daneTerms) do
		local terms, regex = unpack(terms_regex)
		if bibine(rupel, regex) then
						
			local ziman = rupel:match("Peyvên (.+) yên.+")
			local kod = require("Module:ziman").getByCanonicalName(ziman)
				if kod then
					kod = kod:getCode()
					Enziman = k.ziman_en(kod)
					return ''.. Enziman ..' '.. terms .. '' 
				else
					return ''.. b.ucfirst(terms) .. ' by language' 
				
				end	
		end	
	end



	-- [[:Kategorî:Hemû ziman
	local langName = rupel:match("^(.+)")
	-- Use the entire category name if it doesn't end in "language", to handle
	-- cases where "language" is part of the name, e.g. ASL.
	local ziman = b.lcfirst(langName)
	local lang = require("Module:ziman").getByCanonicalName(ziman) or require("Module:ziman").getByCanonicalName(rupel)
	
	if not lang then
		local lang2 = require("Module:ziman").getByName(langName)
		if lang2 then
			error('"' .. langName .. '" is not a valid canonical name. Use "' .. lang2:getCanonicalName() .. '" instead.')
		end
	else
		lang = lang:getCode()
		Enziman = k.ziman_en(lang)
		return '' .. Enziman.. ' language'
	end

	--[[:Kategorî:Zimanên kreyolî yan pîdgînî]]
	if rupel:find("^[zZ]imanên kreyolî yan pîdgînî li ser bingeha ") then
	
		local kreyoliName = rupel:match("^[zZ]imanên kreyolî yan pîdgînî li ser bingeha (.+)$")
		local lang = require("Module:ziman").getByCanonicalName(kreyoliName)
			lang = lang:getCode()
			Enziman = k.ziman_en(lang)
			
		return '' .. Enziman .. '-based creole or pidgin languages'
	end

	--[[:Kategorî:Ziman li gorî malbatan]]
	if rupel:find("^[zZ]imanên") then
	
		local familyName = rupel:match("^[zZ]imanên (.+)$")
		
		local family = require("Module:families").getByCanonicalName(familyName) or
			require("Module:families").getByCanonicalName(mw.ustring.lower(familyName))
		local malbat = family:getCode()
		local malbatKod = require("Module:families").getByCodeEn(malbat)
		return '' .. malbatKod:getCanonicalName() .. ' languages'
	end



	-- [[Modul:dara kategoriyan/rehkatbike]]
	local label, lang = splitLabelLang(rupel)
	
	if label:find("^.+ ji rehê .") then
		local ziman, after = label:match("Peyvên (.+) ji rehê (.+)$")
		if ziman then
			lang = require("Module:ziman").getByCanonicalName(ziman) 
		end
					local term, id
		
		if after:find(". %([^()]+%)$") then
			term, id = after:match("^(.+) %(([^()]+)%)$")
		else
			term = after
		end
		lang = lang:getCode()
		Enziman = k.ziman_en(lang)
		return '' .. Enziman .. ' terms belonging to the root ' .. term .. ''
	end


	local label, lang = splitLabelLang(rupel)

	for _, affixtype in ipairs({"circumfix", "rehan", "navgir", "pêşgir", "paşgir"}) do
		if label:find("^Peyvên.+ li gorî ".. affixtype ..'an') then
			local ziman = label:match("Peyvên (.+) yên li gorî " .. affixtype .. "an")
			if ziman then
				lang = require("Module:ziman").getByCanonicalName(ziman) 
							
				if affixtype == "navgir" then 
					affixtype = "interfix"
				elseif 	affixtype == "paşgir" then
					affixtype = "suffix"
				elseif 	affixtype == "pêşgir" then
					affixtype = "prefix"		
				elseif 	affixtype == "reh" then
					affixtype = "root"				
				end
				lang = lang:getCode()
				Enziman = k.ziman_en(lang)				
				return '' .. Enziman  .. ' terms by ' .. affixtype ..''
			end
		end
	end		

	-- [[Modul:dara kategoriyan/qertafkatbike]]
	local label, lang = splitLabelLang(rupel)
	
	for _, affixtype in ipairs({"circumfix", "infix", "navgir", "pêşgir", "paşgir"}) do
		if label:find("^.+ bi " .. affixtype .. "a .") then
			local ziman, after = label:match("Peyvên (.+) bi " .. affixtype .. "a (.+)$")
			if ziman then
				lang = require("Module:ziman").getByCanonicalName(ziman) 
				lang = lang:getCode()
				enZiman = k.ziman_en(lang)
			end
			
			local term, id
			if after:find(". %([^()]+%)$") then
				term, id = after:match("^(.+) %(([^()]+)%)$")
			else
				term = after
			end
			
			if affixtype == "navgir" then 
				affixtype = "interfix"
			elseif 	affixtype == "paşgir" then
				affixtype = "suffix"
			elseif 	affixtype == "pêşgir" then
				affixtype = "prefix"				
			end
		
			return '' .. enZiman  .. ' terms '.. affixtype .. 'ed with ' .. term .. ''
		--return {title = affixtype .. "katbike", args = {lang:getCode(), term, pos = pos, id = id}}
		end
		
		local label, lang = splitLabelLang(rupel)
	
		if label:find("^Peyvên.+ li gorî rehan") then
			local ziman = label:match("Peyvên (.+) yên li gorî rehan")
			if ziman then
				lang = require("Module:ziman").getByCanonicalName(ziman) 
				lang = lang:getCode()
				Enziman = k.ziman_en(lang)	
				return '' .. Enziman  .. ' terms by root'

			end
		end
	end


	local label, lang = splitLabelLang(rupel)

	for _, etimtype in ipairs({"deynkirî ji", "mîrasmayî ji", "ji"}) do	
		if  label:find("(.+) y?ê?n? ?".. etimtype .. " zimanên din") then
	
			local ziman = label:match("Peyvên (.+) y?ê?n? ?".. etimtype .. " zimanên din$")
			
			if ziman then
				ziman = getObj(ziman)
			
				if etimtype == "deynkirî ji" then 
					etimtype = "borrowed"
				elseif 	etimtype == "mîrasmayî ji" then
					etimtype = "inherited"
				else 
					etimtype = "derived "
						
				end
								
				lang = ziman
				lang = mw.getCurrentFrame():expandTemplate{title = "navê zimanî/en", args = {lang:getCode()}}

				if etimtype == "derived " then 
					return ''.. lang .. ' terms derived from other languages'
				else 
					return ''.. lang .. " " .. etimtype .. ' terms'
				end
			end
		end
	end
	
-- [[Modul:dara kategoriyan/deynkirîkatbike]]
	local label, lang = splitLabelLang(rupel)

	for _, etimtype in ipairs({"deynkirî", "mîrasmayî", "wergerandina yekser"}) do	
		if  label:find("(.+) ".. etimtype .. " ji .") then
	
			local navewergir, sourcename = label:match("Peyvên (.+) yên ".. etimtype .. " ji (.+)$")
			local wergir
			local source
			
			
			if navewergir then
				wergir = getObj(navewergir)

				if sourcename:find("^zimanên ") then
					sourcename = sourcename:gsub("^zimanên ", "")
					source = getObj(sourcename, true)
				else
					source = getObj(sourcename)
				end
			
				if etimtype == "deynkirî" then 
					etimtype = "borrowed"
				elseif 	etimtype == "mîrasmayî" then
					etimtype = "inherited"
				elseif 	etimtype == "wergerandina yekser" then
					etimtype = "calqued"			
--[[
				elseif 	affixtype == "lihevanîna dengî wateyî" then
					affixtype = "phono-semantic matchings"			
				elseif 	affixtype == "wergirtina wateyê" then
					affixtype = "semantic loans"	
--]]					
				end
								
				lang = wergir
				lang = mw.getCurrentFrame():expandTemplate{title = "navê zimanî/en", args = {lang:getCode()}}
				source = mw.getCurrentFrame():expandTemplate{title = "navê zimanî/en", args = {source:getCode()}}
		
				return ''.. lang .. ' terms '.. etimtype .. ' from ' .. source .. ''
		
			elseif not navewergir then 
				local sourcename = label:match("Peyvên ".. etimtype .. " ji (.+)$")
				if sourcename:find("^zimanên ") then
					sourcename = sourcename:gsub("^zimanên ", "")
					source = getObj(sourcename, true)
					source = source:getCode()
					source = require("Module:families").getByCodeEn(source)
					source = source:getCanonicalName() .. " languages"			
					
				else
					source = getObj(sourcename)
					source = mw.getCurrentFrame():expandTemplate{title = "navê zimanî/en", args = {source:getCode()}}
				end		

			
				if etimtype == "deynkirî" then 
					etimtype = "borrowed"
				elseif 	etimtype == "mîrasmayî" then
					etimtype = "inherited"
				elseif 	etimtype == "wergerandina yekser" then
					etimtype = "calqued"			
--[[
				elseif 	affixtype == "lihevanîna dengî wateyî" then
					affixtype = "phono-semantic matchings"			
				elseif 	affixtype == "wergirtina wateyê" then
					affixtype = "semantic loans"	
--]]					
				end
						
				return 'Terms '.. etimtype .. ' from ' .. source .. ''
				
			end
		end
	end
-- [[Modul:dara kategoriyan/jikatbike]]
local label, lang = splitLabelLang(rupel)
	
	if label:find("(.+) ji .") then
		
		local navewergir, sourcename = label:match("Peyvên (.+) ji (.+)$")
		local wergir
		local source
	
		if navewergir then
			wergir = getObj(navewergir)
	
			if sourcename:find("^zimanên ") then
				sourcename = sourcename:gsub("^zimanên ", "")
				source = getObj(sourcename, true)
				source = source:getCode()
				source = require("Module:families").getByCodeEn(source)
				source = source:getCanonicalName() .. " languages"			
			else
				source = getObj(sourcename)
				source = mw.getCurrentFrame():expandTemplate{title = "navê zimanî/en", args = {source:getCode()}}
			end
			
			lang = wergir
			lang = mw.getCurrentFrame():expandTemplate{title = "navê zimanî/en", args = {lang:getCode()}}
	
			return ''.. lang .. ' terms derived from ' .. source .. ''
	
		elseif not navewergir then 
			local sourcename = label:match("Peyvên ji (.+)$")
			if sourcename:find("^zimanên ") then
				sourcename = sourcename:gsub("^zimanên ", "")
				source = getObj(sourcename, true)
				source = source:getCode()
				source = require("Module:families").getByCodeEn(source)
				source = source:getCanonicalName() .. " languages"			
			else
				source = getObj(sourcename)
			source = mw.getCurrentFrame():expandTemplate{title = "navê zimanî/en", args = {source:getCode()}}
			end		
	
			return 'Terms derived from ' .. source .. ''
			
		end	
	end

	
	--[[Modul:dara kategoriyan/ferhengokkatbike/dane/mane]]
	--[[:Kategorî:Maneyên biçûkxister bi îngilîzî]]
	for _, mane_regex in ipairs(daneMane) do
		local mane, regex = unpack(mane_regex)
		if bibine(rupel, regex) then
						
			local ziman = rupel:match("Maneyên .+ bi (.*)$")
			local kod = require("Module:ziman").getByCanonicalName(ziman)
				if kod then
					kod = kod:getCode()
					Enziman = k.ziman_en(kod)	
					return ''.. Enziman ..' '.. mane .. '' 
				else
					return ''.. b.ucfirst(mane) .. ' by language' 
				
				end	
		end	
	end



	for _, kodDawi_regex in ipairs(daneKodDawi) do
		local kodDawi, regex = unpack(kodDawi_regex)
			if bibine(rupel, regex) then
							
				local ziman = rupel:match(".+ bi (.*)$")
				local kod = require("Module:ziman").getByCanonicalName(ziman)
					if kod then
						kod = kod:getCode()
						if kod == "navz" then 
							kod = "mul"
						elseif kod =="ku" then
							kod = "kmr"
						end						
						return ''.. kodDawi ..'/' .. kod..' ' 
					end
			end
	end
	
	for _, zTerms_regex in ipairs(daneZterms) do
		local zTerms, regex = unpack(zTerms_regex)
			if bibine(rupel, regex) then
							
				local ziman = rupel:match(".+ bi (.*)$")
				local kod = require("Module:ziman").getByCanonicalName(ziman)
					if kod then
						kod = kod:getCode()
						Enziman = k.ziman_en(kod)	
						return ''.. zTerms ..' '.. Enziman .. ' terms' 
					end
			end
	end


	for _, dawi_regex in ipairs(daneDawi) do
		local dawi, regex = unpack(dawi_regex)
			if bibine(rupel, regex) then
							
				local ziman = rupel:match(".+ bi (.*)$")
				local kod = require("Module:ziman").getByCanonicalName(ziman)
					if kod then
						kod = kod:getCode()
						Enziman = k.ziman_en(kod)	
						return ''.. dawi ..' '.. Enziman .. '' 
						
					end
			end
	end

	for _, termsBi_regex in ipairs(daneTermsBi) do
		local termsBi, regex = unpack(termsBi_regex)
			if bibine(rupel, regex) then
							
				local ziman = rupel:match(".+ bi (.*)$")
				local kod = require("Module:ziman").getByCanonicalName(ziman)
					if kod then
						kod = kod:getCode()
						Enziman = k.ziman_en(kod)	
						return ''.. Enziman ..' '.. termsBi .. '' 
					else 
						return '' .. b.ucfirst(termsBi) .. ' by language' 
						
					end
			end
	end

	
	--[[WF:Ferhengok]]

	local etiket, ziman = rupel:match("^(.+) bi (.*)$")
	local etiket = b.lcfirst(etiket)
	local interwiki = k.get_label_info(etiket)
	
	if  interwiki then 
		local kod = require("Module:ziman").getByCanonicalName(ziman)
			if kod then
				kod = kod:getCode()
					if kod == "navz" then 
						kod = "mul"
					elseif kod =="ku" then
						kod = "kmr"
					end
				return ''.. kod ..':'..b.ucfirst(interwiki).. '' 
			end
			
	elseif interwiki == nil then
		local etiket, ziman = rupel:match("^(.+) bi (.*)$")
		local etiket = b.lcfirst(etiket)
		local interwiki = k.get_rezimani(etiket)
		local kod = require("Module:ziman").getByCanonicalName(ziman)
			if kod then
				kod = kod:getCode()
					if kod == "navz" then 
						kod = "mul"
					elseif kod =="ku" then
						kod = "kmr"
					end
				return ''.. k.ziman_en(kod) ..' '..b.lcfirst(interwiki).. ''
			else
				local etiket = b.lcfirst(rupel)
				local interwiki = k.get_rezimani(etiket) 

				if interwiki then
					return ''.. b.ucfirst(interwiki) .. ' by language' 
				else 
					local etiket = b.lcfirst(rupel)
					local interwikiFerhengok = k.get_label_info(etiket) 
					if interwikiFerhengok then
						return ''.. b.ucfirst(interwikiFerhengok) .. '' 
					else
						return '[[Kategorî:Xeletiyên Modul:înterwîkî-çêke]]'
					end

				end
			end
	else
		return '[[Kategorî:Xeletiyên Modul:înterwîkî-çêke]]'
	end
end

function k.biwesine(frame)
	if mw.title.getCurrentTitle().nsText == 'Şablon' then
			return '(Ev şablon tenê li ser rûpelên [[Wîkîpediya:Kategorîkirin|kategoriyan]] tê bikaranîn.)'
	end

	local args = frame:getParent().args

	if args[1] or frame.args[1] then 
-- navê kategoriya îngilîzî dide. Nimûne di kategoriya "Navdêr bi îngilîzî" dide "English nouns"
		local rupel  = args[1] or frame.args[1]
		return k.interwiki_ceke(rupel)
	else 
		local rupel = mw.title.getCurrentTitle().text		
-- navê kategoriyê bi kar tîne û înterwîkiyê çêdike. 
		local interwiki = k.interwiki_ceke(rupel)
		return '[[en:Category:' .. interwiki .. ']]'
	end
	
end

return k