सामग्री पर जाएँ

मॉड्यूल:Lang

भारतपीडिया से

उपयोग[स्रोत सम्पादित करें]

यह मॉड्यूल किसी अन्य भाषा के पाठ को उस भाषा की विशेषता के साथ दिखाता है।

प्राचल[स्रोत सम्पादित करें]

  • 1 — भाषा कोड, जैसे ar, la, fr, hi। वैकल्पिक है; न हो तो सादा पाठ दिखता है।
  • 2 — दिखाया जाने वाला पाठ। आवश्यक है; न हो तो कुछ नहीं दिखता।
  • text — पाठ, प्राचल 2 का दूसरा नाम।
  • code / lang — भाषा कोड, प्राचल 1 का दूसरा नाम।
  • translit — पाठ का लिप्यंतरण; हो तो पाठ के बाद कोष्ठक में दिखता है। वैकल्पिक है।
  • script — लिपि का नाम; वैकल्पिक है।
  • italic — yes हो तो पाठ तिरछा दिखता है। वैकल्पिक है।
  • rtl — yes हो तो पाठ दाएँ से बाएँ दिखता है; ar, he, fa, ur जैसी भाषाओं में अपने आप लगता है। वैकल्पिक है।

उदाहरण[स्रोत सम्पादित करें]

{{Lang|ar|आदम}}

इससे आदम दिखता है।

{{Lang|la|Cinchona calisaya}}

इससे लातिनी नाम भाषा विशेषता के साथ दिखता है।

{{Lang|hi|भारत|translit=Bhārat}}

इससे भारत (Bhārat) दिखता है।

सीधे बुलाना:

{{#invoke:Lang|lang|ar|आदम}}
{{#invoke:Lang|main|fr|Bonjour}}

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 args = {}
    local parent = frame:getParent()
    if parent and parent.args then
        for k, v in pairs(parent.args) do args[k] = v 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

function p._lang(args)
    local code = clean_code(args[1] or args.code or args.lang or "")
    local text = trim(args[2] or args.text or "")
    if text == "" then
        -- केवल एक प्राचल हो तो उसे ही पाठ मानें (पुराने प्रयोगों के लिए)
        text = trim(args[1] or "")
        code = ""
    end
    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
    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
        out = text
    else
        out = '<span' .. attrs .. style .. '>' .. text .. '</span>'
    end
    if translit ~= "" then out = out .. ' (' .. translit .. ')' end
    return out
end

function p.lang(frame)
    return p._lang(get_args(frame))
end

p.main = p.lang
setmetatable(p, { __index = function(t, k) return p.lang end })

return p