Modul:Coordinates/kml: Unterschied zwischen den Versionen

Aus InkluPedia
(Modul neu nach https://de.wikipedia.org/wiki/Modul:Coordinates/kml , Autoren siehe https://de.wikipedia.org/w/index.php?title=Modul:Coordinates/kml&action=history und https://de.wikipedia.beta.wmflabs.org/w/index.php?title=Modul:Coordinates/kml)
 
(serial angepasst)
 
(2 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
local coordinates = { suite  = "Coordinates/kml",
local coordinates = { suite  = "Coordinates/kml",
                       serial = "2018-04-02",
                       serial = "2021-02-23",
                       item  = 50976437 }
                       item  = 50976437 }
--[=[
--[=[

Aktuelle Version vom 24. Februar 2021, 07:56 Uhr

  • Dieses Modul enthält Code in der Programmiersprache Lua.
  • Module werden über #invoke in Vorlagen eingebunden.
  • Dieses Modul wird über Vorlagen auf folgenden Seiten verwendet: Seiten anzeigen

local coordinates = { suite  = "Coordinates/kml",
                      serial = "2021-02-23",
                      item   = 50976437 }
--[=[
Overcome a limitation in kmlexport in 2018.

There are three functions below which might be copied into an existing
       [[Module:Coordinates]] ([[d:Q7348344]])
or this module might be used stand-alone.

In templates it can be used then by
        {{#invoke:Coordinates|kmlTitle|Some title for geohack}}
or respectively (as is)
        {{#invoke:Coordinates/kml|kmlTitle|Some title for geohack}}
]=]



coordinates.utf8max2bytes = function ( adjust )
    -- Save characters > 0x7FF by simplification
    -- Precondition:
    --     adjust  -- string to be adjusted
    -- Postcondition:
    --     returns  string
    local r = adjust
    local lucky, translate = pcall( mw.loadData,
                                    "Module:Sort/utf8max2bytes" )
    if type( translate ) == "table" then
        local Sort
        lucky, Sort = pcall( require, "Module:Sort" )
        if type( Sort ) == "table" and
           type( Sort.Sort ) == "function" then
           Sort = Sort.Sort()
            if type( Sort ) == "table" and
               type( Sort.lex ) == "function" then
                local s = Sort.lex( r, translate )
                if type( s ) == "string" then
                    r = s
                end
            end
        end
    end
    return r
end -- coordinates.utf8max2bytes()



coordinates._kmlTitle = function ( adjust )
    -- Hack kmlexport title as of 2018 UTF-8 limitation
    -- Precondition:
    --     adjust  -- string to be adjusted
    -- Postcondition:
    --     returns  string
    local pattern = mw.ustring.char( 91, 0x0800, 45, 0x7FFFF, 93 )
    local r = mw.text.decode( adjust, true )
    r = mw.text.trim( r )
    if mw.ustring.find( r, pattern ) then
        r = coordinates.utf8max2bytes( r )
        r = mw.ustring.gsub( r, pattern, "" )
    end
    if mw.text.trim( r ) == "" then
        -- fall back to original string if all characters removed
        r = adjust
    end
    return r
end -- coordinates._kmlTitle()



coordinates.kmlTitle = function ( frame )
    -- #invoke to adjust kmlexport title
    local r = frame.args[ 1 ]
    if r and r ~= "" then
        r = coordinates._kmlTitle( r )
    end
    return r or ""
end -- coordinates.kmlTitle



return coordinates