Modul:Multilingual: Unterschied zwischen den Versionen
2018-12-27
w>PerfektesChaos (2018-12-25) |
w>PerfektesChaos (2018-12-27) |
||
| Zeile 1: | Zeile 1: | ||
local Multilingual = { suite = "Multilingual", | local Multilingual = { suite = "Multilingual", | ||
serial = "2018-12- | serial = "2018-12-27", | ||
item = 47541920 } | item = 47541920 } | ||
local User = { sniffer = "publishchanges" } | local User = { sniffer = "publishchanges" } | ||
| Zeile 63: | Zeile 63: | ||
-- access -- module title | -- access -- module title | ||
-- allow -- permit non-existence | -- allow -- permit non-existence | ||
-- ahead -- name of startup procedure, if not access | -- ahead -- name of startup procedure, if not access; | ||
-- false for mw.loadData | |||
-- Postcondition: | -- Postcondition: | ||
-- Returns table or false, with library | -- Returns table or false, with library | ||
| Zeile 72: | Zeile 73: | ||
if Multilingual.ext[ access ] == false then | if Multilingual.ext[ access ] == false then | ||
elseif not Multilingual.ext[ access ] then | elseif not Multilingual.ext[ access ] then | ||
local lucky, got = pcall( require, | local src = "Module:" .. access | ||
local lucky, got | |||
if ahead == false then | |||
lucky, got = pcall( mw.loadData, src ) | |||
else | |||
lucky, got = pcall( require, src ) | |||
end | |||
Multilingual.ext[ access ] = false | Multilingual.ext[ access ] = false | ||
if type( got ) == "table" then | if type( got ) == "table" then | ||
| Zeile 701: | Zeile 708: | ||
return r | return r | ||
end -- Multilingual.isMinusculable() | end -- Multilingual.isMinusculable() | ||
Multilingual.isTrans = function ( ask, assign, about ) | |||
-- Check whether valid transcription for context | |||
-- ask -- string, with transcription key | |||
-- assign -- string, with language or scripting code | |||
-- about -- string or nil, with site scripting code | |||
-- Returns boolean | |||
local r = false | |||
local t | |||
if type( Multilingual.trans ) ~= "table" then | |||
t = fetch( "Multilingual/scripts", true, false ) | |||
if type( t ) == "table" then | |||
Multilingual.trans = t.trans or { } | |||
else | |||
Multilingual.trans = { } | |||
end | |||
end | |||
t = Multilingual.trans[ assign ] | |||
if type( t ) == "table" then | |||
for k, v in pairs( t ) do | |||
if v == ask then | |||
r = true | |||
break -- for i | |||
end | |||
end -- for k, v | |||
end | |||
if not r and about == "Latn" then | |||
r = ( ask == "BGN-PCGN" or ask == "ALA-LC" ) | |||
end | |||
return r | |||
end -- Multilingual.isTrans() | |||
| Zeile 819: | Zeile 859: | ||
-- Format language code | -- Format language code | ||
-- 1 -- language code | -- 1 -- language code | ||
local s = mw.text.trim( frame.args[ 1 ] or "" ) | |||
return Multilingual.fair( s ) or "" | |||
end -- p.fair | end -- p.fair | ||
| Zeile 828: | Zeile 869: | ||
-- 1 -- language version specifier to be supported | -- 1 -- language version specifier to be supported | ||
-- 2 -- language specifier of a possible replacement | -- 2 -- language specifier of a possible replacement | ||
local | local s1 = mw.text.trim( frame.args[ 1 ] or "" ) | ||
return | local s2 = mw.text.trim( frame.args[ 2 ] or "" ) | ||
return Multilingual.fallback( s1, s2 ) and "1" or "" | |||
end -- p.fallback | end -- p.fallback | ||
| Zeile 837: | Zeile 879: | ||
-- Retrieve language code from language name | -- Retrieve language code from language name | ||
-- 1 -- name in current project language | -- 1 -- name in current project language | ||
local s = mw.text.trim( frame.args[ 1 ] or "" ) | |||
return Multilingual.findCode( s ) or "" | |||
end -- p.findCode | end -- p.findCode | ||
| Zeile 888: | Zeile 931: | ||
-- Retrieve base language from possibly combined ISO language code | -- Retrieve base language from possibly combined ISO language code | ||
-- 1 -- code | -- 1 -- code | ||
local s = mw.text.trim( frame.args[ 1 ] or "" ) | |||
return Multilingual.getBase( s ) or "" | |||
end -- p.getBase | end -- p.getBase | ||
| Zeile 900: | Zeile 944: | ||
-- * -- native | -- * -- native | ||
-- any valid code | -- any valid code | ||
local s = mw.text.trim( frame.args[ 1 ] or "" ) | |||
local slang = frame.args[ 2 ] | local slang = frame.args[ 2 ] | ||
local r | local r | ||
| Zeile 905: | Zeile 950: | ||
slang = mw.text.trim( slang ) | slang = mw.text.trim( slang ) | ||
end | end | ||
r = Multilingual.getName( | r = Multilingual.getName( s, slang ) | ||
return r or "" | return r or "" | ||
end -- p.getName | end -- p.getName | ||
| Zeile 915: | Zeile 960: | ||
-- 1 -- code | -- 1 -- code | ||
-- 2 -- optional additional key | -- 2 -- optional additional key | ||
local s1 = mw.text.trim( frame.args[ 1 ] or "????" ) | |||
local s2 = frame.args[ 2 ] | |||
if s2 then | |||
s2 = mw.text.trim( s2 ) | |||
end | |||
return Multilingual.getScriptName( s1, false, s2 ) | |||
end -- p.getScriptName | end -- p.getScriptName | ||
| Zeile 968: | Zeile 1.016: | ||
-- Could this be an ISO language code? | -- Could this be an ISO language code? | ||
-- 1 -- code | -- 1 -- code | ||
local lucky, r = pcall( Multilingual.isLang, | local s = mw.text.trim( frame.args[ 1 ] or "" ) | ||
local lucky, r = pcall( Multilingual.isLang, s ) | |||
return r and "1" or "" | return r and "1" or "" | ||
end -- p.isLang | end -- p.isLang | ||
| Zeile 978: | Zeile 1.026: | ||
-- Could this be a Wiki language version? | -- Could this be a Wiki language version? | ||
-- 1 -- code | -- 1 -- code | ||
local lucky, r = pcall( Multilingual.isLangWiki, | local s = mw.text.trim( frame.args[ 1 ] or "" ) | ||
local lucky, r = pcall( Multilingual.isLangWiki, s ) | |||
return r and "1" or "" | return r and "1" or "" | ||
end -- p.isLangWiki | end -- p.isLangWiki | ||
| Zeile 985: | Zeile 1.033: | ||
p. | p.isTrans = function ( frame ) | ||
-- | -- Check whether valid transcription for context | ||
-- 1 -- code | -- 1 -- string, with transcription key | ||
local | -- 2 -- string, with language or scripting code | ||
return | -- site -- string or nil, with site scripting code | ||
end -- p. | local s1 = mw.text.trim( frame.args[ 1 ] or "" ) | ||
local s2 = mw.text.trim( frame.args[ 2 ] or "" ) | |||
local site = mw.text.trim( frame.args.site or "" ) | |||
return Multilingual.isTrans( s1, s2, site ) and "1" or "" | |||
end -- p.isTrans | |||
| Zeile 997: | Zeile 1.049: | ||
-- Which language does the current user prefer? | -- Which language does the current user prefer? | ||
-- 1 -- space separated list of available ISO 639 codes | -- 1 -- space separated list of available ISO 639 codes | ||
local s = mw.text.trim( frame.args[ 1 ] or "" ) | |||
return Multilingual.userLang( s, frame ) | |||
end -- p.userLang | end -- p.userLang | ||