Module:sandbox/grc-translit

Hello, you have come here looking for the meaning of the word Module:sandbox/grc-translit. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:sandbox/grc-translit, but we will also tell you about its etymology, its characteristics and you will know how to say Module:sandbox/grc-translit in singular and plural. Everything you need to know about the word Module:sandbox/grc-translit you have here. The definition of the word Module:sandbox/grc-translit will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:sandbox/grc-translit, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

Module error: No such module "grc-translit/sandbox/testcases".


local export = {}

local m_data = require('Module:grc-utilities/data')
local tokenize = require('Module:grc-utilities').tokenize

local ufind = mw.ustring.find
local ugsub = mw.ustring.gsub
local U = mw.ustring.char
local ulower = mw.ustring.lower
local uupper = mw.ustring.upper

-- Can't do range with null byte apparently.
local UTF8char = '*'

-- Diacritics
local diacritics = m_data.named

-- Greek
local acute = diacritics.acute
local grave = diacritics.grave
local circumflex = diacritics.circum
local diaeresis = diacritics.diaeresis
local smooth = diacritics.smooth
local rough = diacritics.rough
local macron = diacritics.macron
local breve = diacritics.breve
local subscript = diacritics.subscript

-- Latin
local hat = diacritics.Latin_circum

local macron_diaeresis = macron .. diaeresis .. "?" .. hat
-- equivalent to ''
local alpha = '\206'
local a_subscript = '^' .. alpha .. '.*' .. subscript .. '$'
local is_velar = {
	 = true,
	 = true,
	 = true,
	 = true,
}

local tt = {
	-- Vowels
	 = "a",
	 = "e",
	 = "e" .. macron,
	 = "i",
	 = "o",
	 = "u",
	 = "o" .. macron,

	-- Consonants
	 = "b",
	 = "g",
	 = "d",
	 = "z",
	 = "th",
	 = "k",
	 = "l",
	 = "m",
	 = "n",
	 = "x",
	 = "p",
	 = "r",
	 = "s",
	 = "s",
	 = "t",
	 = "ph",
	 = "kh",
	 = "ps",
	
	-- Archaic letters
	 = "w",
	 = "ś",
	 = "q",
	 = "š",
	 = "v",
	
	-- Diacritics
	-- unchanged: macron, diaeresis, grave, acute
	 = '',
	 = '',
	 = '',
	 = hat,
	 = 'i',
}

function export.tr(text, lang, sc)
	-- If the script is given as Cprt, then forward the transliteration to that module.
	-- This should not be necessary, as ] redirects
	-- to this module only if script is polytonic.
	if sc == "Cprt" then
		-- ]
		require('Module:debug').track('grc-translit/Cprt')
		return require('Module:Cprt-translit').tr(text, lang, sc)
	end
	
	if text == '῾' then
		return 'h'
	end
	
	--[[
		Replace semicolon or Greek question mark with regular question mark,
		except after an ASCII alphanumeric character (to avoid converting
		semicolons in HTML entities).
	]]
	text = ugsub(text, "()", "%1?")
	
	-- Handle the middle dot. It is equivalent to semicolon or colon, but semicolon is probably more common.
	text = text:gsub("·", ";")
	
	local tokens = tokenize(text)

	--now read the tokens
	local output = {}
	for i, token in pairs(tokens) do
		-- Convert token to lowercase and substitute each character
		-- for its transliteration
		local translit = ulower(token):gsub(UTF8char, tt)
		
		if token == 'γ' and is_velar] then
			-- γ before a velar should be <n>
			translit = 'n'
		elseif token == 'ρ' and tokens == 'ρ' then
			-- ρ after ρ should be <rh>
			translit = 'rh'
		elseif token:find(a_subscript) then
			-- add macron to ᾳ
			translit = translit:gsub('', '%0' .. macron)
		end
		
		if token:find(rough) then
			if ufind(token, '^') then
				translit = translit .. 'h'
			else -- vowel
				translit = 'h' .. translit
			end
		end
		
		-- Remove macron from a vowel that has a circumflex.
		if ufind(translit, macron_diaeresis) then
			translit = translit:gsub(macron, '')
		end
		
		-- Capitalize first character of transliteration.
		if token ~= ulower(token) then
			translit = translit:gsub("^" .. UTF8char, uupper)
		end
		
		table.insert(output, translit)
	end
	output = table.concat(output)
	
	return output
end

return export