ผู้ใช้:ZilentFyld/autocreatrule.js
หมายเหตุ: หลังเผยแพร่ คุณอาจต้องล้างแคชเว็บเบราว์เซอร์ของคุณเพื่อดูการเปลี่ยนแปลง
- ไฟร์ฟอกซ์ / ซาฟารี: กด Shift ค้างขณะคลิก Reload หรือกด Ctrl-F5 หรือ Ctrl-R (⌘-R บนแมค)
- กูเกิล โครม: กด Ctrl-Shift-R (⌘-Shift-R บนแมค)
- อินเทอร์เน็ตเอกซ์พลอเรอร์ และ Edge: กด Ctrl ค้างขณะคลิก Refresh หรือกด Ctrl-F5
- โอเปร่า: กด Ctrl-F5
var err = 0
function preset (lang,list,element) {
var word = element.text();
var exp = '';
var preset = {};
/*preset*/
//unfinised: unfinished yet, it will show not support and sent result to console
//name: Thai name
//supportedpos: Supported part of speech
//posset: different text in {{head}}
//replacepos: replace {{head}} ** it is a function and will run with (pageName)
//inflset: will write this infl instead of what it look like
//replaceinfl: replace {{inflection}} ** it is a function and will run with (pageName)
//ignoreposhead: ignore the pos heading, in case of different word type use instead
//reverseinfl: reverse inflection pattern
preset.fr = {
'inflset':{'pp':'past|ptcp','ppr':'pres|ptcp'},
'posset':{'plural':'รูปผันคำนามพหูพจน์'},
'name':'ภาษาฝรั่งเศส',
'supportedpos':['คำนาม','คำคุณศัพท์','คำกริยา'],
'reverseinfl':true
};
preset.en = {
'inflset':{},
'posset':{'plural':'รูปผันคำนามพหูพจน์'},
'replaceinfl':{
'third-person-singular':function(word){return '{{infl of|en|'+word+'||s-verb-form}}'},
'present-participle':function(word){return '{{infl of|en|'+word+'||ing-form}}'},
'simple-past-and-participle':function(word){return '{{infl of|en|'+word+'||ed-form}}'},
'plural':function(word){return '{{plural of|en|'+word+'}}'}
},
'name':'ภาษาอังกฤษ',
'supportedpos':['คำนาม','คำกริยา']
};
preset.de = {
'inflset':{},
'posset':{'plural':'คำนามพหูพจน์'},
'name':'ภาษาเยอรมัน',
'supportedpos':['คำนาม'],
'replaceinfl':{}
};
preset.de.replaceinfl['คำนาม'] = function(word,infl) {
return '{{inflection of|de|'+pageName+'||'+infl.split('-').join('|')+'}}'
}
preset.de.replaceinfl.diminutive = function(word) {
return '{{diminutive of|de|'+pageName+'}}'
}
preset.th = {
'inflset':{},
'posset':{},
'name':'ภาษาไทย',
'supportedpos':['คำกริยา'],
'ignoreposhead':true,
'replacepos':{
'abstract-noun':function(word){return '===คำนาม===\n{{th-noun}}'}
},
'replaceinfl':{
'abstract-noun':function(word){return '{{abstract noun of|th|'+word+'}}'}
}
};
preset.th.pron = function(word) {
var wordpron = $('.th-reading').html()
return '{{th-pron|กาน-'+wordpron+'}}'
}
preset.th.eth = function(word) {
return '{{อุปสรรค|th|การ|'+word+'}}'
}
preset.sv = {
'name' : 'ภาษาสวีเดน',
'supportedpos':['คำนาม','คำกริยา'],
'inflset':{
'sv-indf-nom-sg':'nom|sg|indf',
'sv-defn-nom-sg':'nom|sg|defn',
'sv-indf-nom-pl':'nom|pl|indf',
'sv-defb-nom-pl':'nom|pl|defn',
'sv-indf-gen-sg':'gen|sg|indf',
'sv-defn-gen-sg':'gen|sg|defn',
'sv-indf-gen-pl':'gen|pl|infn',
'sv-defn-gen-pl':'gen|pl|defn',
},
'replaceinfl':{}
}
preset.sv.replaceinfl['คำกริยา'] = function(word,infl) {
return '{{inflection of|sv|'+pageName+'||'+infl.split('-').join('|')+'}}'
}
preset.da = {
'name' : 'ภาษาเดนมาร์ก',
'supportedpos':['คำนาม','คำกริยา'],
'inflset':{
'singular-definite':'s|def',
'plural-indefinite':'p|indef',
'plural-definite':'p|def',
'genitive-singular-indefinite':'gen|s|indef',
'genitive-singular-definite':'gen|s|def',
'genitive-plural-indefinite':'gen|p|indef',
'genitive-plural-definite':'gen|p|def',
},
'replaceinfl':{}
}
preset.da.replaceinfl['คำกริยา'] = function(word,infl) {
return '{{inflection of|da|'+pageName+'||'+infl+'}}'
}
preset.nb = {
'name' : 'ภาษานอร์เวย์แบบบุ๊กมอล',
'supportedpos':['คำนาม'],
'inflset':{
'singular-definite':'s|def',
'plural-indefinite':'p|indef',
'plural-definite':'p|def',
},
'replaceinfl':{}
}
preset.nn = {
'name' : 'ภาษานอร์เวย์แบบนือนอสก์',
'supportedpos':['คำนาม'],
'inflset':{
'singular-definite':'s|def',
'plural-indefinite':'p|indef',
'plural-definite':'p|def',
},
'replaceinfl':{}
}
preset.ru = {
'name':'ภาษารัสเซีย',
'supportedpos':['คำนาม'],
'replaceinfl':{}
}
preset.ru.replaceinfl['คำนาม'] = function(word,infl) {
return '{{inflection of|ru|'+pageName+'||'+infl.split('-').join('|')+'}}'
}
preset.it = {
'name':'ภาษาอิตาลี',
'supportedpos':['คำนาม','คำคุณศัพท์'],
};
preset.la = {
'name':'ภาษาละติน',
'supportedpos':['คำนาม','คำคุณศัพท์']
};
preset.ca = {
'name':'ภาษากาตาลา',
'supportedpos':['คำนาม']
};
//Check-lang
console.log('-- start check-lang --')
if (preset[lang] === undefined) err++;
errcheck()
console.log('supported')
exp += "== " + preset[lang].name + " ==\n\n"
console.log('created header')
//etymology
console.log('-- start creating eth --')
if (preset[lang].pron) {
exp += "=== รากศัพท์ ===\n"
exp += preset[lang].eth(pageName) + '\n\n'
}
//pronounciation
console.log('-- start creating pron --')
if (preset[lang].pron) {
exp += "=== การออกเสียง ===\n"
exp += preset[lang].pron(pageName) + '\n\n'
}
//pos
console.log('-- start put in pos --')
var sortbypos = {'คำนาม':[], 'คำกริยา':[], 'คำคุณศัพท์':[],'คำกริยาวิเศษณ์':[]}
list.forEach(function(e) {
if (preset[lang].supportedpos.includes(e[1])) {
sortbypos[e[1]].push(e[0]);
} else {
err++
}
})
errcheck()
console.log('put in done, look like this:')
console.log(sortbypos)
//eachpos
console.log('-- start creating data for each pos --')
for (var posname in sortbypos) {
var posdata = sortbypos[posname];
console.log('-- creating pos for '+ posname +' --')
if (posdata.length > 0) {
if (!preset[lang].ignoreposhead) {
exp += "=== " + posname + " ===\n"
}
//head
var infl = 'pos-'+posname
if (posdata.length == 1) infl = posdata[0]
//head
console.log('creating head')
if (preset[lang].replacepos && preset[lang].replacepos[infl]) {
exp += preset[lang].replacepos[infl](pageName) + "\n\n"
} else if (preset[lang].posset && preset[lang].posset[infl]) {
exp += "{{head|"+lang+"|"+preset[lang].posset[infl]+"}}\n\n"
} else {
exp += "{{head|"+lang+"|รูปผัน"+posname+"}}\n\n"
}
//data
console.log('creating infl')
posdata.forEach(function(infldata){
var infldatasplit = infldata.split('|')
if (preset[lang].reverseinfl === true){
infldata = infldatasplit.reverse().join('|')
}
if (preset[lang].replaceinfl && preset[lang].replaceinfl[posname]) {
exp += '# '+ preset[lang].replaceinfl[posname](pageName,infldata) + "\n"
} else if (preset[lang].replaceinfl && preset[lang].replaceinfl[infldata]) {
exp += '# '+ preset[lang].replaceinfl[infldata](pageName) + "\n"
} else if (preset[lang].inflset && preset[lang].inflset[infldata]) {
exp += '# {{inflection of|'+lang+'|'+pageName+'||'+preset[lang].inflset[infldata]+'}}\n'
} else {
exp += '# {{inflection of|'+lang+'|'+pageName+'||'+infldata+'}}\n'
}
})
exp += '\n'
} else console.log('skipped');
}
console.log(exp)
if (preset[lang].unfinished === true) return 'error';
return exp
}
function errcheck() {
if (err>0) {
console.log('error here')
return 'error'
}
}