Modul:Multilingual: Unterschied zwischen den Versionen
2019-11-02
w>PerfektesChaos (2019-11-01) |
w>PerfektesChaos (2019-11-02) |
||
| Zeile 1: | Zeile 1: | ||
local Multilingual = { suite = "Multilingual", | local Multilingual = { suite = "Multilingual", | ||
serial = "2019-11- | serial = "2019-11-02", | ||
item = 47541920, | item = 47541920, | ||
globals = { ISO15924 = 71584769, | globals = { ISO15924 = 71584769, | ||
WLink = 19363224 } | WLink = 19363224 } | ||
} | } | ||
--[=[ | |||
Utilities for multilingual texts and ISO 639 (BCP47) issues etc. | |||
* fair() | |||
* fallback() | |||
* findCode() | |||
* fix() | |||
* format() | |||
* getBase() | |||
* getLang() | |||
* getName() | |||
* i18n() | |||
* int() | |||
* isLang() | |||
* isLangWiki() | |||
* isMinusculable() | |||
* isRTL() | |||
* message() | |||
* sitelink() | |||
* userLang() | |||
* userLangCode() | |||
* wikibase() | |||
loadData: Multilingual/config Multilingual/names | |||
]=] | |||
local Failsafe = Multilingual | local Failsafe = Multilingual | ||
local GlobalMod = Multilingual | local GlobalMod = Multilingual | ||
| Zeile 167: | Zeile 190: | ||
if not got and got ~= false then | if not got and got ~= false then | ||
local global = Multilingual.globals[ access ] | local global = Multilingual.globals[ access ] | ||
got = foreignModule( access, | local lib = ( not append or append == "config" ) | ||
got = foreignModule( access, lib, append, global ) | |||
if type( got ) == "table" then | if type( got ) == "table" then | ||
if | if lib then | ||
local startup = got[ access ] | local startup = got[ access ] | ||
if type( startup ) == "function" then | if type( startup ) == "function" then | ||
| Zeile 205: | Zeile 229: | ||
local f, lucky, s | local f, lucky, s | ||
Multilingual.tmplLang = template | Multilingual.tmplLang = template | ||
if type( source ) ~= "string" | if type( source ) ~= "string" and | ||
type( template.namePat ) == "string" and | |||
template.namePat:find( "%s", 1, true ) then | |||
source = string.format( template.namePat, access ) | |||
end | end | ||
if type( source ) == "string" then | if type( source ) == "string" then | ||
| Zeile 744: | Zeile 767: | ||
Multilingual.getScriptName = function ( assigned, alien, add ) | Multilingual.getScriptName = function ( assigned, alien, add ) | ||
-- OBSOLETE | |||
-- Retrieve script name, hopefully linked | -- Retrieve script name, hopefully linked | ||
-- Precondition: | -- Precondition: | ||
| Zeile 883: | Zeile 907: | ||
-- Postcondition: | -- Postcondition: | ||
-- Returns boolean | -- Returns boolean | ||
local r | local r = true | ||
if ask then | if ask then | ||
local cnf = fetch( "Multilingual", "config" ) | local cnf = fetch( "Multilingual", "config" ) | ||
| Zeile 905: | Zeile 929: | ||
return r | return r | ||
end -- Multilingual.isMinusculable() | end -- Multilingual.isMinusculable() | ||
Multilingual.isRTL = function ( ask ) | |||
-- Check whether language is written right-to-left | |||
-- Precondition: | |||
-- ask -- string, with language (or script) code | |||
-- Returns true, if right-to-left | |||
local r | |||
Multilingual.rtl = Multilingual.rtl or { } | |||
r = Multilingual.rtl[ ask ] | |||
if type( r ) ~= "boolean" then | |||
local bib = fetch( "ISO15924" ) | |||
if type( bib ) == "table" and | |||
type( bib.isRTL ) == "function" then | |||
r = bib.isRTL( ask ) | |||
else | |||
r = mw.language.new( ask ):isRTL() | |||
end | |||
Multilingual.rtl[ ask ] = r | |||
end | |||
return r | |||
end -- Multilingual.isRTL() | |||
Multilingual.isTrans = function ( ask, assign, about ) | Multilingual.isTrans = function ( ask, assign, about ) | ||
-- OBSOLETE | |||
-- Check whether valid transcription for context | -- Check whether valid transcription for context | ||
-- Precondition: | -- Precondition: | ||
| Zeile 1.350: | Zeile 1.398: | ||
-- Could this be a Wiki language version? | -- Could this be a Wiki language version? | ||
-- 1 -- code | -- 1 -- code | ||
-- Returns non-empty, if possibly language version | |||
local s = mw.text.trim( frame.args[ 1 ] or "" ) | local s = mw.text.trim( frame.args[ 1 ] or "" ) | ||
local lucky, r = pcall( Multilingual.isLangWiki, s ) | local lucky, r = pcall( Multilingual.isLangWiki, s ) | ||
return r and "1" or "" | return r and "1" or "" | ||
end -- p.isLangWiki | end -- p.isLangWiki | ||
p.isRTL = function ( frame ) | |||
-- Check whether language is written right-to-left | |||
-- 1 -- string, with language code | |||
-- Returns non-empty, if right-to-left | |||
local s = mw.text.trim( frame.args[ 1 ] or "" ) | |||
return Multilingual.isRTL( s ) and "1" or "" | |||
end -- p.isRTL() | |||