A modult a Modul:transliteration module documentation/doc lapon tudod dokumentálni
local export = {}
local Array = require "Module:array"
-- Possible names:
-- lang (])
-- script (])
-- lang-script (])
-- script-script where module romanizes either script (])
-- script-script where the first script is transliterated into the second (])
-- script-to-script (])
-- script-something, maybe transliteration system (])
-- The last two are not handled here.
local patterns
do
local lang_code = "%l+%l"
local sc_code = "%u%l%l%l"
patterns = {
{ "^(" .. lang_code .. ")%-translit$", "lang" },
{ "^(" .. sc_code .. ")%-translit$", "sc" },
{ "^(" .. lang_code .. ")%-(" .. sc_code .. ")%-translit$", "lang", "sc" },
{ "^(" .. sc_code .. ")%-(" .. sc_code .. ")%-translit$", "sc1", "sc2" },
}
end
function export.parse_title(title)
local result = {}
for _, vals in ipairs(patterns) do
local pattern, key1, key2 = unpack(vals)
local match1, match2 = title:match(pattern)
if match1 then
result = match1
if key2 then
result = match2
end
break
end
end
return result
end
local function link_lang_cat(lang)
return ("]")
:format(lang:getCategoryName(), lang:getCanonicalName())
end
local function page_exists(title)
local success, title_obj = pcall(mw.title.new, title)
return success and title_obj.exists
end
function export.translit_module_lang_list(pagename, lang_code_in_title, plain, subpage)
local translit_module = pagename
local language_objects = require("Module:languages/byTranslitModule")(translit_module)
local categories = Array()
local lang_code_in_title_in_list = false
if lang_code_in_title then
if language_objects and subpage ~= "doc" then
local agreement = #language_objects == 1 and "" or "s"
categories:insert("[[Category:Transliteration modules used by "
.. #language_objects .. " language" .. agreement .. "]]")
end
language_objects = Array(language_objects)
:filter(
function (lang)
local result = lang:getCode() ~= lang_code_in_title
lang_code_in_title_in_list = lang_code_in_title_in_list or result
return result
end)
end
if subpage ~= "doc" then
for script_code in pagename:gmatch("%f%u%l%l%l%f") do
local script = require "Module:scripts".getByCode(script_code)
if script then
categories:insert("]")
end
end
end
if #language_objects == 0 then
return plain and "" or categories:concat()
end
local langs = Array(language_objects)
:sort(
function(lang1, lang2)
return lang1:getCode() < lang2:getCode()
end)
:map(plain and function (lang)
return lang:getCanonicalName()
end
or link_lang_cat)
return "Használatos " .. mw.text.listToText(langs)
.. " szöveg átírásához" .. (lang_code_in_title_in_list and " is" or "") .. "."
.. (plain and "" or categories:concat())
end
local function make_transliteration_shortcut(lang_code)
return mw.title.new("Wiktionary:" .. lang_code:upper() .. " TR")
end
function export.intro_text(title)
local vals = export.parse_title(title.rootText)
local obj, transliteration_shortcut
local extra = ""
if vals.lang then
obj = require "Module:languages".getByCode(vals.lang)
transliteration_shortcut = make_transliteration_shortcut(vals.lang)
if vals.sc then
local sc = require "Module:scripts".getByCode(vals.sc)
-- This works for scripts whose categories end in "script".
extra = " written in the " .. link_lang_cat(sc)
end
elseif vals.sc then
obj = require "Module:scripts".getByCode(vals.sc)
end
local lang_list = export.translit_module_lang_list(title.rootText, vals.lang)
if obj then
return "This module will transliterate " .. link_lang_cat(obj) .. " text"
.. extra
.. (transliteration_shortcut and transliteration_shortcut.exists
and " per ]"
or "")
.. "."
.. (lang_list and " " .. lang_list or "")
else
error("!!!")
end
end
function export.show(frame, title)
return export.intro_text(mw.title.getCurrentTitle())
end
function export.translitModuleLangList(frame)
local pagename, subpage
if frame.args then
pagename = frame.args
else
local title = mw.title.getCurrentTitle()
subpage = title.subpageText
pagename = title.text
if subpage ~= pagename then
pagename = title.rootText
end
end
local lang_code_in_title = export.parse_title(pagename).lang
return export.translit_module_lang_list(pagename, lang_code_in_title, false, subpage)
end
return export