Modul:Multilingual: Unterschied zwischen den Versionen

2016-06-11
w>PerfektesChaos
(2016-05-23)
w>PerfektesChaos
(2016-06-11)
Zeile 1: Zeile 1:
local Multilingual = { suite  = "Multilingual",
local Multilingual = { suite  = "Multilingual",
                       serial = "2016-05-23" };
                       serial = "2016-06-11" };




Zeile 6: Zeile 6:
-- local globals
-- local globals
local Frame
local Frame
function fair( ask )
    -- Format language code according to BCP 47 / RFC 4646
    -- Precondition:
    --    ask  -- language name, downcased
    -- Postcondition:
    --    nil, or string
    local r
    if ask:find( "-", 3, true ) then
        local parts = mw.text.split( ask, "-" )
        if parts[ 1 ]:match( "^%l%l%l?$" ) then
            local script = parts[ 2 ]
            r = parts[ 1 ]
            if script then
                local subA2  = parts[ 3 ]
                if script:match( "^%l%l%l%l$" ) then
                    r = string.format( "%s-%s%s",
                                      r,
                                      script:sub( 1, 1 ):upper(),
                                      script:sub( 2 ) )
                else
                    subA2 = script
                end
                if subA2  and  subA2:match( "^%l%l$" ) then
                    r = string.format( "%s-%s",
                                      r,
                                      subA2:upper() )
                end
            end
        end
    elseif ask:match( "^%l%l%l?$" ) then
        r = ask
    end
    return r
end -- fair()




Zeile 63: Zeile 100:
     --    alien  -- language code of ask
     --    alien  -- language code of ask
     -- Postcondition:
     -- Postcondition:
     --    nil, or
     --    nil, or string
     local codes = mw.language.fetchLanguageNames( alien, "all" )
     local codes = mw.language.fetchLanguageNames( alien, "all" )
     local r
     local r
Zeile 72: Zeile 109:
         end
         end
     end -- for k, v
     end -- for k, v
    if not r then
        r = fair( ask )
    end
     return r
     return r
end -- find()
end -- find()
Zeile 106: Zeile 146:
         seek = mw.ustring.lower( seek )
         seek = mw.ustring.lower( seek )
         if Multilingual.isLang( seek ) then
         if Multilingual.isLang( seek ) then
             r = seek
             r = fair( seek )
         else
         else
             local slang = favorite()
             local slang = favorite()
Zeile 129: Zeile 169:
     --                  -- "!": current project
     --                  -- "!": current project
     --                  -- "#": code, downcased, space separated
     --                  -- "#": code, downcased, space separated
    --                  -- "-": code, mixcase, space separated
     --                  -- any valid code
     --                  -- any valid code
     --    alter    -- capitalize, if "c"; downcase all, if "d"
     --    alter    -- capitalize, if "c"; downcase all, if "d"
Zeile 150: Zeile 191:
             if adjacent then
             if adjacent then
                 separator = adjacent
                 separator = adjacent
             elseif alien == "#" then
             elseif alien == "#"  or  alien == "-" then
                 separator = " "
                 separator = " "
             else
             else
Zeile 181: Zeile 222:
                 slang = Multilingual.findCode( single )
                 slang = Multilingual.findCode( single )
                 if slang then
                 if slang then
                     if alien == "#" then
                     if alien == "-" then
                         r = slang
                         r = slang
                    elseif alien == "#" then
                        r = slang:lower()
                     else
                     else
                         r = Multilingual.getName( slang, alien )
                         r = Multilingual.getName( slang, alien )
Zeile 188: Zeile 231:
                             local cnf = fetch( "Multilingual/config",
                             local cnf = fetch( "Multilingual/config",
                                               true )
                                               true )
                             if cnf then
                             if cnf and
                              type( cnf.getLink ) == "function" then
                                 if not frame then
                                 if not frame then
                                     if not Frame then
                                     if not Frame then
Zeile 294: Zeile 338:
             slang = ask:lower()
             slang = ask:lower()
         end
         end
         fetch( support, true )
         tLang = fetch( support, true )
        tLang = Multilingual.ext.tNames
         if tLang then
         if tLang then
             tLang = tLang[ slang ]
             tLang = tLang[ slang ]
Zeile 321: Zeile 364:
         if not r then
         if not r then
             r = mw.language.fetchLanguageName( ask, slang )
             r = mw.language.fetchLanguageName( ask, slang )
            if r == "" then
                r = false
            end
         end
         end
     else
     else
Anonymer Benutzer