Usuari:Vriullop/creationrules.js
Nota: Després de publicar, possiblement necessitareu refrescar la memòria cau del vostre navegador per a veure'n els canvis.
- Firefox / Safari: Premeu Majús i alhora cliqueu el botó Actualitzar, o pressioneu Ctrl+F5 o Ctrl+R (⌘+R en un Mac)
- Google Chrome: Premeu Ctrl+Majús+R (⌘+Shift+R en un Mac)
- Internet Explorer / Edge: Premeu Ctrl i alhora cliqueu a Actualitza o pressioneu Ctrl+F5
- Opera: Premeu Ctrl-F5.
// Adaptat de en:User:Conrad.Irwin/creationrules.js
//<br />
//<nowiki>This prevents the parser from processing the file and generating transclusions and categories for it.
/*
* Language-specific entry generation rules for form-of entries, generated by [[WT:ACCEL]].
*
* Each function has two parameters.
* params holds the parameters given in the template.
* entry holds the various parts of the entry to be created.
*
* The function's task is to provide new values for some of the parts of the new entry.
* In most cases, entry.def (the definition line) will be overridden, but the headword (entry.head)
* or even the part-of-speech or language headers can be overridden if necessary.
*
* If the function is not able to handle the current form for whatever reason, throw an exception:
* throw new PreloadTextError();
*/
window.creation_rules = window.creation_rules || {};
// Generate the entry's text
window.generate_entry = function (params)
{
try
{
var param = params.lang;
if (!creation_rules[param])
param = 'others';
pos = params.pos;
var entry = {
lang_header: '{' + '{-' + params.lang + '-}}',
pronunc: null,
pos_header: params.pos.charAt(0).toUpperCase() + params.pos.substr(1),
head: '{{entrada|' + params.lang + '|' + pos + '-forma' + (params.target != params.target_pagename ? '|lema=' + params.target : '') + (params.transliteration ? ('|tr=' + params.transliteration) : '') + '}}',
def: null,
inflection: null,
declension: null,
conjugation: null,
sil: null };
creation_rules[param](params, entry);
return entry;
}
catch (e)
{
if (e instanceof PreloadTextError)
{
console.log(e.message);
return false;
}
else
{
throw e;
}
}
};
getVowels = function (str) {
var v = str.match(/[aàeèéiíïoòóuúü]/gi);
return v === null ? 0 : v.length;
};
// Català
creation_rules.ca =
function (params, entry)
{
var template = {
'plural':'forma-p',
'femenina': 'forma-f',
'alternativa':'forma-a'};
if (!template[params.form])
throw new PreloadTextError('Cap regla per "' + params.form + '" en llengua "' + params.lang + '".');
if (!params.target.match(/^[^ ]+ [^ ]/))
{
entry.pronunc = '{' + '{ca-pron}}';
if (getVowels(params.target) > 1)
entry.sil = '{' + '{ca-sil}}';
}
switch (params.pos)
{
case 'adjectiu':
entry.head = '{' + '{ca-adj-forma|' + params.gender + (params.form == 'plural' ? 'p' : '') + '}}';
break;
case 'nom':
entry.head = '{' + '{ca-nom-forma|' + params.gender + (params.form == 'plural' ? 'p' : '') + '}}';
break;
default:
entry.head = '{' + '{entrada|' + params.lang + '|' + params.pos + '}}';
}
entry.def = '{' + '{' + template[params.form] + '|' + params.lang + '|' + params.origin + '}}';
};
// Català medieval
creation_rules['roa-oca'] =
function (params, entry)
{
var template = {
'plural':'forma-p',
'femenina': 'forma-f'};
if (!template[params.form])
throw new PreloadTextError('Cap regla per "' + params.form + '" en llengua "' + params.lang + '".');
switch (params.pos)
{
default:
entry.head = '{' + '{entrada|' + params.lang + '|' + params.pos + '-forma}}';
}
entry.def = '{' + '{' + template[params.form] + '|' + params.lang + '|' + params.origin + '}}';
};
// Alemany
creation_rules.de =
function (params, entry)
{
if (params.form == 'trad')
{
switch (params.pos)
{
case 'adjectiu':
entry.head = '{' + '{de-adj' + '}}';
break;
case 'nom':
entry.head = '{' + '{de-nom|' + (params.gender ? params.gender : '?') + '}}';
break;
default:
entry.head = '{' + '{entrada|' + params.lang + '|' + params.pos + '}}';
}
entry.def = '[' + '[' + params.origin + ']]';
} else
{
var template = {
'plural':'forma-p',
'genitiu': 'forma-decl',
'diminutiva':'forma-|diminutiva',
'comparativa':'forma-comp',
'superlativa':'forma-super'};
if (!template[params.form])
throw new PreloadTextError('Cap regla per "' + params.form + '" en llengua "' + params.lang + '".');
switch (params.pos)
{
case 'adjectiu':
entry.head = '{' + '{entrada|de|adj-forma' + '}}';
break;
case 'nom':
entry.head = '{' + '{entrada|de|nom-forma' + '}}';
break;
default:
entry.head = '{' + '{entrada|' + params.lang + '|' + params.pos + '}}';
}
entry.def = '{' + '{' + template[params.form] + '|' + params.lang + '|' + params.origin;
if (params.form == 'genitiu')
{
entry.def += '|gen|s';
}
entry.def += '}}';
}
};
// Amazic marroquí
creation_rules.zgh =
function (params, entry)
{
var template = {
'annexió':"forma-estat-a",
'plural':'forma-p',
'femenina': 'forma-f'};
if (!template[params.form])
throw new PreloadTextError('Cap regla per "' + params.form + '" en llengua "' + params.lang + '".');
if (!params.target.match(/^[^ ]+ [^ ]/))
entry.pronunc = '{' + '{' + params.lang + '-pron}}';
switch (params.pos)
{
default:
entry.head = '{' + '{entrada|' + params.lang + '|' + params.pos + '-forma}}';
}
entry.def = '{' + '{' + template[params.form] + '|' + params.lang + '|' + params.origin + '}}';
};
// Anglès
creation_rules.en =
function (params, entry)
{
if (params.form == 'trad')
{
switch (params.pos)
{
case 'adjectiu':
entry.head = '{' + '{en-adj}}'; break;
case 'adverbi':
entry.head = '{' + '{en-adv}}'; break;
case 'nom':
entry.head = '{' + '{en-nom}}'; break;
case 'verb':
entry.head = '{' + '{en-verb}}'; break;
default:
entry.head = '{' + '{entrada|' + params.lang + '|' + params.pos + '}}';
}
entry.def = '[' + '[' + params.origin + ']]';
} else
{
var template = {
'plural':'forma-p',
'comparativa': 'forma-comp',
'superlativa':'forma-super'};
if (!template[params.form])
throw new PreloadTextError('Cap regla per "' + params.form + '" en llengua "' + params.lang + '".');
switch (params.pos)
{
case 'adjectiu':
entry.head = '{' + '{entrada|' + params.lang + '|adj-forma}}'; break;
case 'adverbi':
entry.head = '{' + '{entrada|' + params.lang + '|adv-forma}}'; break;
case 'nom':
entry.head = '{' + '{entrada|' + params.lang + '|nom-forma}}'; break;
default:
entry.head = '{' + '{entrada|' + params.lang + '|' + params.pos + '}}';
}
entry.def = '{' + '{' + template[params.form] + '|' + params.lang + '|' + params.origin + '}}';
}
};
// Basc
creation_rules.eu =
function (params, entry)
{
if (params.form == 'trad')
{
switch (params.pos)
{
case 'nom':
if (!params.target.match(/^[^ ]+ [^ ]/))
entry.head = '{' + '{eu-nom|' + (params.gender ? params.gender : '?') + '}}';
else
entry.head = '{' + '{entrada|' + params.lang + '|' + params.pos + '}}';
break;
default:
entry.head = '{' + '{entrada|' + params.lang + '|' + params.pos + '}}';
}
entry.def = '[' + '[' + params.origin + ']]';
}
};
// Castellà
creation_rules.es =
function (params, entry)
{
if (!params.target.match(/^[^ ]+ [^ ]/))
{
entry.pronunc = '{' + '{es-pron}}';
if (getVowels(params.target) > 1)
entry.sil = '{' + '{es-sil}}';
}
if (params.form == 'trad')
{
switch (params.pos)
{
case 'adjectiu':
entry.head = '{' + '{es-adj' + (params.gender ? '|' + params.gender : '') + '}}';
break;
case 'nom':
entry.head = '{' + '{es-nom|' + (params.gender ? params.gender : '?') + '}}';
break;
case 'verb':
entry.head = '{' + '{es-verb}}';
break;
default:
entry.head = '{' + '{entrada|' + params.lang + '|' + params.pos + '}}';
}
entry.def = '[' + '[' + params.origin + ']]';
} else
{
var template = {
'plural':'forma-p',
'femenina': 'forma-f',
'alternativa':'forma-a'};
if (!template[params.form])
throw new PreloadTextError('Cap regla per "' + params.form + '" en llengua "' + params.lang + '".');
switch (params.pos)
{
case 'adjectiu':
entry.head = '{' + '{es-adj-forma|' + params.gender + (params.form == 'plural' ? 'p' : '') + '}}';
break;
case 'nom':
entry.head = '{' + '{es-nom-forma|' + params.gender + (params.form == 'plural' ? 'p' : '') + '}}';
break;
default:
entry.head = '{' + '{entrada|' + params.lang + '|' + params.pos + '}}';
}
entry.def = '{' + '{' + template[params.form] + '|' + params.lang + '|' + params.origin + '}}';
}
};
// Esperanto
creation_rules.eo =
function (params, entry)
{
if (!params.target.match(/^[^ ]+ [^ ]/))
entry.pronunc = '{' + '{' + params.lang + '-pron}}';
entry.head = '{' + '{eo-entrada}}';
if (params.form == 'trad')
{
if (params.pos == 'preposició')
entry.head = '{' + '{entrada|eo|prep}}';
entry.def = '[' + '['+params.origin + ']]';
} else
{
entry.def = '{' + '{eo-forma}}';
}
};
// Francès
creation_rules.fr =
function (params, entry)
{
if (params.form == 'trad')
{
switch (params.pos)
{
case 'adjectiu':
entry.head = '{' + '{fr-adj' + (params.gender ? '|' + params.gender : '') + '}}';
break;
case 'nom':
entry.head = '{' + '{fr-nom|' + (params.gender ? params.gender : '?') + '}}';
break;
default:
entry.head = '{' + '{entrada|' + params.lang + '|' + params.pos + '}}';
}
entry.def = '[' + '[' + params.origin + ']]';
} else
{
var template = {
'plural':'forma-p',
'femenina': 'forma-f',
'alternativa':'forma-a'};
if (!template[params.form])
throw new PreloadTextError('Cap regla per "' + params.form + '" en llengua "' + params.lang + '".');
switch (params.pos)
{
case 'adjectiu':
entry.head = '{' + '{fr-adj-forma|' + params.gender + (params.form == 'plural' ? 'p' : '') + '}}';
break;
case 'nom':
entry.head = '{' + '{fr-nom-forma|' + params.gender + (params.form == 'plural' ? 'p' : '') + '}}';
break;
default:
entry.head = '{' + '{entrada|' + params.lang + '|' + params.pos + '}}';
}
entry.def = '{' + '{' + template[params.form] + '|' + params.lang + '|' + params.origin + '}}';
}
};
// Gallec
creation_rules.gl =
function (params, entry)
{
if (params.form == 'trad')
{
switch (params.pos)
{
case 'nom':
entry.head = '{' + '{gl-nom|' + (params.gender ? params.gender : '?') + '}}';
break;
default:
entry.head = '{' + '{entrada|' + params.lang + '|' + params.pos + '}}';
}
entry.def = '[' + '[' + params.origin + ']]';
} else
{
var template = {
'plural':'forma-p',
'femenina': 'forma-f'};
if (!template[params.form])
throw new PreloadTextError('Cap regla per "' + params.form + '" en llengua "' + params.lang + '".');
switch (params.pos)
{
case 'adjectiu':
entry.head = '{' + '{entrada|' + params.lang + '|adj-forma}}';
break;
case 'nom':
entry.head = '{' + '{gl-nom-forma|' + params.gender + (params.form == 'plural' ? 'p' : '') + '}}';
break;
default:
entry.head = '{' + '{entrada|' + params.lang + '|' + params.pos + '}}';
}
entry.def = '{' + '{' + template[params.form] + '|' + params.lang + '|' + params.origin + '}}';
}
};
// Italià
creation_rules.it =
function (params, entry)
{
if (!params.target.match(/^[^ ]+ [^ ]/))
{
entry.pronunc = '{' + '{it-pron}}';
if (getVowels(params.target) > 1)
entry.sil = '{' + '{it-sil}}';
}
if (params.form == 'trad')
{
switch (params.pos)
{
case 'adjectiu':
entry.head = '{' + '{it-adj' + (params.gender ? '|' + params.gender : '') + '}}';
break;
case 'nom':
entry.head = '{' + '{it-nom|' + (params.gender ? params.gender : '?') + '}}';
break;
case 'verb':
entry.head = '{' + '{it-verb}}';
break;
default:
entry.head = '{' + '{entrada|' + params.lang + '|' + params.pos + '}}';
}
entry.def = '[' + '[' + params.origin + ']]';
} else
{
var template = {
'plural':'forma-p',
'femenina': 'forma-f',
'alternativa':'forma-a'};
if (!template[params.form])
throw new PreloadTextError('Cap regla per "' + params.form + '" en llengua "' + params.lang + '".');
switch (params.pos)
{
case 'adjectiu':
entry.head = '{' + '{it-adj-forma|' + params.gender + (params.form == 'plural' ? 'p' : '') + '}}';
break;
case 'nom':
entry.head = '{' + '{it-nom-forma|' + params.gender + (params.form == 'plural' ? 'p' : '') + '}}';
break;
default:
entry.head = '{' + '{entrada|' + params.lang + '|' + params.pos + '}}';
}
entry.def = '{' + '{' + template[params.form] + '|' + params.lang + '|' + params.origin + '}}';
}
};
// Occità
creation_rules.oc =
function (params, entry)
{
if (!params.target.match(/^[^ ]+ [^ ]/))
entry.pronunc = '{' + '{' + params.lang + '-pron}}';
if (params.form == 'trad')
{
switch (params.pos)
{
case 'adjectiu':
entry.head = '{' + '{oc-adj' + (params.gender ? '|' + params.gender : '') + '}}';
break;
case 'nom':
entry.head = '{' + '{oc-nom|' + (params.gender ? params.gender : '?') + '}}';
break;
default:
entry.head = '{' + '{entrada|' + params.lang + '|' + params.pos + '}}';
}
entry.def = '[' + '[' + params.origin + ']]';
} else
{
var template = {
'plural':'forma-p',
'femenina': 'forma-f'};
if (!template[params.form])
throw new PreloadTextError('Cap regla per "' + params.form + '" en llengua "' + params.lang + '".');
switch (params.pos)
{
case 'adjectiu':
entry.head = '{' + '{oc-adj-forma|' + params.gender + (params.form == 'plural' ? 'p' : '') + '}}';
break;
case 'nom':
entry.head = '{' + '{oc-nom-forma|' + params.gender + (params.form == 'plural' ? 'p' : '') + '}}';
break;
default:
entry.head = '{' + '{entrada|' + params.lang + '|' + params.pos + '}}';
}
entry.def = '{' + '{' + template[params.form] + '|' + params.lang + '|' + params.origin + '}}';
}
};
// Romanès
creation_rules.ro =
function (params, entry)
{
if (params.form == 'trad')
{
switch (params.pos)
{
case 'nom':
entry.head = '{' + '{ro-nom|' + (params.gender ? params.gender : '?') + '|?}}';
break;
default:
entry.head = '{' + '{entrada|' + params.lang + '|' + params.pos + (params.gender ? '|g=' + params.gender : '') + '}}';
}
entry.def = '[' + '[' + params.origin + ']]';
}
};
// Suec
creation_rules.sv =
function (params, entry)
{
var template = {
'present':"present|act",
'past':'passat|act',
'supine': 'supí|act',
'imperative': 'imperatiu'};
if (!template[params.form])
throw new PreloadTextError('Cap regla per "' + params.form + '" en llengua "' + params.lang + '".');
switch (params.pos)
{
default:
entry.head = '{' + '{entrada|' + params.lang + '|' + params.pos + '-forma}}';
}
entry.def = '{' + '{forma-conj|' + params.lang + '|' + params.origin + '|' + template[params.form] + '}}';
};
// Altres
creation_rules.others =
function (params, entry)
{
if (params.form == 'trad')
{
entry.head = '{' + '{entrada|' + params.lang + '|' + params.pos + '}}';
entry.def = '[' + '[' + params.origin + ']]';
}
else
{
throw new PreloadTextError('Cap regla per la llengua "' + params.lang + '".');
}
};