I added new function "label" which capitalize only first letter for fetched wikidata labels (diff). Because Wikidata English labels generally begin with a lower
| This is an archive of past discussions about Module:String2. Do not edit the contents of this page. If you wish to start a new discussion or revive an old one, please do so on the current talk page. |
| Archive 1 |
I added new function "label" which capitalize only first letter for fetched wikidata labels (diff). Because Wikidata English labels generally begin with a lowercase letter (d:Help:Label#Capitalization). New function is almost same as "sentence" function except that "label" doesn't lowering the rest of text. If there are any questions or problems, feel free to report here. Thanks! --Was a bee (talk) 03:03, 17 September 2017 (UTC)
There is an script error on articles like 999 (album) and Casual Viewin' USA, whith an error on line 35, which originates on line 34. "%a" on line 34 did not match numbers after the pipe in my test, although it does find an letter after the pipe. As both of these articles have an number after the pipe, they both give an script error. The script needs to deal with the possibility of an number after an pipe.--Snaevar (talk) 23:13, 9 October 2019 (UTC)
E.g. {{#invoke:String2 | ucfirst |Đorđe Balašević chronology }} returns ĐOrđe Balašević chronology, as if the function does not realize Đ is a letter and is capitalizing O instead. Note {{ucfirst:Đorđe Balašević chronology}} returns Đorđe Balašević chronology, as it should. Oddly, {{#invoke:String2 | ucfirst |đorđe Balašević chronology }} works correctly (i.e. Đorđe Balašević chronology is returned). {{Infobox album}} chronology is affected, although these kinds of errors seem to be very rare. GregorB (talk) 18:24, 24 July 2020 (UTC)
{{#invoke:String2 | ucfirst |Đorđe Balašević chronology }} → Đorđe Balašević chronology{{#invoke:String2 | ucfirst |đorđe Balašević chronology }} → Đorđe Balašević chronologyFunction findlast finds the last item in a list. The first unnamed parameter is the list. The second, optional unnamed parameter is the list separator (default = comma space). It returns the whole list if the separator is not found.
The list is trimmed of leading and trailing whitespace; the separator is not (so that leading or trailing spaces can be included).
One issue is that using Lua special pattern characters as the separator will probably cause problems.
Examples:
{{#invoke:String2 |findlast | 5, 932, 992,532, 6,074,702, 6,145,291}} → 6,145,291{{#invoke:String2 |findlast | 5, 932, 992,532, 6,074,702, 6,145,291 |;}} → 5, 932, 992,532, 6,074,702, 6,145,291{{#invoke:String2 |findlast | 6,074,702 }} → 6,074,702{{#invoke:String2 |findlast |}} →{{#invoke:String2 |findlast | 5 932 992,532 6,074,702 6,145,291 }} → 5 932 992,532 6,074,702 6,145,291Any bug reports welcome. --RexxS (talk) 20:33, 19 November 2020 (UTC)
I have added a matchAny function to the sandbox; it takes any number of patterns and returns the index of the first which matches, if any. Demo usage at Template:Infobox animanga/Header/sandbox. Comments welcome. (I'm a new template editor so I can make this change myself if no objections.) User:GKFXtalk 19:17, 8 April 2021 (UTC)
I recently noticed a rather significant issue with uppercasing and lowercasing strings in Lua: it mangles strip markers. The built-in parser functions do not. See sample (now a mock-up):
INVOKE:STRING2|UPPER.'"`UNIQ--REF-0000001E-QINU`"'
invoke:string2|lower.'"`uniq--ref-0000001f-qinu`"'
USING UC:[3]
using lc:[4]
Is there any good reason to make this feature available to wikitext? It would be highly confusing for editors and template authors to see strip markers. Otherwise this module's upper and lower functions should be removed from anything using them and replaced with the uc:/lc: parser functions. User:GKFXtalk 18:47, 15 April 2021 (UTC)
I implemented the behavior of {{Trunc}} in Lua, as function trunc() in the sandbox. This code is simpler and faster than the template code. I'd like to promote it to the main module (as opposed to having a small side module just for {{trunc}}). Any objections? — hike395 (talk) 09:12, 9 June 2021 (UTC)
As I just discovered when importing this module on a sister project, findpagetext will throw a big ugly (and misleading) Lua error when the wikipage in its first argument doesn't exist, because the module doesn't check that it exists before getting its contents and doesn't try to catch this kind of error.
If you see this text the bug was fixed.
Simply checking that :getContent() didn't return nil or empty and returning nomatch before handing it to mw.ustring.find() is probably enough. Xover (talk) 17:30, 26 October 2021 (UTC)
{{#invoke:String2 |findpagetext |text=Youghiogheny |title=NoSuchPage |nomatch=If you see this text the bug was fixed.}} → If you see this text the bug was fixed.{{#invoke:String2 |findpagetext |text=Youghiogheny |title=No[SuchPage |nomatch=If you see this text the bug was fixed.}} → If you see this text the bug was fixed.{{#invoke:String2/sandbox |findpagetext |text=Youghiogheny |title=NoSuchPage |nomatch=If you see this text the bug was fixed.}} → If you see this text the bug was fixed.{{#invoke:String2/sandbox |findpagetext |text=Youghiogheny |title=No[SuchPage |nomatch=If you see this text the bug was fixed.}} → If you see this text the bug was fixed.|text= you get empty output (because the check for this case returns nil) instead of the nomatch string, which was unexpected. My expectation for this would be that it is a nomatch, because an empty search string isn't really "invalid" as such, it just doesn't match anything. I could make the opposite argument too, of course, but it might be worth taking another look at when to return nil and when to use nomatch at some point. --Xover (talk) 08:10, 27 October 2021 (UTC)
|text=. In that case, templates often pass empty text to mean "no parameter" which sort-of makes an empty string result sensible. Johnuniq (talk) 09:01, 27 October 2021 (UTC)
Now supports named parameters: source, target, plain, nomatch; and UTC characters:
* <code><nowiki>{{#invoke:String2 |posnq |source=This is a piece of text |target=ece}}</nowiki></code> → {{#invoke:String2 |posnq |source=This is a piece of text |target=ece}}
* <code><nowiki>{{#invoke:String2 |posnq |source=This is a piece of text |target=%s |plain=true}}</nowiki></code> → {{#invoke:String2 |posnq |source=This is a piece of text |target=%s |plain=true}}
* <code><nowiki>{{#invoke:String2 |posnq |source=This is a piece of text |target=%s |plain=false}}</nowiki></code> → {{#invoke:String2 |posnq |source=This is a piece of text |target=%s |plain=false}}
* <code><nowiki>{{#invoke:String2 |posnq |source=This is a piece of text |target=ece |nomatch=0}}</nowiki></code> → {{#invoke:String2 |posnq |source=This is a piece of text |target=ece |plain=false |nomatch=0}}
* <code><nowiki>{{#invoke:String2 |posnq |source=This is a piece of text |target=xyz |nomatch=0}}</nowiki></code> → {{#invoke:String2 |posnq |source=This is a piece of text |target=xyz |nomatch=0}}
* <code><nowiki>{{#invoke:String2 |posnq |This is a piece of text |" of" |true |0}}</nowiki></code> → {{#invoke:String2 |posnq |This is a piece of text |" of" |true |0}}
* <code><nowiki>{{#invoke:String2 |posnq |This is a piece of text |" of" |true |0}}</nowiki></code> → {{#invoke:String2 |posnq |This is a piece of text |" of" |true |0}}
* <code><nowiki>{{#invoke:String2 |posnq |source=Meet at Café Nero |target=afé}}</nowiki></code> → {{#invoke:String2 |posnq |source=Meet at Café Nero |target=afé}}
Any bug reports welcome. --RexxS (talk) 00:08, 8 December 2020 (UTC)
The posnq function from this template has been nominated for deletion. You are invited to comment on the discussion at the entry on the Templates for discussion page. User:GKFXtalk 15:37, 31 December 2021 (UTC)
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.