This module does various things related to Tibetan. See {{bo-new}}
.
local m_str_utils = require("Module:string utilities")
local codepoint = m_str_utils.codepoint
local gsub = m_str_utils.gsub
local len = m_str_utils.len
local match = m_str_utils.match
local sub = m_str_utils.sub
local u = m_str_utils.char
local upper = m_str_utils.upper
local export = {}
function export.preconvert(text)
return (gsub(text, "()༹", function(m1) return u(codepoint(m1) + 0xF0000) end))
end
function export.invalidChecks(text)
return {
len(gsub(text, "", "")) > 6, -- 5 & 6 letter syllables are very rare
}
end
function export.mainStackChecks(text)
return {
match(text, "+*"),
match(text, "+"),
match(text, "^འ+"),
match(text, "()྄"),
match(text, "()འ+$"),
match(text, "()འ"),
(len(text) == 3 or len(text) == 4) and match(text, "()འ$"),
len(gsub(text, "྄", "")) == 1 and text,
len(gsub(text, "྄", "")) == 2 and match(text, "^()"),
len(gsub(text, "྄", "")) == 4 and match(text, "^྄?()"),
match(text, "()$"),
match(text, "^"),
match(text, "^()྄"),
match(text, "^(ག)"),
match(text, "^(ད)"),
match(text, "^(བ)"),
match(text, "^(མ)"),
match(text, "^(འ)"),
match(text, "()ས྄?$"),
match(text, "()ད྄?$")
}
end
function export.postconvert(text)
return (gsub(text, "()", function(m1) return u(codepoint(m1) - 0xF0000) .. "༹" end))
end
export.ambiguousSyllables = {
= "མ", = "མ", = "བ", = "ད", = "ག", = "མ", = "བ", = "བ", = "ག", = "ན", = "ན"
}
function export.new(frame)
local title = mw.title.getCurrentTitle().text
local args = frame:getParent().args
local pron = args or false
local pos = args or ""
local def = args or "{{rfdef|bo}}"
local pos2 = args or (args and "" or false)
local def2 = args or "{{rfdef|bo}}"
local pos3 = args or (args and "" or false)
local def3 = args or "{{rfdef|bo}}"
local etym = args or false
local head = args or false
local cat = args or false
local reg = args or false
local otb = args or false
local result = ""
local function genTitle(text)
local pos_title = {
= "Noun", = "Noun", = "Proper noun", = "Proper noun", = "Pronoun",
= "Verb", = "Verb", = "Adjective", = "Adjective", = "Adverb",
= "Preposition", = "Postposition", = "Conjunction",
= "Particle", = "Suffix",
= "Proverb", = "Idiom", = "Phrase", = "Interjection", = "Interjection",
= "Classifier", = "Classifier", = "Numeral", = "Abbreviation", = "Determiner"
};
return pos_title or upper(sub(text, 1, 1)) .. sub(text, 2, -1)
end
local function genHead(text)
local pos_head = {
= "noun", = "noun", = "proper noun", = "proper noun", = "verb", = "verb form", = "adj",
= "post", = "con", = "particle", = "pronoun",
= "proverb", = "idiom", = "phrase", = "interj",
= "abbr", = "classifier", = "det"
};
return pos_head or text
end
local function other(class, title, args)
local code = ""
if args then
code = code .. "\n\n===" .. title .. "===\n* {{l|bo|" .. args .. "}}"
if args then
code = code .. "\n* {{l|bo|" .. args .. "}}"
if args then
code = code .. "\n* {{l|bo|" .. args .. "}}"
if args then
code = code .. "\n* {{l|bo|" .. args .. "}}"
end
end
end
end
return code
end
result = result .. "==Tibetan=="
if args then result = result .. "\n{{wikipedia|lang=bo" ..
(args == "y" and "" or "|" .. args) .. "}}" end
result = result .. other("alt", "Alternative forms", args)
if etym then result = result .. "\n\n===Etymology===\n" .. etym end
result = result .. "\n\n===Pronunciation===\n{{bo-pron" .. (pron and "|" .. pron or "") .. (otb and "|otb=-" or "") .. "}}"
result = result .. "\n\n===" .. genTitle(pos) .. "===\n{{bo-" .. genHead(pos) .. (head and ("|head=" .. head) or "") .. "}}\n\n# " .. def
if reg then result = result .. "\n{{bo-registers|" .. reg .. "}}" end
result = result .. other("syn", "=Synonyms=", args)
result = result .. other("ant", "=Antonyms=", args)
result = result .. other("der", "=Derived terms=", args)
result = result .. other("also", "=See also=", args)
if pos2 then
result = result .. "\n\n===" .. genTitle(pos2) .. "===\n{{bo-" .. genHead(pos2) .. (head and ("|head=" .. head) or "") .. "}}\n\n# " .. def2
end
if pos3 then
result = result .. "\n\n===" .. genTitle(pos3) .. "===\n{{bo-" .. genHead(pos3) .. (head and ("|head=" .. head) or "") .. "}}\n\n# " .. def3
end
if cat then result = result .. "\n\n{{C|bo|" .. cat .. "}}" end
return result
end
function export.verb(frame)
local title = mw.title.getCurrentTitle().text
title = require("Module:Tibt-translit").tr(title, "bo", "Tibt")
local s = { match(title, (gsub(title, ".", "(.)"))) }
local i = #s - 1
local j = i - 1
if match(s, "") or (s == "n" and s == "g") then
return "བ"
end
return "པ"
end
function export.removePa(frame)
local title = mw.title.getCurrentTitle().text
return (gsub(title, "་$", ""))
end
return export