Commit c6579a3a authored by Siltaar's avatar Siltaar
Browse files

use a real json object

parent 75a95b55
......@@ -1879,7 +1879,7 @@ Disembor</td>
<p>Some countries divide months using a <a href="/wiki/lunar_calendar" title="lunar calendar">lunar calendar</a>, or begin the year on a different date.</p>
<!--
<!--
NewPP limit report
Parsed by mw1092
CPU time usage: 2.224 seconds
......
......@@ -28,8 +28,10 @@ page.onError = function(msg, trace) { // return;
// Appendix:Months_of_the_Year
var the_page_content = fs.read ('Appendix:Months_of_the_year');
page.setContent(the_page_content, 'Appendix:Months_of_the_year');
page.injectJs ('month_nb.js');
page.injectJs ('month_nb_json.js');
var the_javascript_test = fs.read ('test_month_nb.js');
page.evaluateJavaScript (the_javascript_test);
page.injectJs('month_nb.js');
const _json = fs.read('month_nb.json');
var _test = fs.read ('test_month_nb.js');
_test = _test.replace("'month_nb_json_obj_replace_token';",
`const json_obj = JSON.parse('${_json.replace(/[\n\r\t]/gi, '')}');`);
page.evaluateJavaScript (_test);
phantom.exit ();
// Name: month_nb.js
// Desc: returns month number from given litteral case-insensitive name or abbreviation
// Author: Simon 'Siltaar' Descarpentries ; siltaar § acoeuro ' com
// Version: 3
// Version: 4
// Licence: GPLv3
// require('month_nb_json');
const month_nb = function(a, check_keys=false) {
var keys = [Object.keys(month_nb_json)];
var objs = [month_nb_json];
/* globals json_obj */
function month_nb (a, json_obj, check_keys=false) {
var keys = [Object.keys(json_obj)];
var objs = [json_obj];
var o_ks = keys[keys.length-1];
var o = objs[objs.length-1];
var r_range = '';
while(o_ks.length) {
let k = o_ks.shift();
if (k == "comment") continue;
// console.log(a +' '+ k);
if (check_keys) { // show chars out of lang range in keys
if (keys.length == 1) {
......@@ -43,17 +42,12 @@ const month_nb = function(a, check_keys=false) {
} else if (o_ks.length == 0) {
objs.pop(); // backtrack
o = objs[objs.length-1];
keys.pop();
// console.log(`depth level ${keys.length}`);
keys.pop(); // console.log(`depth level ${keys.length}`);
if (keys.length) {
o_ks = keys[keys.length-1];
// console.log(`keys to explore ${o_ks.length}`);
} else {
// console.error(`Did not found for ${a}.`);
o_ks = keys[keys.length-1]; // console.log(`keys to explore ${o_ks.length}`);
} else { // console.error(`Did not found for ${a}.`);
return undefined;
}
}
}
};
// exports.month_nb = month_nb;
}
{
"comment": [
"Name: month_nb.json",
"Desc: contains the regexp tree of month number deternimation by month_nb.js",
"Author: Simon - Siltaar - Descarpentries ; simon § d12s - fr",
"Version: 4",
"Licence: GPLv3",
"Not tested on : Chechen, Cherokee, Hawaiian, Lezgi, Navajo, Ojibwe",
"Old English, Old High German, Old Norse",
"Known failures :",
"- X Croatian : listopad fails to return 10 as it is 11 in Czech and Polish",
"- X Slovenian : prosinec fails to return 1, as it is 12 in Croatian and Czech",
"Languages from : https://en.wiktionary.org/wiki/Appendix:Months_of_the_Year",
"UTF8 ranges from : http://www.regular-expressions.info/unicode.html#block"
],
"^([\\u0000-\\u024F]|[\\u0370-\\u03FF]|[\\u0530-\\u058F]|[\\u0D80-\\u0DFF]|[\\u10A0-\\u10FF])": {
"comment": "latin, greek, armenian, sinhala, georgian",
"^([ijΙygelhxğජი]|d[ij][ua]|հու)": {
"^.?[ijyouο]?[uúüūύeiոජූვ][igւ]?[nñνնනිნ$]([^aäվnweවාg]|e?$)": 6,
"^(.[aαāniíjոනა]|[ig]e)ւ?([aneνවාნ]|նվ)": 1,
"^.?[iyjouο]?[uúüūύiոජූვ][iygւ]?[lèλլලිლ$]([^u]|$)": 7
},
"^[mΜմමმ]": {
"^(..[ae]?[rsctρրრ]([^r](([^e]|ec)|$)|$)|මා)": 3,
"^(.[aāáάաeა]([ijīíygaeιյი]|$)([^l]|$)|මැ)": 5
},
"^([aäΑáաօඅა]|o[igu][^b]*$)": {
"^.(.[rρր]|[පპ])": 4,
"^.([ගგ]|[ouŭgύivwգ]([uûúgtoγո]|$)[^b]*$)": 8
},
"^([fvΦփපთ][^ia][^l]|p[he])": 2,
"^[sΣսසැს]z?[eεեප්තැე]": 9,
"^[oöuΟհඔო][^nžrijīíygΙ][^a]": 10,
"^[nΝնනნ][^ijīíygΙ][^l]": 11,
"^[dΔդදდ][^u]": 12,
"^th": {
" m": {
"mư.*ha[ijīíygјΙ]": 12,
"mư.*một": 11,
"mườ": 10,
"một": 1
},
" t": {
"m": 8,
"ư": 4
},
" b": {
"ả": 7,
"[a]": 3
},
" c": 9,
" s": 6,
" n": 5,
" h": 2
},
"^(pro|gru|jo|ar|rh|ui)": 12,
"^(lis|stu|m[aä]r|ka[^un]|tac|ca)": 11,
"^(říj|pa|lo|^vi|ek|hy|re|nu)": 10,
"^([zw]|sy|ru|ki|ey|med|sü|am.*aq$)": 9,
"^(srpe|sie|ko|el|v.* s|ağ|aw|põ|am.*un$)": 8,
"^(č.*c|srp|lipi|hei|m.* s|te[^n]|go|hai|ing)": 7,
"^(č|c[^ha]|k(e[^p]|au)|lipa|ro|ha[^i]|meh|pi)": 6,
"^([ks]v[^e]|to|v.* t|leh|qu)": 5,
"^(du|tr|kw|hu|m.* t|ni|eb|mah|Tengmiirvik)": 4,
"^(ož|bř|maa|su|maw|urb|Tengmiirvig)": 3,
"^(ú|lu|[hv]el|sv|şu|ch|ra|kep)": 2,
"^(s[it]|le[^h]|ta[^c]|oc|io|vah|kan)": 1
},
"^([\u0590-\u05FF]|[\u0600-\u06FF]|[\u0900-\u097F])": {
"comment": "hebrew, arabic, hindi devanagari",
"^[יيज]": {
"^.(א?נו|ن|न)": 1,
"^(.(ונ|.ن)|जून)": 6,
"^(.(.ל|.ل)|जुला)": 7
},
"^[אأअ]": {
"^.(.ר|ب|प्)": 4,
"^.(..?ג|غ|ग)": 8,
"^.(.?ק|كت|क)": 10
},
"^[מمम]": {
"^.(א?ר|.ر|.र्)": 3,
"^.([אײַ]|.ي|ई)": 5
},
"^[פفफ]": 2,
"^[סسस]": 9,
"^[נنन]": 11,
"^[דدद]": 12
},
"^([\u0980-\u09FF]|[\u0B80-\u0D7FF]|[\u1000-\u109F])": {"comment": "bengali, tamil, burmese",
"^[ജஜజဇজ]": {
"^(.[നனన]|ဇန်|জানু)": 1,
"^(ജൂണ|ஜூன்|జూన్|ဇွ|জুন)": 6,
"^(ജൂല|ஜூலை|జూలై|ဇူ|জুলা)": 7
},
"^[മமమేမম]" : {
"^(മാ|மா|మా|မတ်|মা)": 3,
"^(മേ|மே|మ|မေ|মে)": 5
},
"^[ഡடிడిဒড]": 12,
"^[നநనနন]": 11,
"^[ഒஅఅအঅ]": 10,
"^[സசெసెစস]": 9,
"^([ആஆఆဩ]|[আঅ])": 8,
"^[ഏஏఏဧএ]": 4,
"^[ഫபெఫిဖফ]": 2
},
"^([\u3000-\u9FFF]|[\uAC00-\uD7AF])": {"comment": "hiragana katagana chinese, korean hangul",
"^[十\u3229시십]": {
"^.[月\u322A월]": 10,
"^.[一\u3220일]": 11,
"^.[二\u3221이]": 12
},
"^[一일]": 1,
"^[二이]": 2,
"^[三삼]": 3,
"^[四사]": 4,
"^[五오]": 5,
"^[六유]": 6,
"^[七칠]": 7,
"^[八팔]": 8,
"^[九구]": 9
},
"^([\u0400-\u052F])": {"comment": "cyrillic slavic",
"^[яиюј]": {
"^[^ю]?[юу]н": 6,
"^([^ю][најы]|[ј])[увн][^л]": 1,
"^[^ю]?[ο]?[ј]?[јюу][ј]?л": 7
},
"^м": {
"^(..[а]?[р])": 3,
"^.[а](ј|й|$)": 5
},
"^а": {
"^.(.[р])": 4,
"^.([јв]([јг]|$))": 8
},
"^[сгб]..[^п]": {
"comment": "other",
"^.[нр]": 12,
"^.[ае][^пн]": 3,
"^.[ті]": 1
},
"^л": {
"^.[iи]": {
"^..с": 11,
"^..п": 7
},
"^.ю": 2
},
"^[кж][^н]": {
"^.[ао]": 10,
"^.[рв]": 4
},
"^ф[^јΙа]": 2,
"^(се[^р]|в)": 9,
"^[о][^ј]": 10,
"^[Νн]": 11,
"^д": 12,
"^[жс]": 8,
"^ч": 6,
"^т": 5
},
"^([\u1200-\u137F])": {"comment": "amharic",
"^ጁ": {
"^.ን": 6,
"^.ላ": 7
},
"^ኦ": {
"^.ክ": 10,
"^.ገ": 8
},
"^ዲ": 12,
"^ኖ": 11,
"^ሰ": 9,
"^መ": 5,
"^ኤ": 4,
"^ማ": 3,
"^ፌ": 2,
"^ጃ": 1
},
"^([\u1780-\u17FF])": {"comment": "khmer",
"^ម": {
"^មក": 1,
"^មី": 3,
"^មេ": 4,
"^មិ": 6
},
"^ក": {
"^កុ": 2,
"^កក": 7,
"^កញ": 9
},
"^ត": 10,
"^វ": 11,
"^ធ": 12,
"^ឧ": 5,
"^ស": 8
},
"^([\u0E80-\u0EFF])": {"comment": "lao",
"^ມ": {
"^ມີ": {
"^ມີນາ": 3,
"^ມີຖຸ": 6
},
"^ມັ": 1
},
"^ກ": {
"^ກຸ": 2,
"^ກໍ": 7,
"^ກັ": 9
},
"^ພ": {
"^ພຶ": 5,
"^ພະ": 11
},
"^ເ": 4,
"^ສ": 8,
"^ຕ": 10,
"^ທ": 12
},
"^([\u0E00-\u0E7F])": {"comment": "thai",
"^ม": {
"^มก": 1,
"^มีน": 3,
"^มิถ": 6
},
"^ก": {
"^กุ": 2,
"^กร": 7,
"^กั": 9
},
"^พ": {
"^พฤศ": 11,
"^พฤษ": 5
},
"^ธ": 12,
"^ต": 10,
"^ส": 8,
"^เ": 4
},
"^(ཟླ)": {"comment": "tibetan",
"^ཟླ་བ": {
"^ཟླ་བཅུ": {
"ཉི": 12,
"ཅི": 11,
"^ཟླ་བཅུ་པ།": 10
},
"རྒྱ": 8,
"དུ": 7,
"ཞི": 4
},
"^ཟླ་ད": {
"གུ": 9,
"དྲུ": 6,
"ང": 1
},
"^ཟླ་ག": {
"སུ": 3,
"ཉི": 2
},
"ལྔ": 5
}
}
// Name: month_nb_json.js
// Desc: contains the regexp tree of month number deternimation by month_nb.js
// Author: Simon 'Siltaar' Descarpentries ; simon § d12s ' fr
// Version: 3
// Licence: GPLv3
//
// Not tested on :
// - Chechen
// - Cherokee
// - Hawaiian
// - Lezgi
// - Navajo
// - Ojibwe
// - Old English
// - Old High German
// - Old Norse
//
// Known failures :
// - X Croatian : listopad fails to return 10 as it is 11 in Czech and Polish
// - X Slovenian : prosinec fails to return 1, as it is 12 in Croatian and Czech
//
// Languages from : https://en.wiktionary.org/wiki/Appendix:Months_of_the_Year
// UTF8 ranges from : http://www.regular-expressions.info/unicode.html#block
const month_nb_json = {
'^([\\0000-\\u024F]|[\\u0370-\\u03FF]|[\\u0530-\\u058F]|[\\u0D80-\\u0DFF]|[\\u10A0-\\u10FF])': {
// latin
'^([ijΙygelhxğජი]|d[ij][ua]|հու)': {
'^.?[ijyouο]?[uúüūύeiոජූვ][igւ]?[nñνնනිნ$]([^aäվnweවාg]|e?$)': 6,
'^(.[aαāniíjոනა]|[ig]e)ւ?([aneνවාნ]|նվ)': 1,
'^.?[iyjouο]?[uúüūύiոජූვ][iygւ]?[lèλլලිლ$]([^u]|$)': 7
},
'^[mΜմමმ]': {
'^(..[ae]?[rsctρրრ]([^r](([^e]|ec)|$)|$)|මා)': 3,
'^(.[aāáάաeა]([ijīíygaeιյი]|$)([^l]|$)|මැ)': 5,
},
'^([aäΑáաօඅა]|o[igu][^b]*$)': {
'^.(.[rρր]|[පპ])': 4,
'^.([ගგ]|[ouŭgύivwգ]([uûúgtoγո]|$)[^b]*$)': 8,
},
'^([fvΦփපთ][^ia][^l]|p[he])': 2,
'^[sΣսසැს]z?[eεեප්තැე]': 9,
'^[oöuΟհඔო][^nžrijīíygΙ][^a]': 10,
'^[nΝնනნ][^ijīíygΙ][^l]': 11,
'^[dΔդදდ][^u]': 12,
'^th': {
' m': {
'mư.*ha[ijīíygјΙ]': 12,
'mư.*một': 11,
'mườ': 10,
'một': 1
},
' t': {
'm': 8,
'ư': 4
},
' b': {
'': 7,
'[a]': 3
},
' c': 9,
' s': 6,
' n': 5,
' h': 2
},
'^(pro|gru|jo|ar|rh|ui)': 12,
'^(lis|stu|m[aä]r|ka[^un]|tac|ca)': 11,
'^(říj|pa|lo|^vi|ek|hy|re|nu)': 10,
'^([zw]|sy|ru|ki|ey|med|sü|am.*aq$)': 9,
'^(srpe|sie|ko|el|v.* s|ağ|aw|põ|am.*un$)': 8,
'^(č.*c|srp|lipi|hei|m.* s|te[^n]|go|hai|ing)': 7,
'^(č|c[^ha]|k(e[^p]|au)|lipa|ro|ha[^i]|meh|pi)': 6,
'^([ks]v[^e]|to|v.* t|leh|qu)': 5,
'^(du|tr|kw|hu|m.* t|ni|eb|mah|Tengmiirvik)': 4,
'^(ož|bř|maa|su|maw|urb|Tengmiirvig)': 3,
'^(ú|lu|[hv]el|sv|şu|ch|ra|kep)': 2,
'^(s[it]|le[^h]|ta[^c]|oc|io|vah|kan)': 1,
},
'^([\u0590-\u05FF]|[\u0600-\u06FF]|[\u0900-\u097F])': { // hebrew, arabic, hindi devanagari
'^[יيज]': {
'^.(א?נו|ن|न)': 1,
'^(.(ונ|.ن)|जून)': 6,
'^(.(.ל|.ل)|जुला)': 7,
},
'^[אأअ]': {
'^.(.ר|ب|प्)': 4,
'^.(..?ג|غ|ग)': 8,
'^.(.?ק|كت|क)': 10,
},
'^[מمम]': {
'^.(א?ר|.ر|.र्)': 3,
'^.([אײַ]|.ي|ई)': 5,
},
'^[פفफ]': 2,
'^[סسस]': 9,
'^[נنन]': 11,
'^[דدद]': 12,
},
'^([\u0980-\u09FF]|[\u0B80-\u0D7FF]|[\u1000-\u109F])': { // bengali, tamil, burmese
'^[ജஜజဇজ]': {
'^(.[നனన]|ဇန်|জানু)': 1,
'^(ജൂണ|ஜூன்|జూన్|ဇွ|জুন)': 6,
'^(ജൂല|ஜூலை|జూలై|ဇူ|জুলা)': 7,
},
'^[മமమేမম]' : {
'^(മാ|மா|మా|မတ်|মা)': 3,
'^(മേ|மே|మ|မေ|মে)': 5,
},
'^[ഡடிడిဒড]': 12,
'^[നநనနন]': 11,
'^[ഒஅఅအঅ]': 10,
'^[സசெసెစস]': 9,
'^([ആஆఆဩ]|[আঅ])': 8,
'^[ഏஏఏဧএ]': 4,
'^[ഫபெఫిဖফ]': 2,
},
'^([\u3000-\u9FFF]|[\uAC00-\uD7AF])': { // hiragana katagana chinese, korean hangul
'^[十\u3229시십]': {
'^.[月\u322A월]': 10,
'^.[一\u3220일]': 11,
'^.[二\u3221이]': 12,
},
'^[一일]': 1,
'^[二이]': 2,
'^[三삼]': 3,
'^[四사]': 4,
'^[五오]': 5,
'^[六유]': 6,
'^[七칠]': 7,
'^[八팔]': 8,
'^[九구]': 9,
},
'^([\u0400-\u052F])': { // cyrillic slavic
'^[яиюј]': {
'^[^ю]?[юу]н': 6,
'^([^ю][најы]|[ј])[увн][^л]': 1,
'^[^ю]?[ο]?[ј]?[јюу][ј]?л': 7
},
'': {
'^(..[а]?[р])': 3,
'^.[а](ј|й|$)': 5,
},
'': {
'^.(.[р])': 4,
'^.([јв]([јг]|$))': 8,
},
'^[сгб]..[^п]': { // other
'^.[нр]': 12,
'^.[ае][^пн]': 3,
'^.[ті]': 1,
},
'': {
'^.[iи]': {
'^..с': 11,
'^..п': 7,
},
'^.ю': 2,
},
'^[кж][^н]': {
'^.[ао]': 10,
'^.[рв]': 4,
},
'^ф[^јΙа]': 2,
'^(се[^р]|в)': 9,
'^[о][^ј]': 10,
'^[Νн]': 11,
'': 12,
'^[жс]': 8,
'': 6,
'': 5,
},
'^([\u1200-\u137F])': { // amharic
'^ጁ': {
'^.ን': 6,
'^.ላ': 7,
},
'^ኦ': {
'^.ክ': 10,
'^.ገ': 8,
},
'^ዲ': 12,
'^ኖ': 11,
'^ሰ': 9,
'^መ': 5,
'^ኤ': 4,
'^ማ': 3,
'^ፌ': 2,
'^ጃ': 1,
},
'^([\u1780-\u17FF])': { // khmer
'^ម': {
'^មក': 1,
'^មី': 3,
'^មេ': 4,
'^មិ': 6,
},
'^ក': {
'^កុ': 2,
'^កក': 7,
'^កញ': 9,
},
'^ត': 10,
'^វ': 11,
'^ធ': 12,
'^ឧ': 5,
'^ស': 8,
},
'^([\u0E80-\u0EFF])': { // lao
'^ມ': {
'^ມີ': {
'^ມີນາ': 3,
'^ມີຖຸ': 6,
},
'^ມັ': 1,
},
'^ກ': {
'^ກຸ': 2,
'^ກໍ': 7,
'^ກັ': 9,
},
'^ພ': {
'^ພຶ': 5,
'^ພະ': 11,
},
'^ເ': 4,
'^ສ': 8,
'^ຕ': 10,
'^ທ': 12,
},
'^([\u0E00-\u0E7F])': { // thai
'^ม': {
'^มก': 1,
'^มีน': 3,
'^มิถ': 6,
},
'^ก': {
'^กุ': 2,
'^กร': 7,
'^กั': 9,
},
'^พ': {
'^พฤศ': 11,
'^พฤษ': 5
},
'^ธ': 12,
'^ต': 10,
'^ส': 8,
'^เ': 4,
},
'^(ཟླ)': { // tibetan
'^ཟླ་བ': {
'^ཟླ་བཅུ': {
'ཉི': 12,
'ཅི': 11,
'^ཟླ་བཅུ་པ།': 10,
},
'རྒྱ': 8,
'དུ': 7,
'ཞི': 4,
},
'^ཟླ་ད': {
'གུ': 9,
'དྲུ': 6,
'': 1,
},
'^ཟླ་ག': {
'སུ': 3,
'ཉི': 2,
},
'ལྔ': 5,
},
};
function test (debug=true, display_months=false) {
function unused_name (debug=true, display_months=false) {
'month_nb_json_obj_replace_token';
var tbx = document.querySelectorAll ('#mw-content-text tr');
var mns = [], lgs = [];
var cur_mns, cur_ln;
......@@ -36,9 +37,10 @@ function test (debug=true, display_months=false) {
for (let j = mns[i].length; j--; ) {
cur_mn = mns[i][j].textContent;
cur_mn = cur_mn.replace (/\(bulan\) /, '');
if (month_nb (cur_mn) != j + 1) {