local w={}function w.pseudoLocalize(z)local g=w.PseudoCharacterMap local H=""local C=false for w,x in utf8.graphemes(z)do local Q=z:sub(w,x)if Q=="\123"then C=true H=H..Q elseif Q=="\125"then C=false H=H..Q elseif not C and g[Q]then H=H..g[Q]else H=H..Q end end return H end function w.addToLocalizationTable(z,g,H)local C=g or"\113\108\112-\112\108\115"local x=H or"\101\110"local Q=z:GetEntries()for z,g in pairs(Q)do if not g.Values[C]then local z=g.Values[x]if z then g.Values[C]=w.pseudoLocalize(z)else warn(("\091\080\115\101\117\100\111\076\111\099\097\108\105\122\101\046\097\100\100\084\111\076\111\099\097\108\105\122\097\116\105\111\110\084\097\098\108\101\093 - \078\111 \101\110\116\114\121 \105\110 \107\101\121 \037\113 \102\111\114 \108\111\099\097\108\101 \037\113"):format(g.Key,x))end end end z:SetEntries(Q)end w.PseudoCharacterMap={a="\195\161",b="\206\178";c="\195\167";d="\206\180",e="\195\168",f="\198\146";g="\207\177",h="\206\187";i="\195\175";j="\074";k="\198\153";l="\226\132\147",m="\226\130\165";n="\195\177";o="\195\180";p="\198\165";q="\057",r="\197\153";s="\198\168";t="\198\173";u="\195\186";v="\198\178";w="\207\137",x="\208\182";y="\194\165";z="\198\186",A="\195\130";B="\195\159";C="\195\135",D="\195\144",E="\195\137";F="\070",G="\071",H="\072";I="\195\140";J="\074";K="\075";L="\194\163";M="\077";N="\078";O="\195\147";P="\195\158",Q="\081",R="\082";S="\194\167",T="\084";U="\195\155",V="\086",W="\087";X="\088";Y="\195\157";Z="\090"}return w
--- Pseudo localizes text. Useful for verifying translation without having
--  actual translations available
-- @module PseudoLocalize

local lib = {}

--- Translates a line into pseudo text while maintaining params
-- @tparam {string} line The line to translate
-- @return The translated line
function lib.pseudoLocalize(line)
	local charMap = lib.PseudoCharacterMap
	local out = ""
	local isParam = false

	for start, stop in utf8.graphemes(line) do
		local char = line:sub(start, stop)
		if char == "{" then
			isParam = true
			out = out .. char
		elseif char == "}" then
			isParam = false
			out = out .. char
		elseif not isParam and charMap[char] then
			out = out .. charMap[char]
		else
			out = out .. char
		end
	end

	return out
end

--- Parses a localization table and adds a pseudo localized locale to the table
-- @tparam[opt="qlp-pls"] {string} preferredLocaleId Preferred locale to use
-- @tparam[opt="en-us"] {string} preferredFromLocale Preferred from locale
function lib.addToLocalizationTable(localizationTable, preferredLocaleId, preferredFromLocale)
	local localeId = preferredLocaleId or "qlp-pls"
	local fromLocale = preferredFromLocale or "en"

	local entries = localizationTable:GetEntries()
	for _, entry in pairs(entries) do
		if not entry.Values[localeId] then
			local line = entry.Values[fromLocale]
			if line then
				entry.Values[localeId] = lib.pseudoLocalize(line)
			else
				warn(("[PseudoLocalize.addToLocalizationTable] - No entry in key %q for locale %q")
					:format(entry.Key, fromLocale))
			end
		end
	end

	localizationTable:SetEntries(entries)
end

--- Mapping of English characters to pseudo localized characters
lib.PseudoCharacterMap = {
    ["a"] = "á";
    ["b"] = "β";
    ["c"] = "ç";
    ["d"] = "δ";
    ["e"] = "è";
    ["f"] = "ƒ";
    ["g"] = "ϱ";
    ["h"] = "λ";
    ["i"] = "ï";
    ["j"] = "J";
    ["k"] = "ƙ";
    ["l"] = "ℓ";
    ["m"] = "₥";
    ["n"] = "ñ";
    ["o"] = "ô";
    ["p"] = "ƥ";
    ["q"] = "9";
    ["r"] = "ř";
    ["s"] = "ƨ";
    ["t"] = "ƭ";
    ["u"] = "ú";
    ["v"] = "Ʋ";
    ["w"] = "ω";
    ["x"] = "ж";
    ["y"] = "¥";
    ["z"] = "ƺ";
    ["A"] = "Â";
    ["B"] = "ß";
    ["C"] = "Ç";
    ["D"] = "Ð";
    ["E"] = "É";
    ["F"] = "F";
    ["G"] = "G";
    ["H"] = "H";
    ["I"] = "Ì";
    ["J"] = "J";
    ["K"] = "K";
    ["L"] = "£";
    ["M"] = "M";
    ["N"] = "N";
    ["O"] = "Ó";
    ["P"] = "Þ";
    ["Q"] = "Q";
    ["R"] = "R";
    ["S"] = "§";
    ["T"] = "T";
    ["U"] = "Û";
    ["V"] = "V";
    ["W"] = "W";
    ["X"] = "X";
    ["Y"] = "Ý";
    ["Z"] = "Z";
}

return lib
