"मॉड्यूल:Lang": अवतरणों में अंतर
सीधे बुलाए जाने पर भी भाषा का पाठ दिखाने के लिए सुधार किया गया टैग: मोबाइल संपादन मोबाइल वेब संपादन उन्नत मोबाइल संपादन |
विस्तृत संस्करण बनाया गया टैग: मोबाइल संपादन मोबाइल वेब संपादन उन्नत मोबाइल संपादन |
||
| पंक्ति १: | पंक्ति १: | ||
local p = {} | local p = {} | ||
-- | -- विस्तृत संस्करण: भाषा कोड और पाठ को भाषा विशेषता के साथ दिखाता है। | ||
-- प्रयोग: {{Lang|ar|आदम}} | {{Lang|la|Cinchona}} | {{#invoke:Lang|lang|ar|आदम}} | |||
-- नाम वाले प्राचल: text=, code= / lang=, translit=, script=, italic=yes, rtl=yes | |||
-- यदि पाठ न हो तो खाली लौटाता है; यदि कोड न हो तो सादा पाठ लौटाता है — कभी स्क्रिप्ट त्रुटि नहीं देता। | |||
local rtl_codes = { ar = true, he = true, fa = true, ur = true, ps = true, sd = true, ug = true, yi = true, arc = true, dv = true } | |||
local function trim(s) | |||
if s == nil then return "" end | |||
return tostring(s):gsub("^%s+", ""):gsub("%s+$", "") | |||
end | |||
local function clean_code(code) | |||
code = trim(code):lower() | |||
code = code:gsub("[^a-z%-]", "") | |||
return code | |||
end | |||
local function get_args(frame) | local function get_args(frame) | ||
local args = {} | |||
local parent = frame:getParent() | local parent = frame:getParent() | ||
if parent and parent.args then | if parent and parent.args then | ||
for k, v in pairs(parent.args) do args[k] = v end | |||
end | end | ||
if frame.args then | |||
for k, v in pairs(frame.args) do | |||
if v ~= "" then args[k] = v end | |||
end | |||
end | |||
return args | |||
end | end | ||
function p. | function p._lang(args) | ||
local code = clean_code(args[1] or args.code or args.lang or "") | |||
local code = args[1] or "" | local text = trim(args[2] or args.text or "") | ||
local text = args[2] or "" | |||
if text == "" then | if text == "" then | ||
text = args[1] or "" | -- केवल एक प्राचल हो तो उसे ही पाठ मानें (पुराने प्रयोगों के लिए) | ||
text = trim(args[1] or "") | |||
code = "" | code = "" | ||
end | end | ||
if text == "" then | if text == "" then return "" end | ||
local translit = trim(args.translit or args.transliteration or "") | |||
local script = trim(args.script or "") | |||
local italic = trim(args.italic or args.i or "") | |||
local attrs = "" | |||
if code ~= "" then attrs = attrs .. ' lang="' .. code .. '"' end | |||
if rtl_codes[code] or trim(args.rtl or "") == "yes" or trim(args.dir or "") == "rtl" then | |||
attrs = attrs .. ' dir="rtl"' | |||
end | end | ||
if script ~= "" then attrs = attrs .. ' data-script="' .. script .. '"' end | |||
local style = "" | |||
if italic == "yes" or italic == "y" then style = ' style="font-style:italic;"' end | |||
local out | |||
if code == "" then | if code == "" then | ||
out = text | |||
else | |||
out = '<span' .. attrs .. style .. '>' .. text .. '</span>' | |||
end | end | ||
if translit ~= "" then out = out .. ' (' .. translit .. ')' end | |||
return out | |||
end | |||
function p.lang(frame) | |||
return p._lang(get_args(frame)) | |||
end | end | ||