پودمان:Leftright: Difference between revisions

From faraghaib
Jump to navigation Jump to search
admin>Admin
صفحه‌ای تازه حاوی «-- fork of "Module:Yesno" -- Implements {{چپ‌راست}} -- Converts local or abbreviated forms of "left", "right" and "center" -- to a value usable for HTML attributes such as "align" or "float" require( 'strict' ) local p = {} function p.leftRight(input, default) local out input = type(input) == 'string' and mw.ustring.lower(input) or input if input == nil then out = nil elseif input == 'راست' or input == 'ر' or...» ایجاد کرد
 
admin>Admin
m ۱ نسخه واردشده
(No difference)

Revision as of 22:35, May 25, 2025

-- fork of "Module:Yesno" -- Implements Template:چپ‌راست -- Converts local or abbreviated forms of "left", "right" and "center" -- to a value usable for HTML attributes such as "align" or "float"

require( 'strict' )

local p = {}

function p.leftRight(input, default) local out input = type(input) == 'string' and mw.ustring.lower(input) or input if input == nil then out = nil elseif input == 'راست' or input == 'ر' or input == 'right' or input == 'r' then out = 'right' elseif input == 'چپ' or input == 'چ' or input == 'left' or input == 'l' then out = 'left' elseif input == 'وسط' or input == 'و' or input == 'center' or input == 'centre' or input == 'c' then out = 'center' elseif input == 'راست‌به‌چپ' or input == 'راست به چپ' or input == 'rtl' then out = 'rtl' elseif input == 'چپ‌به‌راست' or input == 'چپ به راست' or input == 'ltr' then out = 'ltr' else out = default end return out end

-- remove whitespaces from beginning and end of args local function valueFunc(key, val) if type(val) == 'string' then val = mw.ustring.match(val, '^%s*(.-)%s*$') if val == then return nil end end return val end

function p.main(frame) local args = require('Module:Arguments').getArgs(frame, {wrappers = 'الگو:چپ‌راست', valueFunc = valueFunc}) return p.leftRight(args[1], (args[2] or args['پیش‌فرض']) or 'left') end

return p