Difference between revisions of "Module:Sandbox/Erutuon/random"

From blackwiki
Jump to navigation Jump to search
blackwiki>Erutuon
m (don't add IPA template if it's already present)
m (31 revisions imported)
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
require("Module:No globals")
+
local p = {}
  
local p = {}
+
local Out_mt = {}
 +
Out_mt.__index = Out_mt
 +
 
 +
function Out_mt:add(...)
 +
for i = 1, select('#', ...) do
 +
self.i = self.i + 1
 +
self[self.i] = select(i, ...)
 +
end
 +
end
 +
 
 +
function Out_mt:__tostring()
 +
return table.concat(self)
 +
end
  
local count_scripts = require("Module:Language/scripts").countScripts
+
function Out()
 +
local o = setmetatable({}, Out_mt)
 +
o.i = 0
 +
return o
 +
end
  
 
function p.show(frame)
 
function p.show(frame)
local content = mw.title.new("Help:IPA/Ukrainian"):getContent()
+
local out = Out()
 
 
content = content:gsub("(\n| *([^\n]+))",
+
local language_data = require 'Module:Language/data'
function(whole_match, cell_content)
+
local Wiktionary = {
whole_match = "\n| " .. cell_content
+
name_to_code = require 'Module:Language/Wiktionary name to code',
if cell_content:sub(1, 1) == "/" then -- IPA
+
code_to_name = require 'Module:Language/Wiktionary code to name',
return whole_match:gsub("/[^/]+/", "{{IPA|%0}}")
+
}
end
+
+
for code, data in require 'Module:TableTools'.sortedPairs(language_data.languages) do
if cell_content:find("<big>") and not cell_content:find("{{IPA") then
+
if not Wiktionary.code_to_name[code] then
return whole_match:gsub("<big>([^<]+)</big>",
+
out:add(code)
function(symbol)
+
local Wiktionary_code = data.name and Wiktionary.name_to_code[data.name]
local template
+
if Wiktionary_code then
if symbol:find("ʲ") then
+
out:add(' &rarr; ', Wiktionary_code)
template = "IPA"
+
local MediaWiki_name = mw.language.fetchLanguageName(Wiktionary_code, 'en')
else
+
if MediaWiki_name ~= data.name then
template = "IPA link"
+
out:add(' (MediaWiki: ',
end
+
MediaWiki_name ~= '' and MediaWiki_name or '<none>',
return "<big>{{" .. template .. "|" .. symbol .. "}}</big>"
+
', Wiktionary: ', data.name, ')')
end)
+
end
end
 
 
local scripts = count_scripts(cell_content)
 
if scripts.Cyrl and not scripts.Latn then
 
return whole_match:gsub("[^ |,]+", "{{lang|uk|%0}}")
 
 
end
 
end
end)
+
out:add('\n* ')
 +
elseif data.name and data.name == mw.language.fetchLanguageName(code, 'en') then
 +
out:add(code, ' (', data.name, ')')
 +
out:add('\n* ')
 +
end
 +
end
 
 
return frame:extensionTag{
+
return out
name = "syntaxhighlight",
 
content = content,
 
}
 
 
end
 
end
  
 
return p
 
return p

Latest revision as of 09:46, 27 September 2020

Test

  • Lua error in package.lua at line 80: module 'Module:Language/Wiktionary name to code' not found.



local p = {}

local Out_mt = {}
Out_mt.__index = Out_mt

function Out_mt:add(...)
	for i = 1, select('#', ...) do
		self.i = self.i + 1
		self[self.i] = select(i, ...)
	end
end

function Out_mt:__tostring()
	return table.concat(self)
end

function Out()
	local o = setmetatable({}, Out_mt)
	o.i = 0
	return o
end

function p.show(frame)
	local out = Out()
	
	local language_data = require 'Module:Language/data'
	local Wiktionary = {
		name_to_code = require 'Module:Language/Wiktionary name to code',
		code_to_name = require 'Module:Language/Wiktionary code to name',
	}
	
	for code, data in require 'Module:TableTools'.sortedPairs(language_data.languages) do
		if not Wiktionary.code_to_name[code] then
			out:add(code)
			local Wiktionary_code = data.name and Wiktionary.name_to_code[data.name]
			if Wiktionary_code then
				out:add(' &rarr; ', Wiktionary_code)
				local MediaWiki_name = mw.language.fetchLanguageName(Wiktionary_code, 'en')
				if MediaWiki_name ~= data.name then
					out:add(' (MediaWiki: ',
						MediaWiki_name ~= '' and MediaWiki_name or '<none>',
						', Wiktionary: ', data.name, ')')
				end
			end
			out:add('\n* ')
		elseif data.name and data.name == mw.language.fetchLanguageName(code, 'en') then
			out:add(code, ' (', data.name, ')')
			out:add('\n* ')
		end
	end
	
	return out
end

return p