<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://academia.la/w/index.php?action=history&amp;feed=atom&amp;title=Module%3AIPA%2FX-SAMPA</id>
	<title>Module:IPA/X-SAMPA - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://academia.la/w/index.php?action=history&amp;feed=atom&amp;title=Module%3AIPA%2FX-SAMPA"/>
	<link rel="alternate" type="text/html" href="https://academia.la/w/index.php?title=Module:IPA/X-SAMPA&amp;action=history"/>
	<updated>2026-05-11T22:52:55Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.40.0</generator>
	<entry>
		<id>https://academia.la/w/index.php?title=Module:IPA/X-SAMPA&amp;diff=1514&amp;oldid=prev</id>
		<title>Jācōbus: Created page with &quot;local export = {}  local m_XSAMPA = mw.loadData('Module:IPA/data/X-SAMPA')  -- IPA &lt;-&gt; XSAMPA lookup tables local i2x_lookup = {} local function Populate_IPA_XSAMPA_LookupTables() 	if #i2x_lookup == 0 then 		for XSAMPA_symbol, data in pairs(m_XSAMPA) do 			local IPA_symbol = data[1] 			i2x_lookup[IPA_symbol] = XSAMPA_symbol 			 			local with_descender = data.with_descender 			if with_descender then 				i2x_lookup[with_descender] = XSAMPA_symbol 			end 		end 	end 	return...&quot;</title>
		<link rel="alternate" type="text/html" href="https://academia.la/w/index.php?title=Module:IPA/X-SAMPA&amp;diff=1514&amp;oldid=prev"/>
		<updated>2023-02-09T12:23:12Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;local export = {}  local m_XSAMPA = mw.loadData(&amp;#039;Module:IPA/data/X-SAMPA&amp;#039;)  -- IPA &amp;lt;-&amp;gt; XSAMPA lookup tables local i2x_lookup = {} local function Populate_IPA_XSAMPA_LookupTables() 	if #i2x_lookup == 0 then 		for XSAMPA_symbol, data in pairs(m_XSAMPA) do 			local IPA_symbol = data[1] 			i2x_lookup[IPA_symbol] = XSAMPA_symbol 			 			local with_descender = data.with_descender 			if with_descender then 				i2x_lookup[with_descender] = XSAMPA_symbol 			end 		end 	end 	return...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local export = {}&lt;br /&gt;
&lt;br /&gt;
local m_XSAMPA = mw.loadData('Module:IPA/data/X-SAMPA')&lt;br /&gt;
&lt;br /&gt;
-- IPA &amp;lt;-&amp;gt; XSAMPA lookup tables&lt;br /&gt;
local i2x_lookup = {}&lt;br /&gt;
local function Populate_IPA_XSAMPA_LookupTables()&lt;br /&gt;
	if #i2x_lookup == 0 then&lt;br /&gt;
		for XSAMPA_symbol, data in pairs(m_XSAMPA) do&lt;br /&gt;
			local IPA_symbol = data[1]&lt;br /&gt;
			i2x_lookup[IPA_symbol] = XSAMPA_symbol&lt;br /&gt;
			&lt;br /&gt;
			local with_descender = data.with_descender&lt;br /&gt;
			if with_descender then&lt;br /&gt;
				i2x_lookup[with_descender] = XSAMPA_symbol&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return i2x_lookup&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function export.IPA_to_XSAMPA(text)&lt;br /&gt;
	Populate_IPA_XSAMPA_LookupTables()&lt;br /&gt;
	&lt;br /&gt;
	local escape = false&lt;br /&gt;
	if type(text) == 'table' then -- a frame, extract args&lt;br /&gt;
		text = text.args[1]&lt;br /&gt;
		text = text:gsub('{{=}}','='):gsub('{{!}}','|')&lt;br /&gt;
		text = mw.text.decode(text) -- XXX&lt;br /&gt;
		escape = true&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	text = text:gsub('ːː', ':') -- this basically sums up m_symbols[2].XSAMPA&lt;br /&gt;
	text = mw.ustring.gsub(text, '.', i2x_lookup)&lt;br /&gt;
&lt;br /&gt;
	if escape then&lt;br /&gt;
		text = mw.text.nowiki(text)&lt;br /&gt;
	end&lt;br /&gt;
	return text&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function export.XSAMPA_to_IPA(text)&lt;br /&gt;
	local data = m_XSAMPA&lt;br /&gt;
	&lt;br /&gt;
	local escape = false&lt;br /&gt;
	if type(text) == 'table' then -- a frame, extract args&lt;br /&gt;
		text = text.args[1]&lt;br /&gt;
		text = mw.text.decode(text) -- XXX&lt;br /&gt;
		escape = true&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- Simpler function adapted from [[w:Module:Sandbox/Erutuon/X-SAMPA]]&lt;br /&gt;
	local output, characteristics  = {}, {}&lt;br /&gt;
	local angle_bracket&lt;br /&gt;
	if text:sub(1, 1) == &amp;quot;&amp;lt;&amp;quot; and text:sub(-1) == &amp;quot;&amp;gt;&amp;quot; then&lt;br /&gt;
		table.insert(output, &amp;quot;⟨&amp;quot;)&lt;br /&gt;
		angle_bracket =  &amp;quot;⟩&amp;quot;&lt;br /&gt;
		text = text:sub(2, -2)&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local escaped = {}&lt;br /&gt;
	local emoticon = 0x1F600 - 1&lt;br /&gt;
	&lt;br /&gt;
	local function escape(text, pattern)&lt;br /&gt;
		emoticon = emoticon + 1&lt;br /&gt;
		return text:gsub(&lt;br /&gt;
			pattern,&lt;br /&gt;
			function(match)&lt;br /&gt;
				local emoticon = mw.ustring.char(emoticon)&lt;br /&gt;
				escaped[emoticon] = match&lt;br /&gt;
				return emoticon&lt;br /&gt;
			end)&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	--[[&lt;br /&gt;
		Replace&lt;br /&gt;
		-- HTML tags&lt;br /&gt;
		-- character entity references (&amp;amp;nbsp;)&lt;br /&gt;
		-- numeric character references (&amp;amp;#32; &amp;amp;#x20;)&lt;br /&gt;
		with characters from Emoticon block.&lt;br /&gt;
	--]]&lt;br /&gt;
	&lt;br /&gt;
	text = escape(text, '&amp;lt;[^&amp;gt;]+&amp;gt;')&lt;br /&gt;
	text = escape(text, '&amp;amp;%a+;')&lt;br /&gt;
	text = escape(text, '&amp;amp;#%d+;')&lt;br /&gt;
	text = escape(text, '&amp;amp;#x%x+;')&lt;br /&gt;
	&lt;br /&gt;
	while #text &amp;gt; 0 do&lt;br /&gt;
		 -- skip non-ASCII bytes (that is, multi-byte characters)&lt;br /&gt;
		text = text:gsub(&lt;br /&gt;
			'^[\128-\255]+',&lt;br /&gt;
			function (nonASCII)&lt;br /&gt;
				table.insert(output, nonASCII)&lt;br /&gt;
				return &amp;quot;&amp;quot;&lt;br /&gt;
			end)&lt;br /&gt;
		&lt;br /&gt;
		for i = 4, 1, -1 do&lt;br /&gt;
			local potential_XSAMPA = text:sub(1, i)&lt;br /&gt;
			local result = data[potential_XSAMPA]&lt;br /&gt;
			local IPA, with_descender, has_descender, is_diacritic&lt;br /&gt;
			&lt;br /&gt;
			if result then&lt;br /&gt;
				IPA = result[1]&lt;br /&gt;
				with_descender = result.with_descender&lt;br /&gt;
				has_descender = result.has_descender&lt;br /&gt;
				is_diacritic = result.is_diacritic&lt;br /&gt;
				if with_descender then&lt;br /&gt;
					-- Go backwords through the transcription, skipping any diacritics.&lt;br /&gt;
					local j = 0&lt;br /&gt;
					while characteristics[#characteristics - j].is_diacritic do&lt;br /&gt;
						j = j + 1&lt;br /&gt;
					end&lt;br /&gt;
					--[[	Look at the first non-diacritic symbol before the current symbol.&lt;br /&gt;
							If it has a descender, use the descender form of the current symbol. ]]&lt;br /&gt;
					if characteristics[#characteristics - j].has_descender then&lt;br /&gt;
						IPA = with_descender&lt;br /&gt;
					end&lt;br /&gt;
				end&lt;br /&gt;
			elseif i == 1 then&lt;br /&gt;
				IPA = potential_XSAMPA&lt;br /&gt;
			end&lt;br /&gt;
			&lt;br /&gt;
			if IPA then&lt;br /&gt;
				text = text:sub(i + 1)&lt;br /&gt;
				table.insert(output, IPA)&lt;br /&gt;
				table.insert(characteristics, { has_descender = has_descender, is_diacritic = is_diacritic } )&lt;br /&gt;
				break&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	table.insert(output, angle_bracket)&lt;br /&gt;
	&lt;br /&gt;
	output = table.concat(output)&lt;br /&gt;
	&lt;br /&gt;
	output = output:gsub(&amp;quot;[\194-\244][\128-\191]+&amp;quot;, escaped)&lt;br /&gt;
	&lt;br /&gt;
	if escape then&lt;br /&gt;
--		output = mw.text.nowiki(output)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return output&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return export&lt;/div&gt;</summary>
		<author><name>Jācōbus</name></author>
	</entry>
</feed>