Module:TableTranslation
local p = {}
-- Optional RTL detection for future Langx/dir support
local rtl_langs = {
ar = true, he = true, fa = true, ur = true,
ps = true, prs = true, syr = true, ckb = true,
}
local function is_rtl(code)
if not code then return false end
code = mw.ustring.lower(mw.text.trim(code))
return rtl_langs[code] or false
end
-- Lang cell using {{Lang}} to support italics and formatting
local function lang_cell(frame, code, rawtext)
code = code or ""
rawtext = rawtext or ""
-- If rawtext contains block-level templates or wikitext, skip Langx
local is_block = rawtext:match("^{{") or rawtext:match("<blockquote") or rawtext:match("<div") or rawtext:match("<table")
if code ~= "" and not is_block then
-- Safe to use Langx
return "| " .. frame:preprocess(string.format("{{Langx|%s|%s|label=none|italic=unset}}", code, rawtext))
else
-- Don't preprocess twice — just wrap in a <span> with lang if needed
local expanded = frame:preprocess(rawtext)
if code ~= "" then
return "| <span lang=\"" .. code .. "\">" .. expanded .. "</span>"
else
return "| " .. expanded
end
end
end
function p.render(frame)
local parent = frame:getParent()
local args = parent and parent.args or frame.args -- fallback for subst
-- Detect substitution and render static content
local isSubst = (parent == nil or frame:getTitle() == (parent.getTitle and parent:getTitle())) or mw.isSubsting()
-- Resolve language codes from various aliases
local code1 = args["lang1code"] or args["lang1"] or args[1]
local code2 = args["lang2code"] or args["lang2"] or args[2]
if not code1 or not code2 then
return "Error: Please provide both lang1code and lang2code."
end
-- Expand display names from ISO 639 codes
local lang1 = frame:expandTemplate{ title = "ISO 639 name", args = { code1 } }
local lang2 = frame:expandTemplate{ title = "ISO 639 name", args = { code2 } }
-- Check if romanization is enabled
local showRom = args["showromanization"] and mw.ustring.lower(args["showromanization"]) == "true"
-- Begin table
local output = {}
-- Check if sortable is disabled
local sortable = args["sortable"]
local tableClass = "wikitable"
if not (sortable and mw.ustring.lower(sortable) == "false") then
tableClass = tableClass .. " sortable"
end
-- Start table with caption (optional future upgrade)
if showRom then
table.insert(output, '{| class="' .. tableClass .. '"')
table.insert(output, string.format("! %s !! Transliteration !! %s", lang1, lang2))
else
table.insert(output, '{| class="' .. tableClass .. '"')
table.insert(output, string.format("! %s !! %s", lang1, lang2))
end
-- Named parameters (text1, rom1, trans1)
local i = 1
while true do
local text = args["text" .. i]
local trans = args["trans" .. i]
if not text and not trans then break end
local roman = args["rom" .. i] or ""
table.insert(output, "|-")
table.insert(output, lang_cell(frame, code1, text))
if showRom then
table.insert(output, "| " .. roman)
end
table.insert(output, lang_cell(frame, code2, trans))
i = i + 1
end
-- Positional fallback (|text|roman|trans) or (|text|trans)
local index = 1
while true do
local text = args[index]
local roman = showRom and args[index + 1] or nil
local trans = showRom and args[index + 2] or args[index + 1]
if not text and not trans then break end
table.insert(output, "|-")
table.insert(output, lang_cell(frame, code1, text))
if showRom then
table.insert(output, "| " .. (roman or ""))
index = index + 3
else
index = index + 2
end
table.insert(output, lang_cell(frame, code2, trans))
end
table.insert(output, "|}")
return table.concat(output, "\n")
end
return p
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.