Module talk:category tree/requests

From Wiktionary, the free dictionary
Jump to navigation Jump to search

Using gsub to add text content[edit]

I think it would make the code more understandable if the module used gsub to add content, rather than string.format. That could be done by replacing "%s" with variables defined with symbols, such as "<<variableName>>" or "{{{variableName}}}", creating a table of variables, then using gsub to replace the variables with their values, once the full output string has been generated. This is done in, for instance, the Arabic conjugation module, Module:ar-verb, to put verb forms into the table. (It's also quite nifty.) — Eru·tuon 20:15, 20 May 2017 (UTC)[reply]

@Daniel Carrero: I've created a version of the module that does this, at Module:User:Erutuon/requests. What do you think? — Eru·tuon 21:05, 20 May 2017 (UTC)[reply]

@Erutuon: I saw your version of the module, but please feel free to do whatever you want as long as it works. I'm not very knowledgeable about the niceties of Lua. I'll trust your judgement. --Daniel Carrero (talk) 00:31, 21 May 2017 (UTC)[reply]
@Daniel Carrero: Done! Now the things (language name, language code, etc.) that are put into the generated text are contained in a table (items), so they can be accessed by gsub. I'm pretty sure it works correctly, but I will check some more to make sure. — Eru·tuon 00:51, 21 May 2017 (UTC)[reply]
Had to redo it. Most of the variables are now in the items table, which makes them a little annoying to type out. Added some newlines and tabs to make the code more readable. — Eru·tuon 03:12, 21 May 2017 (UTC)[reply]
That's nice, but unfortunately now it seems there's some problem with this_request_in_all_languages.
--Daniel Carrero (talk) 04:57, 21 May 2017 (UTC)[reply]
@Erutuon: I reverted your recent edits. Feel free to check your new code and do your improvements again.
When you re-edited the module on May 21, the aforementioned problem got worse: Apparently, all the requests categories became uncategorized themselves. For example, Category:Requests for images in English entries was not a member of any categories (apart from the category "Hidden categories"). --Daniel Carrero (talk) 16:47, 22 May 2017 (UTC)[reply]
Good that you reverted. I was noticing more problems too. I added the testing function again though. — Eru·tuon 18:15, 22 May 2017 (UTC)[reply]