Module:Formatnum: रिवीजन सभ के बीचा में अंतर

Content deleted Content added
Created page with '-- This module is intended to replace the functionality of Template:Formatnum and related templates. -- This module is in beta. Use with caution. local p = {}...'
 
No edit summary
लाइन 8:
local args = pframe.args
-- Preprocessing prec
if tonumber(args.prec) ~= nil and tonumber(args.prec) > 0 and tonumber(args[1]) ~= nil then
if string.find(tostring(args[1]), "%.") ~= nil then
precnumber =if (string.sublen(args[1],) 1,- (string.find(tostring(args[1]), "%.")) +< tonumber(args.prec)) then
precnumber = "" .. args[1] .. string.rep("0", tonumber(args.prec) - (string.len(args[1]) - string.find(tostring(args[1]), "%.")))
elseif (string.len(args[1]) - string.find(tostring(args[1]), "%.")) > tonumber(args.prec) then
local proc = string.gsub(args[1], "0+$", "")
if (string.len(proc) - string.find(tostring(proc), "%.")) < tonumber(args.prec) then
precnumber = proc .. string.rep("0", tonumber(args.prec) - (string.len(proc) - string.find(tostring(proc), "%.")))
else
precnumber = proc
end
elseif (string.len(args[1]) - string.find(tostring(args[1]), "%.")) == tonumber(args.prec) then
precnumber = args[1]
end
else
precnumber = "" .. args[1] .. "." .. string.rep("0", args.prec)
end
number = "" .. precnumber .. "1"
precA = "true"
else
number = args[1]
end
local digitml = {
["0"] = '൦',
["1"] = '൧',
["2"] = '൨',
["3"] = '൩',
["4"] = '൪',
["5"] = '൫',
["6"] = '൬',
["7"] = '൭',
["8"] = '൮',
["9"] = '൯'
}
local digitmn = {
["0"] = '᠐',
["1"] = '᠑',
["2"] = '᠒',
["3"] = '᠓',
["4"] = '᠔',
["5"] = '᠕',
["6"] = '᠖',
["7"] = '᠗',
["8"] = '᠘',
["9"] = '᠙'
}
local digitte = {
["0"] = '౦',
["1"] = '౧',
["2"] = '౨',
["3"] = '౩',
["4"] = '౪',
["5"] = '౫',
["6"] = '౬',
["7"] = '౭',
["8"] = '౮',
["9"] = '౯'
}
local digitth = {
["0"] = '๐',
["1"] = '๑',
["2"] = '๒',
["3"] = '๓',
["4"] = '๔',
["5"] = '๕',
["6"] = '๖',
["7"] = '๗',
["8"] = '๘',
["9"] = '๙'
}
 
if args[2] == "arabic indic" then
language = "ks"
elseif args[2] == "ml-old" then
language = "ml"
else
language = args[2]
end
-- Formatnum
if tonumber(number) ~= nil and mw.language.isSupportedLanguage(args[2] or "") == true then
if tonumber(number) ~= nil and mw.language.isKnownLanguageTag(language or "") == true then
formatnum = mw.getLanguage( args[2] ):formatNum( tonumber(number) )
formatnum = mw.getLanguage( language ):formatNum( tonumber(number) )
elseif tonumber(number) ~= nil then
formatnum = mw.getLanguage(frame:preprocess( "{{int:lang}}" )):formatNum(tonumber(number))
Line 28 ⟶ 98:
end
-- Formatnum, special cases
local numsc = formatnum
if args[2] == "ml-old" then
for en, ml in pairs(digitml) do
numsc = mw.ustring.gsub(numsc, en, ml)
end
elseif args[2] == "mn" then
for en, mn in pairs(digitmn) do
numsc = mw.ustring.gsub(numsc, en, mn)
end
elseif args[2] == "te" then
for en, te in pairs(digitte) do
numsc = mw.ustring.gsub(numsc, en, te)
end
elseif args[2] == "th" then
for en, th in pairs(digitth) do
numsc = mw.ustring.gsub(numsc, en, th)
end
end
--Postprocessing prec
if precA == "true" then
postprec = stringmw.ustring.sub(formatnumnumsc, 1, (stringmw.ustring.len(formatnumnumsc) - 1))
else
postprec = formatnumnumsc
end
-- Seperator
-- Eqvaluent functions to Template:FormatnumSigns
if args.sep ~= nil and args.sep ~= "" then
-- Table over what thousands seperator is used.
thousand = {
ckb="٫",
fa="٫",
glk="٫",
ks="٫",
mzn="٫",
ur=",",
ca=".",
da=",",
de=",",
gl=",",
mk=",",
nds=",",
nl=",",
sl=",",
cs=",",
fr=",",
hu=",",
ro=",",
pl=",",
nb=",",
nn=",",
no=",",
sv=",",
bn=".",
ml=".",
hi=".",
sa=".",
ta=".",
kn=".",
te=".",
mr=".",
["or"]=".",
pa=".",
gu=".",
bho=".",
as="."
}
-- Table ends
if args.sep ~= nil then
local replace = mw.ustring.gsub( "", "%%", "%%%%" )
if mw.language.isKnownLanguageTag(language or "") == true then
local pattern = mw.ustring.gsub( (thousand[args[2] or frame:preprocess( "{{int:lang}}" )] or "."), "([%(%)%.%%%+%-%*%?%[%^%$%]])", "%%%1" )
local seperator = mw.ustring.sub(mw.getLanguage(language):formatNum(tonumber("1000")), 2, 2)
return tostring(mw.ustring.gsub( postprec, pattern, replace ))
if tostring(mw.ustring.find(seperator, "%s")) == "1" then
pattern = mw.ustring.format(" ", "%s")
elseif tostring(mw.ustring.find(seperator, "%p")) == "1" then
pattern = mw.ustring.gsub(seperator, "([%(%)%.%%%+%-%*%?%[%^%$%]])", "%%%1")
else
pattern = ""
end
return tostring(mw.ustring.gsub( postprec, pattern, replace ))
else
local seperator = mw.ustring.sub(mw.getLanguage(frame:preprocess("{{int:lang}}")):formatNum(tonumber("1000")), 2, 2)
if tostring(mw.ustring.find(seperator, "%s")) == "1" then
pattern = mw.ustring.format(" ", "%s")
elseif tostring(mw.ustring.find(seperator, "%p")) == "1" then
pattern = mw.ustring.gsub(seperator, "([%(%)%.%%%+%-%*%?%[%^%$%]])", "%%%1")
else
pattern = ""
end
return tostring(mw.ustring.gsub( postprec, pattern, replace ))
end
else
return postprec
"https://bh.wikipedia.org/wiki/Module:Formatnum" से लिहल गइल