Module:Linguistic: Difference between revisions
From Neodyland Wiki
More actions
m |
harmonize |
||
| Line 65: | Line 65: | ||
end | end | ||
function | function wordsep(lang) -- default separator between words | ||
m = mw.message.newFallbackSequence( "Word-separator" ) | m = mw.message.newFallbackSequence( "Word-separator" ) | ||
m:inLanguage(lang) | m:inLanguage(lang) | ||
Revision as of 14:38, 22 November 2013
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 wordor(lang)
return 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'] = '或',
})
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 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)
args = frame.args
lang = args.lang
if not lang or lang == '' then
lang = frame:preprocess( "{{int:lang}}" )
end
newargs = {} -- transform args metatable into a table so it can be concetenated
args.lang = nil
for i, j in pairs(args) do
if j ~= '' then
table.insert(newargs, j)
end
end
args = newargs
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) .. wordsep(lang))
else
return mw.text.listToText(args, comma(lang), wordand(lang) .. wordsep(lang))
end
end
return p