Documentation for this module may be created at Module:page/τεκμηρίωση

-- Split the title of the page in parts.
-- Lesson https://en.wikiversity.org/wiki/Lua/Title_Library
-- https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Title_library
-- for NO export, see [[Module:learn-title1]]

local export = {}

-- ============ SPLIT the title of the page in parts ================ --

-- 1) gives: Category:Title (textinparenthesis)
-- call it with
--		fullpagetext(blablalbanaythingyouwant)
function export.fullpagetext(xx)						-- xx, yy or anyhing
    local xx = mw.title.getCurrentTitle()		-- do not change this COMMAND
    return xx.fullText  -- do not change the word: fullText
end

-- 2) gives: Category
function export.namespacetext(xx)
    local xx = mw.title.getCurrentTitle();
    return xx.nsText -- do not change the word: nsText
end

-- 3) gives: Title (textinparenthesis)
function export.pagetext(xx)
    local xx = mw.title.getCurrentTitle()
    return xx.text -- do not change the word: text
end

-- 4) gives: (textinparenthesis)
function export.pageparenthesis(xx)
	local xx = mw.ustring.match(export.pagetext(xx), '(%([^%(%)]+%))$') or ''
	return xx
end

-- 5) gives: Title WITHOUT (textinparenthesis)
function export.pagetitle(xx)
	local xx = ''
	if export.pageparenthesis(xx) == '' or export.pageparenthesis(xx) == nil then
		xx = export.pagetext(xx)
	else
		xx = mw.ustring.match(export.pagetext(xx), '^(.+) (%([^%(%)]+%))$')
	end
return xx
end

-- 6) extract the text from the parenthesis, if there is one. This is the languages.name
-- gives: textinparenthesis without the brackets
function export.pagelang(xx)
	local xx = ''
	if export.pageparenthesis(xx) == '' or export.pageparenthesis(xx) == nil then
		xx = ''
	else
		xx = mw.ustring.sub(mw.ustring.match(export.pagetext(xx), '(%([^%(%)]+%))$'), 2, -2) -- this is textwithoutparenthesis
	end
	return xx
end



-- =================== LANGUAGE in pageparenthesis  ===================== --
--7)

local languages = mw.loadData("Module:Languages")
-- also required below: [[Module:lang]] with language related functions

-- ============ get iso from pagelang ================ --
-- In el.wiktionary the textinparenthesis is the language name ([[Module:Languages]] keyword: name, here, the parameter lang_name
-- From that, we will get this language's iso code (keyword: iso)
-- This mathcing is done in [[Module:lang]], function langname_to_langiso
function export.get_iso(iso)
	if export.pageparenthesis(xx) == '' or export.pageparenthesis(xx) == nil then
		lang_name = ''
		lang_iso = ''
	else
		lang_name = export.pagelang(xx)
		lang_iso = require("Module:lang").langname_to_langiso(export.pagelang(xx))
			-- DO NOT USE the function name_to_iso, it will not work here	
	end
	-- PROBLEM: Also gives language names which are WRONG -- there is no ERROR message

return lang_iso
end -- close get_iso(xx)


return export