Module:Linguistic
From Neodyland Wiki
More actions
This documentation is transcluded from Module:Linguistic/doc.
-- some simple internationalization that can be called by other modules
local p = {}
local f = require('Module:Fallback')
local vowels = 'aeiouyąăẵằẳặȃắâẫấầẩậãäǟāáàȁǎảẚåǻḁạǡæǣǽĕȇêễếềểệḙẽḛëēḕéḗèȅěẻẹęȩḝǝĭȋîĩḭïḯīíìȉǐỉịįıŏȏôỗốồổộõṏṍöōṑóṓòȍǒỏọǫǭơỡớờởợøǿŭȗûṷũṻṹṵüǖǘǜǚṳūúùȕǔủůụųưữứừửựŷỹÿȳýỳỷẙỵ'
function wordord(lang)
wordor = f.langSwitch({
['lang'] = lang,
['ar'] = 'أو',
['ca'] = 'o',
['cs'] = 'nebo',
['da'] = 'eller',
['de'] = 'oder',
['el'] = 'ή',
['en'] = 'or',
['eo'] = 'aŭ',
['et'] = 'või',
['fa'] = 'یا',
['fi'] = 'tai',
['fr'] = 'ou',
['gl'] = 'ou',
['he'] = 'או',
['hu'] = 'vagy',
['it'] = 'o',
['ja'] = 'または',
['mk'] = 'или',
['ml'] = 'അഥവാ',
['nds'] = 'oder',
['nl'] = 'of',
['nn'] = 'eller',
['no'] = 'eller',
['os'] = 'ó',
['pl'] = 'lub',
['pt'] = 'ou',
['pt-br'] = 'ou',
['ru'] = 'или',
['sl'] = 'ali',
['sv'] = 'eller',
['tg'] = 'ё',
['th'] = 'หรือ',
['tr'] = 've',
['zh'] = '或',
})
return wordor
end
function comma(lang)
m = mw.message.newFallbackSequence( "comma-separator" )
m:inLanguage(lang)
return m:plain()
end
function wordand(lang)
local andtable = { -- languages with a problem with the MediaWiki:And
['pl'] = 'i',
['no'] = 'og',
['zh'] = '和'
}
if andtable[lang] then
return andtable[lang]
end
m = mw.message.newFallbackSequence( "and" )
m:inLanguage(lang)
return m:plain()
end
function p.wordsep(lang) -- default separator between words
m = mw.message.newFallbackSequence( "Word-separator" )
m:inLanguage(lang)
return m:plain()
end
function isin(str, pattern)
if mw.ustring.find(str, pattern, 1, true ) then
return true
end
end
function langisin(str, lang)
return isin(str, lang .. ',') -- comma is necessary to avoid false positives like zh in zh-hans
end
function p.vowelfirst (str)
return isin(vowels, str[1])
end
function p.noungroup(noun, adj, lang)
if not noun then
return nil end
if not adj
then return noun
end
-- adjective before the noun
if langisin('de, de-at, de-ch, en, en-ca, en-gb, zh ', lang) then
return adj .. p.wordsep(lang) .. noun
-- adjective after the noun
elseif langisin('fr, fr-ca, it') then
return noun .. p.wordsep(lang) .. adj
else
return noun ' (' .. adj .. ')'
end
end
function p.conj(frame)
if frame then
args = frame.args
else
args = mw.getCurrentFrame().args
end
lang = args.lang
if not lang or lang == '' then
lang = frame:preprocess( "{{int:lang}}" )
end
if args.type == 'comma' then
return mw.text.listToText(args, comma(lang), comma(lang))
elseif args.type == 'or' then
return mw.text.listToText(args, comma(lang), wordor(lang))
else
return mw.text.listToText(args, comma(lang), wordand(lang))
end
end
return p