Content deleted Content added
Ohconfucius (talk | contribs) U.S.A. to USA |
Ohconfucius (talk | contribs) Undid revision 1299042620 by Ohconfucius (talk) |
||
(13 intermediate revisions by the same user not shown) | |||
Line 31:
},
{
category: 'EngvarB', name: '
ohc_ENGVAR_set_variation(editor, "B");
}
Line 137:
protect_string(/((?:analy|iri|peni)ses)/gi);
protect_string(/(World Health Organization)/gi);
protect_string(/(Royal Space Force: The Wings of Honnêamise)/g);
// protect from hyphenation
Line 188 ⟶ 189:
// old-fashioned
// hyphenation
Line 228 ⟶ 229:
'maneuver(ab|ed|ing)': '$1manoeuvr$2',
'maneuver': '$1manoeuvre',
'meager': '$1meagre',
'louve(red|ring)': '$1louv$2',
'(louv|somb)er': '$1$2re',
Line 288 ⟶ 290:
// '~l' words where the 'l' doubles as past and present participle
'((?:\\w{3,9}[-–—]|)(?:fu|pan))el(e[dr]|ist|ing)': '$1$2ell$3',
'(bev|canc|couns|fu|jew|lab|lev|marv|mod|
'([a-zA-Z]{2,8}[^eglpstz ])el(e[dr]|est|ing)(\\b)': '$1$2ell$3$4', // added 'p' to avoid changing of "misspelling"
'(app|di|enthr|equ|initi|journ|riv|sign|tot)al(e[dr]|ing)': '$1$2all$3' // appalled/appalling is also American
Line 345 ⟶ 347:
// remove ambiguous pound sign; rem incidental intervening space
editor.replace(/₤ ?(\d)/g, '£$1');
editor.replace(/\b(vice) (president|chairman|chancellor|minister)/gi, '$1-$2');
}
function ohc_ENGVAR_simple_c(editor) {
var table = {
'ageing': '$1aging',
'aluminum': '$1aluminium',
'adrenalin(\\b)': '$1adrenaline$2',
'annex(\\b)': '$1annexe$2',
'(ana|breatha|cata|hydro|para)lyz(e|ing)': '$1$2lys$3',
'bau(lk)': '$1ba$2',
'(de|of)fense': '$1$2fence',
'license': '$1licence',
'(licen)c(ing|ed)': '$1$2s$3',
'percent(\\b)': '$1per cent$2',
'(practi)s(ing|ed)': '$1$2c$3',
'furor(\\b)': '$1furore$2',
Line 399 ⟶ 402:
// 'f' words
//'(S|s)ulfur': '$1$2ulphur', //disabled per WP:
'anymore': '$1any more',
Line 426 ⟶ 429:
// '~l' words where the 'l' doubles as past and present participle
'((?:\\w{3,9}[-–—]|)(?:fu|pan))el(e[dr]|ist|ing)': '$1$2ell$3',
'(bev|canc|couns|fu|jew|lab|lev|marv|mod|
'([a-zA-Z]{2,8}[^eglpstz ])el(e[dr]|est|ing)(\\b)': '$1$2ell$3$4', // added 'p' to avoid changing of "misspelling"
'(app|di|enthr|equ|initi|journ|riv|sign|tot)al(e[dr]|ing)': '$1$2all$3' // appalled/appalling is also American
Line 495 ⟶ 498:
'diarrhoea': '$1diarrhea',
'(de|of)fence': '$1$2fense',
'licence': '$1license',
'(licen)c(ing|ed)': '$1$2s$3',
'per cent(\\b)': '$1percent$2',
'(practi)s(ing|ed)': '$1$2c$3',
'furore(\\b)': '$1furor$2',
Line 534 ⟶ 537:
// 'f' words
//'(S|s)ulfur': '$1$2ulphur', //disabled per WP:
'any more': '$1anymore',
Line 551 ⟶ 554:
'honour(abl[ey]|ed|ing|s|\\b)': '$1honor$2',
'(endeav|lab)our(e[dr]|ing|s|\\W)': '$1$2or$3',
'moul(
// '~re~' words
Line 557 ⟶ 560:
'(centi|kilo|micro|milli|nano|-|hundred\\s|\\d\\s)metre': '$1$2meter',
'(centi|milli|deci|pico|hecto|\\b)litre(s?\\b)': '$1$2liter$3',
'(
// '(\\W[a-zA-Z]{3,12}[^s\\b])iz(e[drs]?|ation(s|al|)|ing)': '$1$2is$3',
// '~l' words where the 'l' doubles as past and present participle
'((?:\\w{3,9}[-–—]|)(?:fu|pan))ell(e[dr]|ist|ing)': '$1$2el$3',
'(bev|canc|couns|fu|jew|lab|lev|marv|mod|pan|prop|quarr|rev|sign|trav)ell?(e[dr]|ing)': '$1$2el$3',
'([a-zA-Z]{2,8}[^eglpstz ])ell?(e[dr]|est|ing)(\\b)': '$1$2el$3$4', // added 'p' to avoid changing of "misspelling"
// '\\b(appal|excel)((?:e[dr]|est|ing)\\b)': '$1l$2', // "excelling/excelled" is US English
};
Line 591 ⟶ 594:
// '~logu~' words
'([^\\w\\d\\-\\/])(ana|cata|epi|homo|mono|pro)logu(ed|ing)': '$1$2log$3', // removing "dialogue" per user:coffeeandcrumbs (21/8/2018)
'([^\\w\\d\\-\\/])(ana|cata|epi|homo|mono|pro)logue(s?\\b)': '$1$2log$3', // removing "dialogue" per user:coffeeandcrumbs
// '~l' words where the 'l' doubles as past and present participle
Line 600 ⟶ 603:
'([ \\|\\[\\*])aeroplane': '$1airplane',
// '([ \\|\\[\\*])\\b[Mm](um|om(my|))\\b': '$1mother'
};
Line 615 ⟶ 617:
// remove US spelling from {{convert}} template output
// remove ambiguous dollar sign; rem incidental intervening space
editor.replace(/$ ?(\d)/g, '$$1');
// reconvert special cases
}
Line 655 ⟶ 656:
ohc_ENGVAR_insert_template(editor, variation);
ohc_Reorder_template(editor)
ohc_ENGVAR_edit_summary(editor, variation);
Line 735 ⟶ 737:
/** ------------------------------------------------------------------------ **/
function
const monthMap = [
'January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'
];
const now = new Date();
return `${monthMap[now.getMonth()]} ${now.getFullYear()}`;
}
function remove_deprecated(editor) {
const deprecatedMatcher = /\{\{\s*Engvar(?:A|C)[^}]*\}\}\s*/gi; // Only remove EngvarA and EngvarC
editor.replace(deprecatedMatcher, '');
return editor;
}
function ohc_ENGVAR_insert_template(editor, variant) {
editor = remove_deprecated(editor);
const variantClass = {
'U': [
'Use American English', 'Use Liberian English', 'Use Philippine English'
],
'C': ['Use Canadian English'],
'O': ['Use Oxford spelling'],
'B': [
'Use Commonwealth English spelling', 'Use British English', 'Use Antiguan and Barbudan English',
'Use Australian English', 'Use Bangladeshi English', 'Use Ghanaian English', 'Use Hiberno-English',
'Use Hong Kong English', 'Use Indian English', 'Use Jamaican English', 'Use Kenyan English',
'Use Malaysian English', 'Use New Zealand English', 'Use Nigerian English',
'Use Pakistani English', 'Use Singapore English', 'Use Sri Lankan English', 'Use South African English',
'Use Trinidad and Tobago English', 'Use Ugandan English'
]
};
const allTemplates = new Set(Object.values(variantClass).flat());
const templatePattern = Array.from(allTemplates)
.map(name => name.replace(/[\s\-]/g, '[\\s\\-]+').replace(/([()])/g, '\\$1'))
.join('|');
const allVarTemplatesMatcher = new RegExp(
`\{\{\s*(?:Template\s*:)?\s*(${templatePattern})(\s*\|[^}]*)?\}\}`,
'gi'
);
let foundVariantTemplate = false;
let engvarBFound = false;
const currentDate = month_year();
const allowedTemplates = variantClass[variant] || [];
// Process existing templates
editor.replace(allVarTemplatesMatcher, function (match, templateName, paramStr = '') {
const currentTemplate = templateName.trim();
if (!allowedTemplates.includes(currentTemplate)) {
console.log(`Removing non-matching variant template: {{${currentTemplate}}}`);
return '';
}
foundVariantTemplate = true;
let params = paramStr.split('|').map(p => p.trim()).filter(Boolean);
let paramMap = {};
for (const p of params) {
const [k, v] = p.split('=').map(s => s.trim());
paramMap[k] = v || true;
}
paramMap['date'] = currentDate;
const paramString = Object.entries(paramMap)
.map(([k, v]) => v === true ? k : `${k}=${v}`)
.join('|');
return `{{${templateName}|${paramString}}}`;
});
// Handle EngvarB specifically
const engvarBMatcher = /\{\{\s*EngvarB\s*(\|[^}]*)?\}\}/gi;
if (variant === 'B') {
editor.replace(engvarBMatcher, function (match, paramStr = '') {
engvarBFound = true;
let params = paramStr.split('|').map(p => p.trim()).filter(Boolean);
let paramMap = {};
for (const p of params) {
const [k, v] = p.split('=').map(s => s.trim());
paramMap[k] = v || true;
}
paramMap['date'] = currentDate;
const paramString = Object.entries(paramMap)
.map(([k, v]) => v === true ? k : `${k}=${v}`)
.join('|');
return `{{EngvarB|${paramString}}}`;
});
} else {
// Remove EngvarB when switching to non-Commonwealth variants
editor.replace(engvarBMatcher, '');
}
// Insert new template if needed
if (!foundVariantTemplate && !(variant === 'B' && engvarBFound)) {
let newTemplate = '';
if (variant === 'B') {
newTemplate = `{{Use British English|date=${currentDate}}}`;
} else if (allowedTemplates.length > 0) {
newTemplate = `{{${allowedTemplates[0]}|date=${currentDate}}}`;
}
if (newTemplate) {
const shortdescMatcher = /\{\{\s*short\s+description\s*\|[^}]+\}\}\s*(\r?\n)?/i;
if (editor.contains(shortdescMatcher)) {
editor.replace(shortdescMatcher, function (m) {
return m + newTemplate + '\n';
});
} else {
editor.prepend(newTemplate + '\n');
}
}
}
}
function ohc_Reorder_template(editor) {
// Ensure Short description appears before EngvarB if both exist
editor.replace(/(\{\{Use \w+ (?:spelling|English) ?\|[^}]+\}\}\n?)((?:\{\{[\S\s]+\}\}\n?)+|)(\{\{[Ss]hort description ?\|[^}]+\}\}(<!--[^>{}]+-->|)\n?)/g, '$3$2$1');
}
Line 778 ⟶ 878:
switch (variation) {
case 'B':
variation_string = 'EngvarB by [[User:Ohconfucius/script/EngvarB|script]]';
break;
case 'O':
variation_string = 'Oxford
break;
case 'C':
variation_string = 'Canadian
break;
case 'U':
variation_string = 'American
break;
default:
Line 793 ⟶ 893:
}
doaction('diff');
editor.appendEditSummary(variation_string);
}
// </syntaxhighlight>
|