Eisspeedway

Wikipedia talk:Lua: Difference between revisions

Content deleted Content added
Tag: Reply
Line 36: Line 36:


:@[[User:Amangeldi Mukhamejan|Amangeldi Mukhamejan]]: i only saw this now, sorry about that. i hope it's not too late.
:@[[User:Amangeldi Mukhamejan|Amangeldi Mukhamejan]]: i only saw this now, sorry about that. i hope it's not too late.
:a while ago i wrote a utility module that enables you to use any module from another language with localized parameters name. the idea is simple - i'm sure you won't have any trouble grasping it and figuring out how it's done. see [[:he:יחידה:תרגום יחידה]]
:a while ago i wrote a utility module that enables you to use any module from another language with localized parameter names. the idea is simple - i'm sure you won't have any trouble grasping it and figuring out how it's done. see [[:he:יחידה:תרגום יחידה]]
:in a nutshell: for each module you want "translated", you create a "translation" module (in retrospect i guess it could have been a JSON rather than module). then you call the utility module, passing it the target module, the target function, the name of the "translation module", and any parameter you want to pass directly.
:in a nutshell: for each module you want "translated", you create a "translation" module (in retrospect i guess it could have been a JSON rather than module). then you call the utility module, passing it the target module, the target function, the name of the "translation module", and any parameter you want to pass directly.
:the utility module clones the frame (such that the "parent" of the clone is the real parent, not the utility module), it then enriches the "args" and the parent's args with the translated parameters, and then it calls the target module/function with this enriched frame.
:the utility module clones the frame (such that the "parent" of the clone is the real parent, not the utility module), it then enriches the "args" and the parent's args with the translated parameters, and then it calls the target module/function with this enriched frame.

Revision as of 04:30, 26 January 2024

How to make multilangual parameters in Module:Navbox

Hello!

I'm translated Navbox module into Kazakh Wikipedia, but have one issue. We've already have a kk:Module:Navbox, but I want to upgrade it. Additionally in the some templates we also used English version of Navbox (english parameters). So I need to add english versions of parameters (Aliases?) to new kk:Module:Шолғы exactly to kk:Module:Шолғы/configuration. I've already ask this question on talk page of Module:Navbox, but nobody replied, that's why I'm writing here Thanks--Amangeldi Mukhamejan (talk) 15:15, 27 October 2023 (UTC)[reply]

@Amangeldi Mukhamejan: i only saw this now, sorry about that. i hope it's not too late.
a while ago i wrote a utility module that enables you to use any module from another language with localized parameter names. the idea is simple - i'm sure you won't have any trouble grasping it and figuring out how it's done. see he:יחידה:תרגום יחידה
in a nutshell: for each module you want "translated", you create a "translation" module (in retrospect i guess it could have been a JSON rather than module). then you call the utility module, passing it the target module, the target function, the name of the "translation module", and any parameter you want to pass directly.
the utility module clones the frame (such that the "parent" of the clone is the real parent, not the utility module), it then enriches the "args" and the parent's args with the translated parameters, and then it calls the target module/function with this enriched frame.
note that i said "enriches", not "replace". this means that the caller can use either the original param name _or_ the translated name, which i think is part of your requirements, you can mix and match - some of the parameters can be the translated ones and others can be the original ones
there is some rudimentary documentation as a comment at the top of the module (the doc is not very long, but it's still 50% of the whole thing - the code is short and sweet and pretty easy to understand - no magic. i wrote it per some request on hewiki, and tested it to verify it works, but eventually the requestor decided not to use it, so you can say it's not "tried and tested", only "tested"...
this of course is not specific to "navbox": once you install it, you can use it for any module, at the cost of creating "translation module" for each imported module you want to use with native language parameter names.
if you do decide to use it, i'll be grateful if you can let me know, and of course, if you find bugs let me know too.
peace. קיפודנחש (aka kipod) (talk) 04:24, 26 January 2024 (UTC)[reply]

Up until just now Template:WikiProject Cephalopods invoked Module:WikiProject banner with a parameter containing a template, i.e.

|HOOK_ASSESS = {{WPBannerMeta/hooks/bchecklist}}

Template:WikiProject Cephalopods was not listed at Special:WhatLinksHere/Template:WPBannerMeta/hooks/bchecklist, however, a page like Talk:Vampire squid which transcludes Template:WikiProject Cephalopods was listed in WhatLinksHere, which surprised me. Why was the page listed but not the template? — Martin (MSGJ · talk) 07:20, 10 November 2023 (UTC)[reply]

The point of WhatLinksHere is so MediaWiki knows what pages need to be regenerated when a template or module is changed. The page Template:WikiProject Cephalopods did not contain anything that would change if the now deleted Template:WPBannerMeta/hooks/bchecklist were changed. However, Talk:Vampire squid transcluded {{WikiProject Cephalopods}} and its wikitext used to transclude {{WPBannerMeta/hooks/bchecklist}}, so Talk:Vampire squid needed to be regenerated when Template:WPBannerMeta/hooks/bchecklist changed. In conclusion, the WhatLinksHere feature is not very helpful for those maintaining templates/modules. Johnuniq (talk) 07:59, 10 November 2023 (UTC)[reply]
This is the reason I quite regularly do insource searches when messing around with templates. This has the problem of not detecting redirects, but it is definitely useful in some circumstances. --Trialpears (talk) 08:28, 10 November 2023 (UTC)[reply]

Regex question

I am using :gmatch('{{{([^|]+)') to find valid parameters in a template's code. It is not working quite right.

For example the code contains {{{event}}} {{{event-type|edit-a-thon}}} but it seems to be matching with event}}} {{{event-type but not the event-type which I require. — Martin (MSGJ · talk) 13:00, 11 January 2024 (UTC)[reply]

[^|]+ will go as far as it can to capture text before running into a pipe, which is why the first capture is so long and contains text from both event and event-type. gmatch then continues from the pipe it got stopped at last time so won't pick event-type up since its beyond it at this point. I'd recommend adding } inside of that negated list, which should prevent it from over-capturing event (and therefore pick up event-type afterwards too). Aidan9382 (talk) 13:31, 11 January 2024 (UTC)[reply]
I'm guessing here, but try "-" instead of "+" in the capture. You could also try escaping characters that might have another meaning (e.g.{ and | which would need escaping in regex proper). —  Jts1882 | talk  13:36, 11 January 2024 (UTC)[reply]
For some reason I didn't get an edit warning message and missed the reply above. —  Jts1882 | talk  13:38, 11 January 2024 (UTC)[reply]
Apparently - is an alias for *. That would not help here — Martin (MSGJ · talk) 14:06, 11 January 2024 (UTC)[reply]
Perfect, thanks! — Martin (MSGJ · talk) 14:03, 11 January 2024 (UTC)[reply]
Another alternative might be to gmatch the whole parameter and then parse that. In the debug console I get these results using string.match() in place of string.gmatch():
=string.match ('{{{event}}} {{{event-type|edit-a-thon}}}', '{{{([^}]+)}}}')event – this would be the first string.match() result
=string.match ('{{{event-type|edit-a-thon}}}', '{{{([^}]+)}}}')event-type|edit-a-thon – and this would be the second string.match() result
Trappist the monk (talk) 14:39, 11 January 2024 (UTC)[reply]
Beware that the parameter default often contains braces in a nested parameter, magic word or template call, e.g. {{{display_text|{{{title}}}}}} or {{{page_name|{{PAGENAME}}}}. In some very clever templates, they even crop up in the parameter name itself. Certes (talk) 14:50, 11 January 2024 (UTC)[reply]