Module:Linguistic

-- some simple internationalization that can be called by other moduleslocalp={}localf=require('Module:Fallback')localvowels='aeiouyąăẵằẳặȃắâẫấầẩậãäǟāáàȁǎảẚåǻḁạǡæǣǽĕȇêễếềểệḙẽḛëēḕéḗèȅěẻẹęȩḝǝĭȋîĩḭïḯīíìȉǐỉịįıŏȏôỗốồổộõṏṍöōṑóṓòȍǒỏọǫǭơỡớờởợøǿŭȗûṷũṻṹṵüǖǘǜǚṳūúùȕǔủůụųưữứừửựŷỹÿȳýỳỷẙỵ'functionwordor(lang)returnf._langSwitch(require('Module:I18n/or'),lang)endfunctioncomma(lang)m=mw.message.newFallbackSequence("comma-separator")m:inLanguage(lang)returnm:plain()endfunctionwordand(lang)localandtable={-- languages with a problem with the MediaWiki:And['pl']=' i',['no']=' og',['zh']='和',['ja']='および'}ifandtable[lang]thenreturnandtable[lang]endm=mw.message.newFallbackSequence("and")m:inLanguage(lang)returnm:plain()endfunctionwordsep(lang)-- default separator between wordsm=mw.message.newFallbackSequence("Word-separator")m:inLanguage(lang)returnm:plain()endfunctionisin(str,pattern)ifstrandpatternandmw.ustring.find(str,pattern,1,true)thenreturntrueendendfunctionlangisin(str,lang)returnisin(str,lang..' ')-- space is necessary to avoid false positives like zh in zh-hansendfunctionprocessgender(str)if(str=='f')or(str=='fem')or(str=='feminine')thenreturn'feminine'elseif(str=='n')or(str=='neutral')thenreturn'neutral'elsereturn'masculine'endendfunctionprocessnumber(str)if(str=='p')or(str=='plural')thenreturn'plural'elsereturn'singular'endendfunctionp.vowelfirst(str)ifstrthenreturnisin(vowels,str[1])endendfunctionp.of(word,lang,raw,gender,number,determiner)-- rough translation of "of" in various languages-- note that the cases when on "of" is employed varies a lot among languages, so it is more prudent to call this from lang specific function onlyifnotrawthenraw=wordendgender=processgender(gender)number=processnumber(number)-- raw is the string without the Wikiformatting so that it correctly analyses the string that is [[:fr:Italie|Italie]] -> 'italie'-- any way to automate this ?-- todo: ca to replace Template:Of/caiflang=='fr'thenifnumber=='plural'thenreturn'des '..wordelseifp.vowelfirst(raw)thenreturn'de l\''..wordelseifgender=='feminine'thenreturn'de la '..wordelseifderterminerthenreturn'du '..wordelsereturn'de '..wordendendendfunctionp.offromwiki(frame)args=frame.argsreturnp.of(args.word,args.lang,args.raw,args.gender,args.number,args.determiner)endfunctionp.noungroup(noun,adj,lang)ifnotnounornoun==''thenreturnnil-- not '' so that it is not counted as a string by mw.listToTextendifnotadjoradj==''thenreturnnounend-- adjective before the nouniflangisin('de de-at de-ch en en-ca en-gb pl zh zh-hans zh-hant zh-my zh-cn zh-sg zh-tw ',lang)thenreturnadj..wordsep(lang)..noun-- adjective after the nounelseiflangisin('fr fr-ca es it')thenreturnnoun..wordsep(lang)..adjelsereturnnoun' ('..adj..')'endendfunctionp.conj(args,lang,conjtype)ifconjtype=='comma'thenreturnmw.text.listToText(args,comma(lang),comma(lang))elseifconjtype=='or'thenreturnmw.text.listToText(args,comma(lang),wordor(lang)..wordsep(lang))elseifconjtype=='explicit or'then-- adds "or" betwen all words when the context can be confusingreturnmw.text.listToText(args,wordor(lang)..wordsep(lang),wordor(lang)..wordsep(lang))elseifconjtypeandconjtype~='and'andconjtype~=''thenreturn'unknown conj type : '..conjtype..'[[Category:Pages with incorrect template usage/Conj|B]]'elsereturnmw.text.listToText(args,comma(lang),wordand(lang)..wordsep(lang))endendfunctionp.conjfromWiki(frame)args=frame.argsifnotargsornotargs[1]thenargs=mw.getCurrentFrame():getParent().argsendlocalconjtype=args.typelocallang=args.langifnotlangormw.text.trim(lang)==''thenlang=frame:preprocess("{{int:lang}}")endnewargs={}-- transform args metatable into a table so it can be concetenatedfori,jinpairs(args)doiftype(i)=='number'thenj=mw.text.trim(j)ifj~=''thentable.insert(newargs,j)endelseifi~='type'andi~='lang'thenreturn'error: bad parameter in template:Conj: '..i..'[[Category:Pages with incorrect template usage/Conj|A]]'endendendreturnp.conj(newargs,lang,conjtype)endreturnp