Revision 18626517 of "Module:utilities" on frwiktionarylocal languages = mw.loadData("Module:languages")
local export = {}
-- Create a tagged text from a given text. This is equivalent of the script templates.
function export.tag_text(text, lang, tag, class)
return "<" .. (tag or "span") .. (class and (" class=\"" .. class .. "\"") or "")
.. " lang=\"" .. lang .. "\">" .. text .. "</" .. (tag or "span") .. ">"
end
-- transliterate the text, if possible
function export.translit(lang, text)
-- TODO: the table's information should be moved to [[Module:languages]]
local translit_modules = {
["ae"] = "Module:Avst-translit",
["el"] = "Module:el-translit",
["ru"] = "Module:ru-translit",
["ug"] = "Module:ug-translit",
["tg"] = "Module:tg-translit",
["xcl"] = "Module:xcl-translit"
}
if translit_modules[lang] then
return require(translit_modules[lang]).tr(text)
end
end
-- Detect the script based on the first alphabetical characters of a string
function export.detect_script(text, lang)
-- list of characters that may occur at the beginning of a word
local chars_table = {
["Latn"] = "A-Za-z",
["Arab"] = "ءاآأإئؤبتثجچحخدذرزسشصضطظعغفقكلمنوهي",
["Armn"] = "Ա-֊",
["Beng"] = "ঁ-৺",
["Cyrl"] = "Ѐ-ӿ",
["Deva"] = "ँ-ॽ",
["fa-Arab"] = "کیٔ",
["Geor"] = "Ⴀ-ჼ",
["Goth"] = "𐌰-𐍊",
["Grek"] = "ʹ-Ͽ",
["Hebr"] = "א-ת",
["Khmr"] = "ក-៹",
["Laoo"] = "ກ-ໝ",
["Mong"] = "᠀-ᢪ",
["Mymr"] = "က-ၙ",
["Thai"] = "ก-ฺ",
["Sinh"] = "ං-෴",
["ug-Arab"] = "ۈۇې",
-- TODO
}
-- first try to detect the script based on the native scripts of the language
local scripts = languages[lang].scripts or {}
for i, script in ipairs(scripts) do
if mw.ustring.match(text, "[%[%*%d%p%s]-[" .. chars_table[script] .. "]") then
return script
end
end
-- not written in native scripts; check for all scripts
for script, chars in ipairs(chars_table) do
if mw.ustring.match(text, "[%[%d%p%s]-[" .. chars .. "]") then
return script
end
end
end
function export.annotate(text, lang, tag, class, class_tr, translit, gloss, lit, gender, frame)
text = export.tag_text(text, lang, tag, class)
local annotations = {}
if translit then
table.insert(annotations, "<span lang=\"\"" .. (class_tr and (" class=\"" .. class_tr .. "\"") or "") .. ">" .. translit .. "</span>")
end
if gloss then
table.insert(annotations, "<span class=\"mention-gloss-double-quote\">“</span><span class='mention-gloss'>" .. gloss .. "</span><span class=\"mention-gloss-double-quote\">”</span>")
end
if lit then
table.insert(annotations, "literally <span class=\"mention-gloss-double-quote\">“</span><span class='mention-gloss'>" .. lit .. "</span><span class=\"mention-gloss-double-quote\">”</span>")
end
if #annotations > 0 then
text = text .. " (" .. table.concat(annotations, ", ") .. ")"
end
if gender then
if gender[2] or gender[3] then
-- {{#if:{{{g|{{{g1|}}}}}}| {{{{{g|{{{g1|}}}}}}|{{{g2|}}}|{{{g3|}}}}}}}
text = text .. " " .. frame:expandTemplate{title = gender[1], args = {gender[2], gender[3]}}
elseif gender[1] then
local gen = require("Module:gender and number")
text = text .. " " .. gen.format_list(gender)
end
end
return text
end
return exportAll content in the above text box is licensed under the Creative Commons Attribution-ShareAlike license Version 4 and was originally sourced from https://fr.wiktionary.org/w/index.php?oldid=18626517.
![]() ![]() This site is not affiliated with or endorsed in any way by the Wikimedia Foundation or any of its affiliates. In fact, we fucking despise them.
|