Zum Inhalt springen

Modul:Coordinates/kml

Ord Wikipedia

Die Dokumentation für dieses Modul kann unter Modul:Coordinates/kml/Doku erstellt werden

local coordinates = { suite  = "Coordinates/kml",
                      serial = "2018-04-02",
                      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