Jump to content
Toggle menu
  • 8 articles
  • 75 files
  • 7 users
  • 37.8K edits
Neodyland Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Linguistic: Difference between revisions

From Neodyland Wiki
ahem
+
Line 2: Line 2:


local p = {}
local p = {}
local f = require('Module:Fallback')
local vowels = 'aeiouyąăẵằẳặȃắâẫấầẩậãäǟāáàȁǎảẚåǻḁạǡæǣǽĕȇêễếềểệḙẽḛëēḕéḗèȅěẻẹęȩḝǝĭȋîĩḭïḯīíìȉǐỉịįıŏȏôỗốồổộõṏṍöōṑóṓòȍǒỏọǫǭơỡớờởợøǿŭȗûṷũṻṹṵüǖǘǜǚṳūúùȕǔủůụųưữứừửựŷỹÿȳýỳỷẙỵ'
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)
function isin(str, pattern)
Line 16: Line 84:
function p.vowelfirst (str)
function p.vowelfirst (str)
return isin(vowels, str[1])  
return isin(vowels, str[1])  
end
function p.wordsep(lang) -- default separator between words
-- language with no separator
if langisin('zh, ja, zh-hans, zh-hant, zh-sg, zh-cn, sh-tw', lang) then
return ''
end
-- default: white space
return ' '
end
end


Line 41: Line 100:
else
else
return noun ' (' .. adj .. ')'
return noun ' (' .. adj .. ')'
end
end
function conj(args)
lang = args.lang
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
end
end
return p
return p

Revision as of 14:08, 22 November 2013

Module documentation[ create · purge ]
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 conj(args)
	lang = args.lang
	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
Cookies help us deliver our services. By using our services, you agree to our use of cookies.