মডিউল:Convert/sandbox

উইকিপিডিয়া, মুক্ত বিশ্বকোষ থেকে

এটি এই পাতার একটি পুরনো সংস্করণ, যা Johnuniq (আলোচনা | অবদান) কর্তৃক ১০:৩৪, ২৪ আগস্ট ২০১৩ তারিখে সম্পাদিত হয়েছিল (fix fact that translation_table now does not use language index)। উপস্থিত ঠিকানাটি (ইউআরএল) এই সংস্করণের একটি স্থায়ী লিঙ্ক, যা বর্তমান সংস্করণ থেকে ব্যাপকভাবে ভিন্ন হতে পারে।

মডিউল নথি[তৈরি করুন]
-- Test mw.ustring.gsub when used to translate bn digits to en.
-- Seems to be a problem using mw.loadData to access the table.
-- Usage:
-- {{#invoke:convert/sandbox|main|TEST}}
-- {{#invoke:convert/sandbox|main|১২৩.৪}}  (123.4)
-- Or in debug window:
-- =p.translate('TEST')
-- =p.translate('১২৩.৪')
-- Can append extra argument 'load' or 'require' to use table from Convert/text.
-- =p.translate('TEST', 'load')         use mw.loadData
-- =p.translate('TEST', 'require')      use require
-- Can use 'SHOW' instead of 'TEST' to return a display of the table.

local to_en = {
    ['০']='0', ['১']='1', ['২']='2', ['৩']='3', ['৪']='4',
    ['৫']='5', ['৬']='6', ['৭']='7', ['৮']='8', ['৯']='9'
}

local function show(t)
    -- Return text representing given table of strings.
    local keys = {}
    for k, _ in pairs(t) do
        table.insert(keys, k)
    end
    table.sort(keys)
    local lines = { '{' }
    for _, k in ipairs(keys) do
        local fmt = '  [%q] = %q,'
        table.insert(lines, fmt:format(k, t[k]))
    end
    return table.concat(lines, '\n') .. '\n}\n'
end

local function translate(text, include)
    if text == 'TEST' then
        text = '১২৩৪৫৬৭৮৯০'  -- '1234567890'
    end
    local converttext
    if include == 'load' then
        converttext = mw.loadData('Module:Convert/text')
    elseif include == 'require' then
        converttext = require('Module:Convert/text')
    end
    local xlate
    if converttext then
        xlate = converttext.translation_table.to_en
    else
        xlate = to_en
    end
    if text == 'SHOW' then
        return show(xlate)
    else
    return (mw.ustring.gsub(text, '%d', xlate))
    end
end

local function main(frame)
    return translate(frame.args[1], frame.args[2])
end

return { main = main, translate = translate }