"मोड्युल:Coordinates" के अवतरणसभमे अन्तर
Content deleted Content added
self-rv: Johnuniq wanted to remove namespace test for both category and error output. Also looks like he explicitly removed a bunch whitespace. |
Biplab Anand (वार्ता | योगदान) अ Updating |
||
पङ्क्त्ति ३:
templates. It provides several methods, including
{{#
coordinate values.
{{#
degree values to DMS format.
{{#
to decimal degree format.
{{#
]]
require('Module:No globals')
local math_mod = require("Module:Math")
local coordinates = {};
Line २३ ⟶ २२:
local current_page = mw.title.getCurrentTitle()
local page_name = mw.uri.encode( current_page.prefixedText, 'WIKI' );
local coord_link = '//tools.wmflabs.org/geohack/geohack.php?language=bn&pagename=' .. page_name .. '¶ms='
local function direction2mai(text)
text = text:gsub('[NSEW]', {
N = ' उत्तर',
S = ' दक्षिण',
E = ' पूर्व',
W = ' पश्चिम',
})
return text
end
local function translate2mai(text)
text = text:gsub('%d', {
['0'] = '०',
['1'] = '१',
['2'] = '२',
['3'] = '३',
['4'] = '४',
['5'] = '५',
['6'] = '६',
['7'] = '७',
['8'] = '८',
['9'] = '९',
})
return text
end
local function translate2en(text)
text = mw.ustring.gsub(text, '%d', {
['०'] = '0',
['१'] = '1',
['२'] = '2',
['३'] = '3',
['४'] = '4',
['५'] = '5',
['६'] = '6',
['७'] = '7',
['८'] = '8',
['९'] = '9',
})
text = text
:gsub(' *उत्तर', 'N')
:gsub(' *दक्षिण', 'S')
:gsub(' *पूर्व', 'E')
:gsub(' *पश्चिम', 'W')
return text
end
--[[ Helper function, replacement for {{coord/display/title}} ]]
local function displaytitle(s, notes)
local l = "[[भौगोलिक निर्देशाङ्क प्रणाली|निर्देशाङ्क]]: " .. s
local co = '<span id="coordinates">' .. l .. notes .. '</span>';
return '<span style="font-size: small;">' .. co .. '</span>';
Line ५१ ⟶ ९७:
return function (frame)
local args = require('Module:Arguments').getArgs(frame, {
wrappers = 'Module:Coordinates' -- TODO should this use the bn name? check Module:Arguments
})
for k, v in pairs(args) do
args[k] = translate2en(v)
end
return coordinates[funcName](args, frame)
end
Line ६८ ⟶ ११७:
local result = ""
for i,v in ipairs(errors) do
local errorHTML = '<strong class="error">
result = result .. errorHTML .. "<br />"
end
Line १०३ ⟶ १५२:
if uriComponents == "" then
-- RETURN error, should never be empty or nil
return "त्रुटी: खाली प्यारामिटर"
end
if args["name"] then
Line १०९ ⟶ १५८:
end
local geodmshtml = '<span class="geo-dms" title="
.. '<span class="latitude">' .. translate2mai(coordinateSpec["dms-lat"]) .. '</span> '
.. '<span class="longitude">' .. translate2mai(coordinateSpec["dms-long"]) .. '</span>'
.. '</span>'
Line ११८ ⟶ १६७:
if lat < 0 then
-- FIXME this breaks the pre-existing precision
geodeclat = tostring(coordinateSpec["dec-lat"]):sub(2) .. "°
else
geodeclat = (coordinateSpec["dec-lat"] or 0) .. "°
end
Line १२७ ⟶ १७६:
if long < 0 then
-- FIXME does not handle unicode minus
geodeclong = tostring(coordinateSpec["dec-long"]):sub(2) .. "°
else
geodeclong = (coordinateSpec["dec-long"] or 0) .. "°
end
local geodechtml = '<span class="geo-dec" title="
.. translate2mai(geodeclat) .. ' '
.. translate2mai(geodeclong)
.. '</span>'
Line २५१ ⟶ ३००:
if strong then
if lat_d < 0 then
table.insert(errors, {source, "
end
if long_d < 0 then
table.insert(errors, {source, "
end
--[[
Line २६३ ⟶ ३१२:
if long_d > 180 then
table.insert(errors, {source, "
end
]]
Line २६९ ⟶ ३१८:
if lat_d > 90 then
table.insert(errors, {source, "
end
if lat_d < -90 then
table.insert(errors, {source, "
end
if lat_m >= 60 then
table.insert(errors, {source, "
end
if lat_m < 0 then
table.insert(errors, {source, "
end
if lat_s >= 60 then
table.insert(errors, {source, "
end
if lat_s < 0 then
table.insert(errors, {source, "
end
if long_d >= 360 then
table.insert(errors, {source, "
end
if long_d <= -360 then
table.insert(errors, {source, "
end
if long_m >= 60 then
table.insert(errors, {source, "
end
if long_m < 0 then
table.insert(errors, {source, "
end
if long_s >= 60 then
table.insert(errors, {source, "
end
if long_s < 0 then
table.insert(errors, {source, "
end
Line ३१९ ⟶ ३६८:
if not long then
return nil, {{"parseDec", "
elseif not tonumber(long) then
return nil, {{"parseDec", "
end
Line ३२९ ⟶ ३७८:
local mode = coordinates.determineMode( lat, long );
coordinateSpec["dms-lat"] = convert_dec2dms( lat, "
coordinateSpec["dms-long"] = convert_dec2dms( long, "
if format then
Line ३६० ⟶ ४०९:
errors = validate( lat_d, lat_m, lat_s, long_d, long_m, long_s, 'parseDMS', true );
if not long_d then
return nil, {{"parseDMS", "
elseif not tonumber(long_d) then
return nil, {{"parseDMS", "
end
Line ३७८ ⟶ ४२७:
end
coordinateSpec["dms-lat"] = lat_d.."°"..optionalArg(lat_m,"′") .. optionalArg(lat_s,"″") .. direction2mai(lat_f)
coordinateSpec["dms-long"] = long_d.."°"..optionalArg(long_m,"′") .. optionalArg(long_s,"″") .. direction2mai(long_f)
coordinateSpec["dec-lat"] = convert_dms2dec(lat_f, lat_d, lat_m, lat_s) -- {{coord/dms2dec|{{{4}}}|{{{1}}}|0{{{2}}}|0{{{3}}}}}
coordinateSpec["dec-long"] = convert_dms2dec(long_f, long_d, long_m, long_s) -- {{coord/dms2dec|{{{8}}}|{{{5}}}|0{{{6}}}|0{{{7}}}}}
Line ४१० ⟶ ४५९:
if not args[1] then
-- no lat logic
return errorPrinter( {{"formatTest", "
elseif not tonumber(args[1]) then
-- bad lat logic
return errorPrinter( {{"formatTest", "
elseif not args[4] and not args[5] and not args[6] then
-- dec logic
Line ४३४ ⟶ ४८३:
args[5], args[6], args[7], args[8], args.format)
if args[10] then
table.insert(errors, {'formatTest', '
end
if not result then
Line ४४५ ⟶ ४९४:
args[4], args[5], nil, args[6], args['format'])
if args[8] then
table.insert(errors, {'formatTest', '
end
if not result then
Line ४५६ ⟶ ५०५:
args[3], nil, nil, args[4], args.format)
if args[6] then
table.insert(errors, {'formatTest', '
end
if not result then
Line ४६४ ⟶ ५१३:
else
-- Error
return errorPrinter({{"formatTest", "
end
result.name = args.name
Line ४७१ ⟶ ५२०:
for _, v in ipairs(extra_param) do
if args[v] then
table.insert(errors, {'formatTest', '
end
end
Line ४७७ ⟶ ५२६:
local ret = specPrinter(args, result)
if #errors > 0 then
ret = ret .. ' ' .. errorPrinter(errors) .. '[[
end
return ret, backward
Line ४९३ ⟶ ५४२:
if snaktype == 'value' then
-- coordinates exist both here and on Wikidata, and can be compared.
ret = 'विकिडेटा निर्देशाङ्क'
elseif snaktype == 'somevalue' then
ret = 'अज्ञात निर्देशित निर्देशाङ्क'
elseif snaktype == 'novalue' then
ret = 'विकिडेटा निर्देशाङ्क निर्धारण नै कएल'
end
else
-- We have to either import the coordinates to Wikidata or remove them here.
ret = 'विकिडेटा निर्देशाङ्क अनुपलब्ध'
end
end
if ret then
return string.format('[[
else
return ''
Line ६२५ ⟶ ६७४:
end
end
local contents, backward = formatTest(args)
Line ६६४ ⟶ ७१४:
while count <= 9 do args[count] = (args[count] or ''); count = count+1 end
end
if isInTitle(Display) and not page_title.isTalkPage and page_title.subpageText ~= '
args.notes, args.format, args.display = nil
text = text .. coord_wrapper(args)
Line ६८१ ⟶ ७३१:
{{#invoke:Coordinates | coord2text | {{Coord}} | parameter }}
Valid values for the second parameter are strings: lat
]]
function coordinates.coord2text(frame)
if
coord = translate2en(coord)
local value, direction, long, ew = coord:match('(%-?[.%d]+)°([NS]) (%-?[.%d]+)°([EW])')
if param == 'long' then value, direction = long, ew end
value = tonumber(value)
if value then
if direction == 'S' or direction == 'W' then value = -value end
return tostring(value)
end
▲ return result[1]
else
return
end
end
|