"मोड्युल: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.
Updating
पङ्क्त्ति ३:
templates. It provides several methods, including
 
{{#invokeInvoke:Coordinates | coord }} : General function formatting and displaying
coordinate values.
 
{{#invokeInvoke:Coordinates | dec2dms }} : Simple function for converting decimal
degree values to DMS format.
 
{{#invokeInvoke:Coordinates | dms2dec }} : Simple function for converting DMS format
to decimal degree format.
 
{{#invokeInvoke:Coordinates | link }} : Export the link used to reach the tools
 
]]
 
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 .. '&params='
 
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 l = "[[Geographic coordinate system|Coordinates]]: " .. 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
wrappers = 'Template:Coord'
})
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">Coordinatesनिर्देशाङ्क: ' .. v[2] .. '</strong>'
result = result .. errorHTML .. "<br />"
end
Line १०३ ⟶ १५२:
if uriComponents == "" then
-- RETURN error, should never be empty or nil
return "त्रुटी: खाली प्यारामिटर"
return "ERROR param was empty"
end
if args["name"] then
Line १०९ ⟶ १५८:
end
 
local geodmshtml = '<span class="geo-dms" title="Maps, aerialस्थान photosमानचित्रसभक लेल, and otherहवाई dataचित्र for thisअन्य locationजानकारी">'
.. '<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) .. "°S दक्षिण"
else
geodeclat = (coordinateSpec["dec-lat"] or 0) .. "°N उत्तर"
end
 
Line १२७ ⟶ १७६:
if long < 0 then
-- FIXME does not handle unicode minus
geodeclong = tostring(coordinateSpec["dec-long"]):sub(2) .. "°W पश्चिम"
else
geodeclong = (coordinateSpec["dec-long"] or 0) .. "°E पूर्व"
end
 
local geodechtml = '<span class="geo-dec" title="Maps, aerialई स्थान मानचित्रसभक photosलेल, andहवाई otherचित्र data forअन्य thisजानकारी location">'
.. translate2mai(geodeclat) .. ' '
.. translate2mai(geodeclong)
.. '</span>'
 
Line २५१ ⟶ ३००:
if strong then
if lat_d < 0 then
table.insert(errors, {source, "latitudeगोलार्द्ध degreesझण्डा <अक्षांश 0डिग्री with hemisphere< flag"})
end
if long_d < 0 then
table.insert(errors, {source, "longitudeगोलार्द्ध degreesझण्डा <देशान्तर 0डिग्री with hemisphere< flag"})
end
--[[
Line २६३ ⟶ ३१२:
 
if long_d > 180 then
table.insert(errors, {source, "longitudeगोलार्द्ध degreesझण्डा >देशान्तर 180डिग्री with hemisphere> flag१८०"})
end
]]
Line २६९ ⟶ ३१८:
 
if lat_d > 90 then
table.insert(errors, {source, "latitudeअक्षांश degreesडिग्री > 90९०"})
end
if lat_d < -90 then
table.insert(errors, {source, "latitudeअक्षांश degreesडिग्री < -90९०"})
end
if lat_m >= 60 then
table.insert(errors, {source, "latitudeअक्षांश minutesमिनेट >= 60६०"})
end
if lat_m < 0 then
table.insert(errors, {source, "latitudeअक्षांश minutesमिनेट < 0"})
end
if lat_s >= 60 then
table.insert(errors, {source, "latitudeअक्षांश secondsसेकेन्ड >= 60६०"})
end
if lat_s < 0 then
table.insert(errors, {source, "latitudeअक्षांश secondsसेकेन्ड < 0"})
end
if long_d >= 360 then
table.insert(errors, {source, "longitudeदेशान्तर degreesडिग्री >= 360३६०"})
end
if long_d <= -360 then
table.insert(errors, {source, "longitudeदेशान्तर degreesडिग्री <= -360३६०"})
end
if long_m >= 60 then
table.insert(errors, {source, "longitudeदेशान्तर minutesडिग्री >= 60६०"})
end
if long_m < 0 then
table.insert(errors, {source, "longitudeदेशान्तर minutesडिग्री < 0"})
end
if long_s >= 60 then
table.insert(errors, {source, "longitudeदेशान्तर secondsडिग्री >= 60६०"})
end
if long_s < 0 then
table.insert(errors, {source, "longitudeदेशान्तर secondsडिग्री < 0"})
end
 
Line ३१९ ⟶ ३६८:
 
if not long then
return nil, {{"parseDec", "Missingदेशान्तर longitudeअनुपस्थित"}}
elseif not tonumber(long) then
return nil, {{"parseDec", "Longitudeदेशान्तरक couldएक notसङ्ख्याक beरुपमे parsedव्याख्या asनै aकएल numberजा सकैत अछि: " .. long}}
end
 
Line ३२९ ⟶ ३७८:
 
local mode = coordinates.determineMode( lat, long );
coordinateSpec["dms-lat"] = convert_dec2dms( lat, "N उत्तर", "S दक्षिण", mode) -- {{coord/dec2dms|{{{1}}}|N|S|{{coord/prec dec|{{{1}}}|{{{2}}}}}}}
coordinateSpec["dms-long"] = convert_dec2dms( long, "E पूर्व", "W पश्चिम", mode) -- {{coord/dec2dms|{{{2}}}|E|W|{{coord/prec dec|{{{1}}}|{{{2}}}}}}}
 
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", "Missingदेशान्तर longitudeअनुपस्थित" }}
elseif not tonumber(long_d) then
return nil, {{"parseDMS", "Longitudeदेशान्तरक couldएक notसङ्ख्याक beरुपमे parsedव्याख्या asनै aकएल numberजा सकैत अछि:" .. long_d }}
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", "Missingअक्षांश latitudeअनुपस्थित"}} )
elseif not tonumber(args[1]) then
-- bad lat logic
return errorPrinter( {{"formatTest", "Unableअक्षांशक toएक parseसङ्ख्याक latitudeरुपमे asपार्स aकरैमे numberविफल:" .. args[1]}} )
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', 'Extraअतिरिक्त unexpectedअप्रत्यासित parametersप्यारामिटर'})
end
if not result then
Line ४४५ ⟶ ४९४:
args[4], args[5], nil, args[6], args['format'])
if args[8] then
table.insert(errors, {'formatTest', 'Extraअतिरिक्त unexpectedअप्रत्यासित parametersप्यारामिटर'})
end
if not result then
Line ४५६ ⟶ ५०५:
args[3], nil, nil, args[4], args.format)
if args[6] then
table.insert(errors, {'formatTest', 'Extraअतिरिक्त unexpectedअप्रत्यासित parametersप्यारामिटर'})
end
if not result then
Line ४६४ ⟶ ५१३:
else
-- Error
return errorPrinter({{"formatTest", "Unknownअज्ञात argumentतर्क formatप्रारूप"}})
end
result.name = args.name
Line ४७१ ⟶ ५२०:
for _, v in ipairs(extra_param) do
if args[v] then
table.insert(errors, {'formatTest', 'Parameterप्यारामिटर: "' .. v .. '=" shouldहोवाक beचाही "' .. v .. ':"' })
end
end
Line ४७७ ⟶ ५२६:
local ret = specPrinter(args, result)
if #errors > 0 then
ret = ret .. ' ' .. errorPrinter(errors) .. '[[Categoryश्रेणी:Pagesखराब withलेबल malformedसमन्वययुक्त coordinate tagsपन्ना]]'
end
return ret, backward
Line ४९३ ⟶ ५४२:
if snaktype == 'value' then
-- coordinates exist both here and on Wikidata, and can be compared.
ret = 'विकिडेटा निर्देशाङ्क'
ret = 'Coordinates on Wikidata'
elseif snaktype == 'somevalue' then
ret = 'अज्ञात निर्देशित निर्देशाङ्क'
ret = 'Coordinates on Wikidata set to unknown value'
elseif snaktype == 'novalue' then
ret = 'विकिडेटा निर्देशाङ्क निर्धारण नै कएल'
ret = 'Coordinates on Wikidata set to no value'
end
else
-- We have to either import the coordinates to Wikidata or remove them here.
ret = 'विकिडेटा निर्देशाङ्क अनुपलब्ध'
ret = 'Coordinates not on Wikidata'
end
end
if ret then
return string.format('[[Categoryश्रेणी:%s]]', ret)
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 ~= 'docDoc' and page_title.subpageText ~= 'testcasesपरीक्षण पृष्ठ' then args[10] = 'primary' end
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 (signed integer), long (signed integer), type, scale, dim, region, globe, source
 
]]
function coordinates.coord2text(frame)
iflocal frame.args[1]coord == '' or mw.text.trim(frame.args[21] ==or '' or not frame.args[2] then return nil end)
frame.args[2]local param = mw.text.trim(frame.args[2] or '')
if frame.args[2]coord == 'lat' or frame.args[2]param == 'long' then return nil end
coord = translate2en(coord)
local result, negative = mw.text.split((mw.ustring.match(frame.args[1],'[%.%d]+°[NS] [%.%d]+°[EW]') or ''), ' ')
if frame.args[2]param == 'lat' or param == 'long' then
local value, direction, long, ew = coord:match('(%-?[.%d]+)°([NS]) (%-?[.%d]+)°([EW])')
result, negative = result[1], 'S'
if param == 'long' then value, direction = long, ew end
else
value = tonumber(value)
result, negative = result[2], 'W'
if value then
if direction == 'S' or direction == 'W' then value = -value end
return tostring(value)
end
return result[1]nil
result = mw.text.split(result, '°')
if result[2] == negative then result[1] = '-'..result[1] end
return result[1]
else
return mw.ustring.coord:match(frame.args[1], 'params=.-_'..frame.args[2]param..':(.-)[ _]')
end
end