Nicht angemeldeter Benutzer - Bearbeiten von Seiten ist nur als angemeldeter Benutzer möglich.

Änderungen

Zur Navigation springen Zur Suche springen
4.268 Bytes hinzugefügt ,  13:15, 11. Nov. 2019
2019-10-02
Zeile 1: Zeile 1: −
local Export = { serial = "2019-02-24",
+
local Export = { serial = "2019-10-02",
 
                 suite  = "lang",
 
                 suite  = "lang",
 
                 item  = 26826825 }
 
                 item  = 26826825 }
Zeile 5: Zeile 5:  
Vorlage:lang und Sprachnamenvorlagen usw. unterstützen
 
Vorlage:lang und Sprachnamenvorlagen usw. unterstützen
 
]=]
 
]=]
 +
local Failsafe  = Export
 +
local GlobalMod = Export
          
local Config = {
 
local Config = {
   errCat         = false,
+
   errCat       = false,
   errClass       = "error_lang",
+
   errClass     = "error_lang",
   errClasses     = false,
+
   errClasses   = false,
   errHide       = true,
+
   errHide       = true,
   errNS         = false,
+
   errNS         = false,
   errDoubled     = { en = "Doubled:",
+
   errDoubled   = { en = "Doubled:",
                      de = "Doppelangabe:" },
+
                    de = "Doppelangabe:" },
   errEmpty       = { en = "Empty parameter value",
+
   errEmpty     = { en = "Empty parameter value",
                      de = "Parameterwert fehlt" },
+
                    de = "Parameterwert fehlt" },
   errInvalid     = { en = "Invalid:",
+
   errInvalid   = { en = "Invalid:",
                      de = "Ungültig:" },
+
                    de = "Ungültig:" },
   errMissing     = { en = "Missing parameter",
+
   errMissing   = { en = "Missing parameter",
                      de = "Parameter fehlt" },
+
                    de = "Parameter fehlt" },
   errSuggest     = { en = "'%s' * probably '%s' intended",
+
   errSuggest   = { en = "'%s' * probably '%s' intended",
                      de = "'%s' * vermutlich ist '%s' gemeint" },
+
                    de = "'%s' * vermutlich ist '%s' gemeint" },
   errUnkown     = { en = "Unkown parameter:",
+
   errUnkown     = { en = "Unkown parameter:",
                      de = "Parameter unbekannt:" },
+
                    de = "Parameter unbekannt:" },
   ipa           = "IPA",
+
   ipa           = "IPA",
   params         = { "Text1",
+
  keyBase      = 100,
                      "Audio",
+
  keyProject    = 200,
                      "IPA",
+
  keyAncient    = 300,
                      "class",
+
  keyTranslate  = 400,
                      "lenient",
+
   params       = { "Text1",
                      "script",
+
                    "Audio",
                      "style",
+
                    "IPA",
                      "nachgestellt",
+
                    "class",
                      "demo",
+
                    "lenient",
                      "demo2",
+
                    "script",
                      "demo3",
+
                    "style",
                      "demo4",
+
                    "nachgestellt",
                      "NoCat" },
+
                    "demo",
   percents       = false,
+
                    "demo2",
   orderOther     = { grc = 1,
+
                    "demo3",
                      hbo = 2,
+
                    "demo4",
                      la  = 3,
+
                    "NoCat" },
                      en  = 9 },
+
   percents     = false,
   owns           = { de = "‚%s‘" },
+
   orderOther   = { grc = 1,
  scripts        = "Multilingual/scripts",
+
                    hbo = 2,
   sepComma       = "Latn Armn Cyrl Grek Thai",
+
                    la  = 3,
   site           = "Latn",
+
                    en  = 9 },
   tmplAudio     = false,    -- template for media player link
+
   owns         = { de = "‚%s‘" },
   tmplLang       = false,    -- template for language name link
+
   sepComma     = "Latn Armn Cyrl Grek Thai",
   tmplStyles     = false
+
   site         = "Latn",
 +
   tmplAudio     = false,    -- template for media player link
 +
   tmplLang     = false,    -- template for language name link
 +
   tmplStyles   = false,
 +
  wikidata      = { Multilingual      = 47541920,
 +
                    ISO15924          = 71584769,
 +
                    ["ISO15924/codes"] = 71840276,
 +
                    TemplUtl          = 52364930 }
 
}
 
}
 +
 +
 +
 +
local foreignModule = function ( access, advanced, append, alt, alert )
 +
    -- Fetch global module
 +
    -- Precondition:
 +
    --    access    -- string, with name of base module
 +
    --    advanced  -- true, for require(); else mw.loadData()
 +
    --    append    -- string, with subpage part, if any; or false
 +
    --    alt      -- number, of wikidata item of root; or false
 +
    --    alert    -- true, for throwing error on data problem
 +
    -- Postcondition:
 +
    --    Returns whatever, probably table
 +
    -- 2019-10-29
 +
    local storage = access
 +
    local finer = function ()
 +
                      if append then
 +
                          storage = string.format( "%s/%s",
 +
                                                  storage,
 +
                                                  append )
 +
                      end
 +
                  end
 +
    local fun, lucky, r, suited
 +
    if advanced then
 +
        fun = require
 +
    else
 +
        fun = mw.loadData
 +
    end
 +
    GlobalMod.globalModules = GlobalMod.globalModules or { }
 +
    suited = GlobalMod.globalModules[ access ]
 +
    if not suited then
 +
        finer()
 +
        lucky, r = pcall( fun,  "Module:" .. storage )
 +
    end
 +
    if not lucky then
 +
        if not suited  and
 +
          type( alt ) == "number"  and
 +
          alt > 0 then
 +
            suited = string.format( "Q%d", alt )
 +
            suited = mw.wikibase.getSitelink( suited )
 +
            GlobalMod.globalModules[ access ] = suited or true
 +
        end
 +
        if type( suited ) == "string" then
 +
            storage = suited
 +
            finer()
 +
            lucky, r = pcall( fun, storage )
 +
        end
 +
        if not lucky and alert then
 +
            error( "Missing or invalid page: " .. storage, 0 )
 +
        end
 +
    end
 +
    return r
 +
end -- foreignModule()
      Zeile 60: Zeile 122:  
     -- Parameter:
 
     -- Parameter:
 
     --    ask  -- string, with name
 
     --    ask  -- string, with name
 +
    --                    "ISO15924"
 
     --                    "Multilingual"
 
     --                    "Multilingual"
 
     --                    "TemplUtl"
 
     --                    "TemplUtl"
 
     -- Returns string, with error message, if not available
 
     -- Returns string, with error message, if not available
 +
    local ext = Config[ ask ]
 
     local r
 
     local r
     if type( Config[ ask ] ) ~= "table" then
+
     if not ext  and  ext ~= false then
         local lucky, g = pcall( require, "Module:" .. ask )
+
         ext = foreignModule( ask,
         if type( g ) == "table" then
+
                            true,
             g = g[ ask ]
+
                            false,
             if type( g ) == "function" then
+
                            Config.wikidata[ ask ] )
                 Config[ ask ] = g()
+
         if type( ext ) == "table" then
 +
             Config[ ask ] = ext
 +
             if type( ext[ ask ] ) == "function" then
 +
                 Config[ ask ] = ext[ ask ]()
 
             end
 
             end
            g = false
  −
        else
  −
            g = false
   
         end
 
         end
 
         if type( Config[ ask ] ) ~= "table" then
 
         if type( Config[ ask ] ) ~= "table" then
             if not g then
+
            Config[ ask ] = false
                 g = "Invalid library *** Module:" .. ask
+
             if not ext then
 +
                 ext = "Invalid library *** Module:" .. ask
 
             end
 
             end
             g = mw.html.create( "span" )
+
             ext = mw.html.create( "span" )
                      :attr( "class", "error" )
+
                        :attr( "class", "error" )
                      :wikitext( g )
+
                        :wikitext( ext )
             r = tostring( g )
+
             r = tostring( ext )
 
         end
 
         end
 
     end
 
     end
Zeile 102: Zeile 167:     
local function Friend()
 
local function Friend()
     -- Fetch Module:Multilingual/scripts
+
     -- Fetch Module:ISO15924/codes
     if not Config.multiScripts then
+
     if not Config.codesISO15924 then
         local lucky
+
         Config.codesISO15924 = foreignModule( "ISO15924",
        lucky, Config.multiScripts = pcall( mw.loadData,
+
                                              false,
                                            "Module:" .. Config.scripts )
+
                                              "codes",
         if type( Config.multiScripts ) ~= "table" then
+
                                              Config.wikidata.ISO15924 )
             Config.multiScripts = { }
+
         if type( Config.codesISO15924 ) ~= "table" then
 +
             Config.codesISO15924 = { }
 
         end
 
         end
 
     end
 
     end
     return Config.multiScripts
+
     return Config.codesISO15924
 
end -- Friend()
 
end -- Friend()
   Zeile 164: Zeile 230:  
         end
 
         end
 
     else
 
     else
         r = string.format( "<span class=\"error\">????.%s.????</span>",
+
         local e = mw.html.create( "span" )
                          apply )
+
                        :attr( "class", "error" )
 +
                        :wikitext( string.format( "????.%s.????",
 +
                                                  apply ) )
 +
        r = tostring( e )
 
     end
 
     end
 
     return r
 
     return r
Zeile 180: Zeile 249:  
     if s == "string" then
 
     if s == "string" then
 
         r = mw.text.trim( adjust )
 
         r = mw.text.trim( adjust )
         r = ( r ~= ""  and  r ~= "0" )
+
         r = ( r ~= ""  and  r ~= "0"  and  r ~= "-" )
 
     elseif s == "boolean" then
 
     elseif s == "boolean" then
 
         r = adjust
 
         r = adjust
Zeile 197: Zeile 266:  
     -- Returns boolean
 
     -- Returns boolean
 
     local r
 
     local r
     Fetch( "Multilingual" )
+
     Fetch( "ISO15924" )
     if Config.Multilingual then
+
     if Config.ISO15924 then
         r = Config.Multilingual.isTrans( ask, assign, Config.site )
+
         r = Config.ISO15924.isTrans( ask, assign, Config.site )
 
     end
 
     end
 
     return r
 
     return r
Zeile 353: Zeile 422:  
     -- Returns string or false
 
     -- Returns string or false
 
     local r
 
     local r
     local written = Friend().written
+
     local iso639script = Friend().iso639script
     if type( written ) == "table" then
+
     if type( iso639script ) == "table" then
         r = written[ acquire ]
+
         r = iso639script[ acquire ]
 
         if type( r ) == "table" then
 
         if type( r ) == "table" then
 
             r = r[ 1 ]
 
             r = r[ 1 ]
Zeile 492: Zeile 561:  
                         :attr( "lang", advanced )
 
                         :attr( "lang", advanced )
 
         local s = "normal"
 
         local s = "normal"
         if acquire == Config.standard
+
         if acquire == facility()
 
           and Config.owns[ acquire ]  then
 
           and Config.owns[ acquire ]  then
 
             story = string.format( Config.owns[ acquire ], apply )
 
             story = string.format( Config.owns[ acquire ], apply )
Zeile 524: Zeile 593:  
     local lone = alone
 
     local lone = alone
 
     local r    = ""
 
     local r    = ""
     local lucky, s, t
+
     local k, lucky, s, t
 
     family()
 
     family()
 
     facility()
 
     facility()
Zeile 531: Zeile 600:  
         t = aliens[ i ]
 
         t = aliens[ i ]
 
         if t.short == Config.standard then
 
         if t.short == Config.standard then
 +
            t.m = Config.keyProject
 
             t.n = 0
 
             t.n = 0
 
         else
 
         else
             local o = Config.orderOther[ t.short ]
+
             k = Config.orderOther[ t.short ]
             if o then
+
             if k then
                 t.n = o
+
                 t.n = k
 +
                t.m = Config.keyAncient
 
             end
 
             end
 
             lone = false
 
             lone = false
 
         end
 
         end
 +
        t.n = t.m + t.n
 
     end -- for i
 
     end -- for i
 
     table.sort( aliens,
 
     table.sort( aliens,
Zeile 554: Zeile 626:  
               t.script  and
 
               t.script  and
 
               t.n > 0 then
 
               t.n > 0 then
                 Fetch( "Multilingual" )
+
                 Fetch( "ISO15924" )
                 if Config.Multilingual then
+
                 if Config.ISO15924 then
                     s = Config.Multilingual.getScriptName( t.script )
+
                     s = Config.ISO15924.scriptName( t.script )
 
                     if s == t.script then
 
                     if s == t.script then
 
                         s = false
 
                         s = false
Zeile 562: Zeile 634:  
                 end
 
                 end
 
             end
 
             end
             if not s  and  t.n > 0 then
+
             if not s  and  t.n > Config.keyProject then
 
                 s = fill( t.short )
 
                 s = fill( t.short )
 
             end
 
             end
 
             if not s then
 
             if not s then
 +
                Fetch( "Multilingual" )
 
                 s = mw.language.fetchLanguageName( t.short,
 
                 s = mw.language.fetchLanguageName( t.short,
 
                                                   Config.standard )
 
                                                   Config.standard )
Zeile 587: Zeile 660:  
     return r
 
     return r
 
end -- foreigns()
 
end -- foreigns()
        Zeile 754: Zeile 826:  
                 if arglist[ Config.scripting ]  and
 
                 if arglist[ Config.scripting ]  and
 
                   not arglist.Text2 then
 
                   not arglist.Text2 then
                     Fetch( "Multilingual" )
+
                     Fetch( "ISO15924" )
                     if Config.Multilingual then
+
                     if Config.ISO15924 then
                         s = Config.Multilingual
+
                         s = Config.ISO15924
                                      .getScriptName( Config.scripting )
+
                                          .scriptName( Config.scripting )
 
                     end
 
                     end
 
                 end
 
                 end
Zeile 817: Zeile 889:  
         Config.errClasses = argsF.errClasses
 
         Config.errClasses = argsF.errClasses
 
         Config.errNS      = argsF.errNS
 
         Config.errNS      = argsF.errNS
 +
        if argsF.ELEMENT and argsF.ELEMENT:match( "^%a+$" ) then
 +
            Config.scope = argsF.ELEMENT:lower()
 +
        end
 
         if argsF.SUITABLE then
 
         if argsF.SUITABLE then
 
             local params = mw.text.split( argsF.SUITABLE, " ", true )
 
             local params = mw.text.split( argsF.SUITABLE, " ", true )
Zeile 889: Zeile 964:  
                     if legal then
 
                     if legal then
 
                         local state = k:match( "^%l%l%l?%-(%u%u)$" )
 
                         local state = k:match( "^%l%l%l?%-(%u%u)$" )
 +
                        local m
 +
                        if s == Config.slang then
 +
                            m = Config.keyBase
 +
                        else
 +
                            m = Config.keyTranslate
 +
                        end
 
                         if not script then
 
                         if not script then
 
                             script = fit( s )
 
                             script = fit( s )
Zeile 899: Zeile 980:  
                         end
 
                         end
 
                         table.insert( r.trsl,
 
                         table.insert( r.trsl,
                                       { n      = #r.trsl + 10,
+
                                       { m      = m,
 +
                                        n      = #r.trsl + 1,
 
                                         script = script,
 
                                         script = script,
 
                                         short  = s,
 
                                         short  = s,
Zeile 927: Zeile 1.009:  
                     end
 
                     end
 
                 else
 
                 else
                  if not r.trsl then
+
                    if not r.trsl then
                      r.trsl = { }
+
                        r.trsl = { }
                  end
+
                    end
                  table.insert( r.trsl,
+
                    table.insert( r.trsl,
                                { n      = #r.trsl + 1,
+
                                  { m      = 100,
                                  script = k,
+
                                    n      = #r.trsl + 1,
                                  short  = k,
+
                                    script = k,
                                  slang  = Config.slang,
+
                                    short  = Config.slang,
                                  story  = v } )
+
                                    slang  = string.format( "%s-%s",
 +
                                                            Config.slang,
 +
                                                            k ),
 +
                                    story  = v } )
 
                 end
 
                 end
 
                 k = false
 
                 k = false
Zeile 977: Zeile 1.062:  
         end
 
         end
 
         if unknown then
 
         if unknown then
             r = string.format( "'<code>%s</code>'",
+
             local e = mw.html.create( "code" )
                              table.concat( unknown, " " ) )
+
                            :wikitext( table.concat( unknown, " " ) )
             r = fault( "errUnkown", r, true )
+
             r = fault( "errUnkown",
 +
                      string.format( "'%s'",  tostring( e ) ),
 +
                      true )
 
         end
 
         end
 
     end
 
     end
Zeile 987: Zeile 1.074:  
     return r
 
     return r
 
end -- furnish()
 
end -- furnish()
  −
  −
  −
Export.failsafe = function ( assert )
  −
    -- Retrieve versioning and check for compliance
  −
    -- Precondition:
  −
    --    assert  -- string, with required version or "wikidata",
  −
    --                or false
  −
    -- Postcondition:
  −
    --    Returns  string with appropriate version, or false
  −
    local since = assert
  −
    local r
  −
    if since == "wikidata" then
  −
        local item = Export.item
  −
        since = false
  −
        if type( item ) == "number"  and  item > 0 then
  −
            local entity = mw.wikibase.getEntity( string.format( "Q%d",
  −
                                                                item ) )
  −
            if type( entity ) == "table" then
  −
                local vsn = entity:formatPropertyValues( "P348" )
  −
                if type( vsn ) == "table"  and
  −
                  type( vsn.value ) == "string" and
  −
                  vsn.value ~= "" then
  −
                    r = vsn.value
  −
                end
  −
            end
  −
        end
  −
    end
  −
    if not r then
  −
        if not since  or  since <= Export.serial then
  −
            r = Export.serial
  −
        else
  −
            r = false
  −
        end
  −
    end
  −
    return r
  −
end -- Export.failsafe()
        Zeile 1.134: Zeile 1.184:  
             end
 
             end
 
         end
 
         end
 +
    end
 +
    if s  and
 +
      s:sub( 1, 5 ) == "<bdo "  and
 +
      s:find( "^<bdo [^<>]+><bdi [^<>]+>[^<>]+</bdi></bdo>$" ) then
 +
        r = s
 +
        s = false
 
     end
 
     end
 
     if s then
 
     if s then
Zeile 1.144: Zeile 1.200:  
         local slang  = params[ 1 ]
 
         local slang  = params[ 1 ]
 
         local script = argsF.SCRIPTING
 
         local script = argsF.SCRIPTING
 +
        local state  = argsF.STATE
 
         local selector
 
         local selector
 
         family()
 
         family()
Zeile 1.150: Zeile 1.207:  
                 local parts = mw.text.split( slang, "-", true )
 
                 local parts = mw.text.split( slang, "-", true )
 
                 slang = parts[ 1 ]
 
                 slang = parts[ 1 ]
                 if #parts > 1  and  parts[ 2 ]:match( "^%u%l%l%l$" ) then
+
                 for i = 2, #parts do
                    script = parts[ 2 ]
+
                    if parts[ i ]:match( "^%u%u$" ) then
                 end
+
                        state = parts[ i ]
 +
                    elseif parts[ i ]:match( "^%u%l%l%l$" ) then
 +
                        script = parts[ i ]
 +
                    end
 +
                 end -- for i
 
             end
 
             end
 
             slang = slang:lower()
 
             slang = slang:lower()
Zeile 1.160: Zeile 1.221:  
         if script then
 
         if script then
 
             first( script, bdo )
 
             first( script, bdo )
            bdi:attr( "lang", string.format( "%s-%s", slang, script ) )
   
             features( bdi, script )
 
             features( bdi, script )
 
             selector = script
 
             selector = script
Zeile 1.166: Zeile 1.226:  
                 selector = flag( selector, Config.classScript[ script ] )
 
                 selector = flag( selector, Config.classScript[ script ] )
 
             end
 
             end
 +
            s = string.format( "%s-%s", slang, script )
 
         else
 
         else
             bdi:attr( "lang", slang )
+
             s = slang
 +
        end
 +
        if state then
 +
            s = string.format( "%s-%s", s, state )
 
         end
 
         end
 +
        bdi:attr( "lang", s )
 
         selector = flag( selector, argsF.class )
 
         selector = flag( selector, argsF.class )
 
         selector = flag( selector, params.class )
 
         selector = flag( selector, params.class )
Zeile 1.205: Zeile 1.270:  
         local parts = mw.text.split( alien, "-", true )
 
         local parts = mw.text.split( alien, "-", true )
 
         slang = parts[ 1 ]
 
         slang = parts[ 1 ]
         if #parts > 1  then
+
         for i = 2, #parts do
             if parts[ 2 ]:match( "^%u%u$" ) then
+
             if parts[ i ]:match( "^%u%u$" ) then
                 state = parts[ 2 ]
+
                 state = parts[ i ]
             elseif parts[ 2 ]:match( "^%u%l%l%l$" ) then
+
             elseif parts[ i ]:match( "^%u%l%l%l$" ) then
                 script = parts[ 2 ]
+
                 script = parts[ i ]
 
             end
 
             end
         end
+
         end -- for i
 
     else
 
     else
 
         slang = alien
 
         slang = alien
Zeile 1.233: Zeile 1.298:  
     selector = flag( selector, alike )
 
     selector = flag( selector, alike )
 
     if ltr then
 
     if ltr then
         local elem = mw.html.create( "span" )
+
        local scope = Config.scope or "span"
 +
         local elem = mw.html.create( scope )
 +
        local story = apply
 +
        local set
 
         if script then
 
         if script then
             elem:attr( "lang", string.format( "%s-%s", slang, script ) )
+
             set = string.format( "%s-%s", slang, script )
 
             features( elem, script )
 
             features( elem, script )
        elseif state then
  −
            elem:attr( "lang", string.format( "%s-%s", slang, state ) )
   
         else
 
         else
             elem:attr( "lang", slang )
+
             set = slang
 
         end
 
         end
 +
        if state then
 +
            set = string.format( "%s-%s", set, state )
 +
        end
 +
        elem:attr( "lang", set )
 
         if selector then
 
         if selector then
 
             elem:addClass( selector )
 
             elem:addClass( selector )
Zeile 1.248: Zeile 1.318:  
             elem:cssText( appear )
 
             elem:cssText( appear )
 
         end
 
         end
         elem:wikitext( apply )
+
        if scope == "span" then
 +
            story = story:gsub( "\n", " " )
 +
        end
 +
         elem:wikitext( story )
 
         r = tostring( elem )
 
         r = tostring( elem )
 
         if script  and  script ~= Config.site then
 
         if script  and  script ~= Config.site then
Zeile 1.309: Zeile 1.382:  
     return furnish( argsF, argsT )
 
     return furnish( argsF, argsT )
 
end -- Export.full()
 
end -- Export.full()
 +
 +
 +
 +
Failsafe.failsafe = function ( atleast )
 +
    -- Retrieve versioning and check for compliance
 +
    -- Precondition:
 +
    --    atleast  -- string, with required version or "wikidata" or "~"
 +
    --                or false
 +
    -- Postcondition:
 +
    --    Returns  string  -- with queried version, also if problem
 +
    --              false  -- if appropriate
 +
    local last  = ( atleast == "~" )
 +
    local since = atleast
 +
    local r
 +
    if last  or  since == "wikidata" then
 +
        local item = Failsafe.item
 +
        since = false
 +
        if type( item ) == "number"  and  item > 0 then
 +
            local entity = mw.wikibase.getEntity( string.format( "Q%d",
 +
                                                                item ) )
 +
            if type( entity ) == "table" then
 +
                local vsn = entity:formatPropertyValues( "P348" )
 +
                if type( vsn ) == "table"  and
 +
                  type( vsn.value ) == "string"  and
 +
                  vsn.value ~= "" then
 +
                    if last  and  vsn.value == Failsafe.serial then
 +
                        r = false
 +
                    else
 +
                        r = vsn.value
 +
                    end
 +
                end
 +
            end
 +
        end
 +
    end
 +
    if type( r ) == "nil" then
 +
        if not since  or  since <= Failsafe.serial then
 +
            r = Failsafe.serial
 +
        else
 +
            r = false
 +
        end
 +
    end
 +
    return r
 +
end -- Failsafe.failsafe()
      Zeile 1.341: Zeile 1.457:     
p.failsafe = function ( frame )
 
p.failsafe = function ( frame )
 +
    -- Versioning interface
 
     local s = type( frame )
 
     local s = type( frame )
 
     local since
 
     local since
Zeile 1.354: Zeile 1.471:  
         end
 
         end
 
     end
 
     end
     return Export.failsafe( since )  or  ""
+
     return Failsafe.failsafe( since )  or  ""
end -- p.failsafe()
+
end -- p.failsafe
     
Cookies helfen uns bei der Bereitstellung von imedwiki. Durch die Nutzung von imedwiki erklärst du dich damit einverstanden, dass wir Cookies speichern.

Navigationsmenü