模組討論:WikidataIB

Latest comment: 5 年前 by Deryck Chan
  • {{#invoke:WikidataIB |getValue |P569 |qid=Q151973 |fwd=ALL |osd=no}}
    • 1925年11月10號 喺Wikidata改呢個

@RexxS This is the same code that you've provided on en:Module:WikidataIB but it doesn't work here. Is there something missing with the localization? Curiously non-date values seem to work:

  • {{#invoke:WikidataIB |getValue |P569 |qid=Q151973 |fwd=ALL |osd=no}}

--翹仔 (傾偈) 2018年8月23號 (四) 14:37 (UTC)回覆

@Deryck Chan The date handling code works in two stages. First it takes the timestamp and creates a "standard" date string in lines 656 to 667 - so it changes "+2018-04-01T00:00:00Z" to "1 April 2018" which matches the way that the Wikibase routine does it. However, I deliberately made it localised for the month name, so here we would get "1 4月 2018" which isn't a proper Cantonese date, but can be parsed in the same way that the Wikibase version is.
The second stage takes the "standardised" date string and formats it according to local conventions in lines 211 to 254. Of course the reverse lookup table that I originally patched in at line 233 to change month names to month numbers also needed to be internationalised. I've now generalised that and removed the need for localisation there. Obviously that code could be much simpler in Cantonese because of the numeric format of month names, but I've kept the same structure in case other folks want to use this as a basis to do the same job in other languages that have non-numeric month names.
  • {{#invoke:WikidataIB |formatDate | 1 4月 2018}}Lua error in 模組:WikidataIB at line 338: attempt to concatenate global 'yearsuffix' (a nil value).
  • {{#invoke:WikidataIB |formatDate | 1 4月 2018 |df=y}}Lua error in 模組:WikidataIB at line 338: attempt to concatenate global 'yearsuffix' (a nil value).
  • {{#invoke:WikidataIB |formatDate | 20 8月 30 BC}}Lua error in 模組:WikidataIB at line 338: attempt to concatenate global 'yearsuffix' (a nil value).
  • {{#invoke:WikidataIB |formatDate | 20 8月 30 BC |df=y}}Lua error in 模組:WikidataIB at line 338: attempt to concatenate global 'yearsuffix' (a nil value).
  • {{#invoke:WikidataIB |formatDate | 1月 2018}}Lua error in 模組:WikidataIB at line 343: attempt to concatenate global 'yearsuffix' (a nil value).
  • {{#invoke:WikidataIB |formatDate | 753 BCE}}Lua error in 模組:WikidataIB at line 343: attempt to concatenate global 'yearsuffix' (a nil value).
The 出世日子 (P569) for 李察波頓 (Q151973)
  • {{#invoke:WikidataIB |getValue |P569 |qid=Q151973 |fwd=ALL |osd=no}} → 1925年11月10號 喺Wikidata改呢個
The 死亡日期 (P570) for 凱撒 (Q1048)
  • {{#invoke:WikidataIB |getValue |P570 |qid=Q1048 |fwd=ALL |osd=no}} → 44年3月15號 BC、44年 BC 喺Wikidata改呢個
I think that's all working okay now. Let me know if there are more problems. --RexxS (傾偈) 2018年8月23號 (四) 16:27 (UTC)回覆

@RexxS Yeah I figured out that the code involved getValue getting the timestamp from an ISO format, then converting it into a date string with month names substituted in, the putting the result into formatDate which reverse-engineers that to extract the various parts of the month back out... and then I decided I probably shouldn't get involved with fixing that because if I did that then then next iteration of WikidataIB trunk will steamroll away my attempts to localise that. Thanks for making it work here, though I still think the way Module:Wikidata handles dates seems more sensible because it doesn't involve converting a timestamp into human-readable month names and then back, and the i18n variable contains date format strings that are actually used...! 翹仔 (傾偈) 2018年8月23號 (四) 22:01 (UTC)回覆

返去版面「WikidataIB」。