Page MenuHomePhabricator

Magic word to recognise the first letter of a word, such as a template parameter, and pass it on
Open, Needs TriagePublicFeature

Description

Hello. I would request a magic word is introduced that recognises the first letter of a word and passes it on. It would change the behaviour of a template depending on the first word of a parameter.

I describe below an example with Slovenian, which was the reason to open this request. However, the same would also matter for English with the a/an articles.

Example:

The template {{merge|article}} would show a different text depending on the letter that the parameter 'article' starts with.

For example, in Slovenian we use the preposition 's' before words starting on c, č, f, h, k, p, s, š, t and the preposition 'z' before words starting on b, d, g, j, l, m, n, r, v, z, ž and a, e, i, o, u.

It would thus show e.g. 'združi z '[c]article' or 'združi s [b]article' (združi here meaning merge).

Event Timeline

You can use lua to get the first letter of an argument.

Or trick with parser functions to cut of the first letter of the parameter to compare with (združi {{#switch:{{padleft:|1|{{{1}}}}}|c|č|f|h|k|p|s|š|t=s|b|d|g|j|l|m|n|r|v|z|ž|a|e|i|o|u=z}} {{{1}}})

Not sure if this special case needs its own magic word.

Izno subscribed.

This feels like something that would be more up the language group's alley rather than necessarily changing something in the parser or even forcing someone to have to write a template to do that.

Thank you for the comments. I see that this can be solved with parser functions or Lua. In any case, this is used so frequently (also in English with a/an or Italian with il/lo/gli) that it would be smart to have this as simple and readily available as possible. That's why imo it would be best to have it included in the MediaWiki itself.

I have tried the code that was proposed above and have figured out two things:

  1. It only works for lowercase letters (I have then added the lc: function);
  2. numbers would also have to be accounted for by the function.

However, regarding numbers, this then becomes more complex as the final digit of a numeral decides about the preposition/article to be used for numbers below 100 and the first digit for numbers above 100 (and a special case for 100).

Of course, parameters (like an article title in merge) can consist of a numeral and characters, which should be properly evaluated (what comes first decides on the selection).

I have no idea how to solve this using the available parser functions/Lua.

I have now thought about it further and it seems it would be best to avoid parsing words starting with a digit altogether, as these are read differently in various cases, which requires understanding the text. So such a magic word would only work for strings starting with a letter or display the default combination of prepositions/articles in case of a number (e.g. a/an in front of 802.16 (Wimax))).

My template code was only a suggestion based on the information of that task, nothing about cases of letters was written there or about numbers. I have no knowledge in that language. A solution could be more complex.

Maybe {{GRAMMAR:}} (https://translatewiki.net/wiki/Grammar) is a better solution for that situation in that language (The doc says "Convert from the nominative form of a noun to some other case").
At least the "z" part for instrumental cases is implemented, but without a check for letters (since 9016f7f9ca163f2a6cced3271d0919878343ead4).

{{GRAMMAR:orodnik|word}} gives z word

Yes, it will certainly be more complex. At the moment, it would be great if it worked for first letters of the following text string (case-insensitive) though.

The instrumental with the 'z' preposition should be corrected itself; it should render only the declensed word (noun) without the preposition to be fully usable. The preposition with instrumental is not necessarily 'z', it can be 's' as stated or an entirely different adjective can be inserted between the preposition and the declensed word.

I have now solved this with two modules:

https://sl.wikipedia.org/wiki/Modul:Z_ali_s

https://sl.wikipedia.org/wiki/Modul:H_ali_k

which are analogous to the 'a or an' module in the English Wikipedia

https://en.wikipedia.org/wiki/Module:A_or_an

Still, it would be useful to have this option implemented at the MediaWiki level.