= month_nb : get the number of a month from its name :experimental: yes :toc: :toc-title: Index `month_nb.js` is a small utility which knows the corresponding number of a month name, in 71 https://en.wiktionary.org/wiki/Appendix:Months_of_the_year[languages]. == Usage ```javascript >> month_nb('août'); 8 ``` The function returns a month number from a given litteral case-insensitive month name or abbreviation. It returns `undefined` if no corresponding number is found. To use it, include the `month_nb.js` file and define a `month_nb_json` variable containing the `month_nb.json` instantiated object : ```html ``` A working expliciter approach : ```html ``` Modern method, using `async`/`await` : ```javascript (async () => { "use strict" let month_nb_json = await fetch("js/month_nb/month_nb.json") month_nb_json = await month_nb_json.json() month_nb('août') })() ``` == Architecture `month_nb.js` only contains a loop going through a JSON tree data structure made of regular expression strings as keys (for the nodes), sub-objects for branchs and numbers for leafs. The data structure itself resides in the `month_nb.json` file. This clear separation between code and data is wanted to ease the re-use of `month_nb.json` data structure with other languages, to reimplement a `month_nb` feature. An experimental *Python implementation* is provided with currently 53 working languages (only). == Supported languages `month_nb.js` works for 71 languages (including most living written languages), and it would be 73 if it was not for those two ambiguities : but there two ambiguities : - Croatian : _listopad_ fails to return 10 as it is 11 in Czech and Polish - Slovenian : _prosinec_ fails to return 1, as it is 12 in Croatian and Czech Support for those languages has been postponed : Cherokee, Hawaiian, Lezgi, Navajo, Ojibwe, Old English, Old High German, Old Norse, Sinhalese. == Character encoding considerations Currently the `month_nb.json` tree data structure is filled with UTF-8 characters (like "é"). It's easy to read but can prove complicated to edit, specifically with right-to-left characters mixed with left-to-right ones, or with aggregating characters (combining in one symbol) separated by copy/pastes and than end up aggregating with a closing parenthesis or a quote. Converting every UTF-8 character to the `\u00E9` form might help other programming languages to re-use it (but would complicate the maintenance of the tree). == Update month definitions To update the definitions, download a new copy of `Appendix:Months_of_the_year` and run the `phantomjs_gen_def.js` script : ```sh $ cd month_definitions $ wget https://en.wiktionary.org/wiki/Appendix:Months_of_the_year $ phantomjs phantomjs_gen_def.js <1> ``` <1> `phantomjs` is from the eponymous Debian package. Then clean the `.json` file from error logging of phantomjs, and add the "numeric" first line (that you can copy from the previous `.json` definition file). == Running tests To test `month_nb.js` against the language definition file, run : ```sh $ node test_month_nb.js ``` The `node` v15.8.0 command comes from the `nodejs` package on Arch-based distributions such as Artix Linux. It will display various informations about the working and broken languages. == Who uses it ? `month_nb` have been initially developped for https://www.meta-press.es/[Meta-Press.es]. == TODO === Update according to Wiktionary evolution The Wiktionary snapshot page of https://en.wiktionary.org/wiki/Appendix:Months_of_the_year[Appendix:Months_of_the_year] used is from 2019-09-18. 14 languages were added since the 2013 version of the initial release of `month_nb`, they are not all supported yet. === Node packaging Make a NodeJS package out of it.