Wikipedia gvwiki https://gv.wikipedia.org/wiki/Ard-ghuillag MediaWiki 1.47.0-wmf.18 first-letter Meanyn Er lheh Resooney Ymmydeyr Resooney ymmydeyr Wikipedia Resooney Wikipedia Coadan Resooney coadan MediaWiki Resooney MediaWiki Clowan Resooney clowan Cooney Resooney cooney Ronney Resooney ronney TimedText TimedText talk Module Module talk Event Event talk Ny Steatyn Unnaneysit 0 1893 392849 370765 2026-09-06T15:27:02Z MacTire02 219 MacTire02 moved page [[Steatyn Unnaneysit America]] to [[Ny Steatyn Unnaneysit]] over redirect: ennym cadjin 370765 wikitext text/x-wiki {{Kishtey fys çheer |ennym_dooghyssagh = Steatyn Unnaneysit America |ennym_foddey_cadjincliaghtagh= {{nobold|United States of America {{small|([[Baarle]])}}}} |ennym_gienneydagh = ny Steatyn Unnaneysit |jalloo_brattagh = Flag of the United States.svg |jalloo_cleinney = Greater coat of arms of the United States.svg |jalloo_caslys = United States (orthographic projection).svg |jarroo-raa = "[[In God We Trust]]"<ref>{{USC|36|302}}</ref> |arrane_ashoonagh = "[[The Star-Spangled Banner]]"<ref>{{cite web |date=3 Mayrnt 1931 |title=An Act To make The Star-Spangled Banner the national anthem of the United States of America |url=https://uscode.house.gov/statviewer.htm?volume=46&page=1508}}</ref>{{parabr}}{{center|[[Coadan:Star Spangled Banner instrumental.ogg]]}} |çhengaghyn_oikoil = [[Baarle]]{{efn|name=officiallanguage|Jeeagh er [[Executive Order 14224]].<ref name="EOWP">{{cite news |url=https://www.washingtonpost.com/nation/2025/03/01/trump-english-official-language-explainer/ |title=A Trump order made English the official language of the U.S. What does that mean? |newspaper=[[The Washington Post]] |author1=Vivian Ho |author2=Rachel Pannett |date=1 Mayrnt 2025}}</ref><ref name="EONYT">{{cite news |url=https://www.nytimes.com/2025/03/01/us/politics/trump-order-english-official-language.html |author=Luke Broadwater |newspaper=[[The New York Times]] |date=1 Mayrnt 2025 |title=Trump Signs Order to Designate English as Official Language of the U.S.}}</ref>}} |preeu-valley = [[Washington, D.C.]] |latd=38 |latm=53 |latNS=N |longd=77 |longm=02 |longEW=W |latNSgael=Hwoaie |longEWgael=Heear |balley_smoo = [[Caayr York Noa]] |sorçh_reiltys = Pobblaght eaghtyraneagh [[Conastaghys ayns ny Steatyn Unnaneysit|chonastagh]] fo corys [[Smaghtaght|smaghtagh]] [[corys mestit|mestit]]<ref>{{cite web| title = The Price of American Authoritarianism: What Can Reverse Democratic Decline? | url=https://www.foreignaffairs.com/united-states/american-authoritarianism-levitsky-way-ziblatt | last1=Levitsky | first1=Steven |last2=Way |first2 = Lucan A. |last3=Ziblatt |first3=Daniel | date= 11 Mee ny Nollick 2025 |accessdate=14 Jerrey Geuree 2026 | language = Baarle | work = [[Foreign Affairs (earishlioar)|Foreign Affairs]]}}</ref><ref>{{cite web| url= https://www.thenation.com/article/politics/trump-miller-authoritarianism-imperialism-venezuela/|title= The Ugly Beast of American Authoritarianism |lang=Baarle |last=Abramsky |first=Sasha |date=8 Jerrey Geuree 2026 |accessdate=14 Jerrey Geuree 2026 |work = The Nation}}</ref><ref>{{cite web|url = https://www.newyorker.com/podcast/political-scene/how-bad-is-it-three-political-scientists-say-america-is-no-longer-a-democracy |title=How Bad Is It?: Three Political Scientists Say America Is No Longer a Democracy |first = Tyler|last=Foggatt| lang=Baarle |date=11 Mee ny Nollick 2025 |accessdate=14 Jerrey Geuree 2026 | work = The New Yorker}}</ref><ref>{{cite web|url=https://news.berkeley.edu/2025/01/21/theres-a-term-for-trumps-political-style-authoritarian-populism/|title=There’s a term for Trump’s political style: authoritarian populism |last=Thulin |first=Lila |work = UC Berkely News |date=21 Jerrey Geuree 2025 |accessdate=14 Jerrey Geuree 2026}}</ref> |enmys1_fer-toshee = [[Eaghtyrane ny Steatyn Unnaneysit|Eaghtyrane]] |ennym1_fer-toshee = [[Donald Trump]] |enmys2_fer-toshee = [[Lhiass-eaghtyrane ny Steatyn Unnaneysit|Lhiass-eaghtyrane]] |ennym2_fer-toshee = [[JD Vance]] |enmys3_fer-toshee = [[Loayreyder Whaiyl ny Steatyn Unnaneysit|Loayreyder y Whaiyl]] |ennym3_fer-toshee = [[Mike Johnson]] |enmys4_fer-toshee = [[Ard-vriw ny Steatyn Unnaneysit|Ard-vriw]] |ennym4_fer-toshee = [[John G. Roberts|John Roberts]] |eaghtyr_km2 = 9,833,520 |eaghtyr_mi_ker = 3,796,740 |eaghtyr_rhenk = 3oo |ushtey_sy_cheead = 7.0 |pobble_ooley = 328,239,523 |blein_ooley_pobble = 2019 |rhenk_ooley_pobble = 3-oo |pobble_coontey = {{WD Earroo yn Phobble cour Kishtey Fys}} |blein_coontey_pobble = |rhenk_coontey_pobble = |glooaght_pobble_km2 = 31 |glooaght_pobble_mi_ker = 80 |rhenk_glooaght_pobble = 180oo |quaiyl = |blein_LTS_CCK = 2024 |LTS_CCK = $29.168 trillioon |rhenk_LTS_CCK = 2h |LTS_CCK_yn_dooinney = $86,601 |rhenk_LTS_CCK_yn_dooinney = 8oo |LTS_ennymagh = $29.168 trillioon |rhenk_LTS_ennymagh = 1d |blein_LTS_ennymagh = 2024 |LTS_ennymagh_yn_dooinney = $86,601 |rhenk_LTS_ennymagh_yn_dooinney = 6oo |Gini = 41.6 |blein_Gini = 2023 |ronney_Gini = |blein_ALD = 2023 |ALD = {{increase}} 0.938 |rhenk_ALD = 17oo |ronney_ALD = <span style="color:#090">feer ard</span> |sorçh_kiondeeaght = [[Shennaghys ny Steatyn Unnaneysit|Neuchrogheydys]] |note_kiondeeaght = veih [[Reeriaght y Vretyn Vooar]] | taghyrt1_bunnt = [[Fogrey Neuchrogheydys ny Steatyn Unnaneysit|Fogrey neuchrogheydys]] | date1_bunnit = 4 Jerrey Souree 1776 | taghyrt2_bunnit = [[Eash y Chochiangle|Cochiangle]] | date2_bunnit = 1 Mayrnt 1781 | taghyrt3_bunnit = [[Conaant Phaarys (1783)|Hooar enney]] | date3_bunnit = 3 Mean Fouyir 1783 | taghyrt4_bunnit = [[Bunraght ny Steatyn Unnaneysit|Bunraght]] | date4_bunnit = 21 Mean Fouyir 1788 |coad_argid = USD |traa_ynnydagh = |ashchur_utc = -5 gys -10 |traa_ynnydagh_TTLS = |ashchur_utc_TTLS = -4 gys -10 |cctld = [[.us]] |coad_çhellvane = 1 |ard_noo = |fo-note1 = }} She [[pobblaght chonastagh]] [[corys eaghtyraneagh|eaghtyraneagh]] ad '''Steatyn Unnaneysit America''' ({{lang-en|United States of America}}), ta enmyssit '''ny Steatyn Unnaneysit''' ({{lang|en|''United States''}}), '''S.U.A.''' ({{lang|en|''U.S.A.''}}) as '''America''' chammah. Ta'n çheer jeant seose ass jeih steat as daeed cur liorish [[slyst chonastagh]]. Er y chooid smoo, ta'n çheer soit ayns [[America Hwoaie]] veanagh, raad dy vel [[ny Steatyn Unnaneysit colhiantagh|hoght steatyn as daeed]], chammah as y clyst chonastagh, soit eddyr y [[Yn Keayn Sheear|Cheayn Sheear]] as y [[Yn Keayn Sheealtagh|Cheayn Sheealtagh]]. T'ad çhemmal rish [[Yn Chanadey|y Chanadey]] 'sy twoaie as [[Meksico]] 'sy jiass. Ta [[Alaska]] soit ayns sheear hwoaie yn vooar-rheynn as raad t'eh çhemmit rish y Chanadey 'sy niar echey as rish [[Yn Roosh|y Roosh]] 'sy neear tessen [[Mooir Bering]]. Ta [[Hawaii]] ny ellanragh soit 'sy Cheayn Sheealtagh Meanagh. Ta shiartanse dy [[Thallooyn ny Steatyn Unnaneysit|hallooyn]] echey ta skeaylt magh mygeayrt y [[Yn Vooir Charibagh|Vooir Charibagh]] as y Cheayn Sheealtagh. ==Steatyn ny Steatyn Unnaneysit== {{Main|Steatyn ny Steatyn Unnaneysit}} [[Coadan:Map of USA with state names.svg|thumbnail|400px|left|Steatyn ny Steatyn Unnaneysit]] {| |- | * [[Alabama]] * [[Alaska]] * [[Arizona]] * [[Arkansas]] * [[California]] * [[Carolina Hwoaie]] * [[Carolina Yiass]] * [[Colorado]] * [[Connecticut]] * [[Dakota Hwoaie]] * [[Dakota Yiass]] * [[Delaware]] * [[Ellan Rhode]] * [[Florida]] * [[Yn Çhorshey (steat)|Yn Çhorshey]] * [[Hawaii]] * [[Idaho]] | * [[Illinois]] * [[Indiana]] * [[Iowa]] * [[Kansas]] * [[Kentucky]] * [[Louisiana]] * [[Maine]] * [[Maryland]] * [[Massachusetts]] * [[Michigan]] * [[Minnesota]] * [[Mississippi]] * [[Missouri]] * [[Montana]] * [[Nebraska]] * [[Nevada]] * [[New Hampshire]] | * [[New Jersey]] * [[New Mexico]] * [[Ohio]] * [[Oklahoma]] * [[Oregon]] * [[Pennsylvania]] * [[Tennessee]] * [[Texas]] * [[Utah]] * [[Vermont]] * [[Yn Virjeeney‎]] * [[Yn Virjeeney Heear‎]] * [[Washington (steat)|Washington]] * [[Wisconsin]] * [[Wyoming]] * [[York Noa (steat)|York Noa]] |} ==Noteyn== {{notelist}} ==Imraaghyn== {{reflist}} {{Yn Americkey Hwoaie}} {{G8}} {{RCAH}} {{Gurneil eaghtyrys}} {{bun}} {{Coord|40|-100|dim:10000000_region:region:US_type:country|name=United States of America|display=title}} [[Ronney:Ny Steatyn Unnaneysit| ]] [[Ronney:Çheeraghyn America Hwoaie]] [[Ronney:Pobblaghtyn bunraghtoil conastagh]] [[Ronney:Eear-choloinyn as eear-choadanyssyn Goaldagh ayns ny h-Americkyn]] [[Ronney:Eear-chochianglaghyn]] [[Ronney:Çheeraghyn y G20]] [[Ronney:Çheeraghyn-oltey Reagheydys Chonaant yn Atlantagh Hwoaie]] [[Ronney:Çheeraghyn-oltey ny h-Ashoonyn Unnaneysit]] [[Ronney:Steatyn as thallooyn bunnit 'sy vlein 1776]] pvlwg7ihavjdndq09g6g0d62wnb5g7r Steaytyn Unnaneysit 0 2310 392940 31926 2026-09-07T11:55:31Z EmausBot 2954 Fixing double redirect from [[Steatyn Unnaneysit America]] to [[Ny Steatyn Unnaneysit]] 392940 wikitext text/x-wiki #REDIRECT [[Ny Steatyn Unnaneysit]] 07m63uvowlvg6gkwbislwrjseaqgcv3 Ny Steaytyn Unnaneyssit 0 2311 392937 31927 2026-09-07T11:55:01Z EmausBot 2954 Fixing double redirect from [[Steatyn Unnaneysit America]] to [[Ny Steatyn Unnaneysit]] 392937 wikitext text/x-wiki #REDIRECT [[Ny Steatyn Unnaneysit]] 07m63uvowlvg6gkwbislwrjseaqgcv3 Ny Steaytyn Unnaneysit 0 2326 392936 31928 2026-09-07T11:54:51Z EmausBot 2954 Fixing double redirect from [[Steatyn Unnaneysit America]] to [[Ny Steatyn Unnaneysit]] 392936 wikitext text/x-wiki #REDIRECT [[Ny Steatyn Unnaneysit]] 07m63uvowlvg6gkwbislwrjseaqgcv3 Corys ny Greiney 0 3370 392829 390609 2026-09-06T13:37:04Z Omarius257 23226 /* */ 392829 wikitext text/x-wiki [[Coadan:Solar System True Color GV.png|upright=1.5|thumb|Corys ny Greiney]] She '''Corys ny Greiney''' ta shin gra rish [[yn Ghrian]] as ooilley ny [[planaidyn]] as nheeghyn elley ta goll mygeayrt-y-moee. Cha nel yn fockle shen currit agh da'n chorys ta mygeayrt ny Greiney. Ta'n enmys [[corys planaidagh]] currit er ny coryssyn ta mygeayrt rollageyn elley. Ta'n Ghrian soit ayns çheshvean y chorys. Ta 99.86 % dy vass y chorys 'sy Ghrian. Ta sateleetyn (eaystyn) cruinlaghey paart jeh ny planaidyn. Chammah as ny planaidyn, ta reddyn beggey dy liooar goll mygeayrt y Ghrian. Ny mast'oc shen ta asteroidjyn, claghyn-çhenney as commaidyn. She yn forsey-stoo eddyr y Ghrian as ny planaidyn as reddyn elley ta cummal ad er nyn goorseyn. She Curain y phlanaid sniessey da'n Ghrian as Neptioon y fer sodjey magh. She yn Dowan y trass phlanaid sniessey da'n Ghrian. Myr sniessey y phlanaid da'n Ghrian, sloo yn traa dy gholl mygeayrt y Ghrian un cheayrt. Myr sampleyr, ta Curain goll mygeayrt y Ghrian ayns 88 laa, agh ta Pluto goll mygeayrt un cheayrt ayns 248 jeh ny bleeanyn ainyn. Ayns nyn Gorys ny Greiney ta – * [[yn Ghrian]] hene (☉) * [[Planaid|Ny planaidyn]] (tree jeu crivassanagh as kiare jeu as fainaghyn oc) ** [[Curain]] ** [[Badlag]] ** [[yn Dowan]] ** [[Mart (planaid)|Mart]] ** [[Iupiter]] ** [[Sarn (planaid)|Sarn]] ** [[Uraanus]] ** [[Neptioon]] * [[Planaid Crivassanagh|Ny planaidyn crivassanagh]] ** [[Keres (planaid crivassanagh)|Keres]] ** [[Pluto]] ** [[Eris (planaid crivassanagh)|Eris]] * Reddyn Tessen-Neptioonagh ** [[Quaoar]] ** [[Sedna]] ** [[Ixion]] ** [[Varuna]] ** [[Cryss Kuiper]] ** [[Bodjal Oort]] * 169 eaystyn ta goll mygeayrt ny planaidyn (as foddee tooilley nagh vel fys ain er foast), chammah’s tousaneyn dy [[roltageyn]] as [[comaidyn]] as dreigaghyn as claghyn çhenney as meeryn dy yoan spoaragh. == Kianglaghyn magh == * [https://web.archive.org/web/20101126070519/http://learnmanx.com/cms/Corys%20ny%20Greiney%20reayrt%20lhean___________________________________4e61fa7621ea63c2067be16aa4fa976f________________________________.pdf Lessonyn er learnmanx.com] ([[Gaelg]]) * [http://science.nationalgeographic.com/science/space/solar-system National Geographic] ([[Baarle]]) {{Corys ny Greiney}} {{Raad Mooar Gorree}} {{gurneil eaghtyrys}} [[Ronney:Corys ny Greiney| ]] [[Ronney:Planaid-oaylleeaght]] [[Ronney:Coryssyn planaidagh as hoght planaid shickyrit oc|Greiney]] [[Ronney:Sheanse spoar]] t689s6n7lvsaxqcrgbbcsrrz7z5m9hn Ny Steatyn Unnaneyssit 0 4006 392935 31929 2026-09-07T11:54:41Z EmausBot 2954 Fixing double redirect from [[Steatyn Unnaneysit America]] to [[Ny Steatyn Unnaneysit]] 392935 wikitext text/x-wiki #REDIRECT [[Ny Steatyn Unnaneysit]] 07m63uvowlvg6gkwbislwrjseaqgcv3 SUA 0 4213 392938 31930 2026-09-07T11:55:11Z EmausBot 2954 Fixing double redirect from [[Steatyn Unnaneysit America]] to [[Ny Steatyn Unnaneysit]] 392938 wikitext text/x-wiki #REDIRECT [[Ny Steatyn Unnaneysit]] 07m63uvowlvg6gkwbislwrjseaqgcv3 Steatyn Unnaneysit 0 9451 392939 59376 2026-09-07T11:55:21Z EmausBot 2954 Fixing double redirect from [[Steatyn Unnaneysit America]] to [[Ny Steatyn Unnaneysit]] 392939 wikitext text/x-wiki #REDIRECT [[Ny Steatyn Unnaneysit]] 07m63uvowlvg6gkwbislwrjseaqgcv3 Milla Jovovich 0 23831 392890 378405 2026-09-07T01:29:21Z PaulLim11 23221 Image 392890 wikitext text/x-wiki {{WD Kishtey Fys Dooinney | jalloo = Milla Jovovich - Protector.jpg | fo-heidyl = Jovovich 'sy vlein 2026 | boayl_ruggyr = [[Kyiv]], [[Pobblaght Hoveidjagh Hoshiallagh ny h-Ookraan|PHH yn Ookraan]], [[yn Unnaneys Soveidjagh]] <small>([[yn Ookraan]] jiu)</small> | bleeantyngobbyr = 1985–jiu }} She ben-aghteyr, ard-chraishteyder, as arraneyder Americaanagh ee '''Milica Bogdanovna Jovovich''' ({{lang-sr|Милица Богдановна Јововић}}; {{lang-ru|Милица Богдановна Йовович}}; {{lang-uk|Милиця Богданівна Йовович}}; ruggit er 17 Nollick 1975), ta goll er enney dy keirdagh myr '''Milla Jovovich'''.<ref>{{cite web|url=http://millaj.com/faq.shtml|title=Milla Jovovich Official Site|website=millaj.com|accessdate=11 Jerrey Souree 2017|archive-date=2017-07-07|archive-url=https://web.archive.org/web/20170707003739/http://www.millaj.com/faq.shtml|url-status=dead}}</ref> Va Jovovich ruggit ayns [[Kyiv]], [[Pobblaght Hoveidjagh Hoshiallagh ny h-Ookraan|PHH yn Ookraan]], [[yn Unnaneys Soveidjagh]], agh ren ish as e lught thie arraghey dys [[Lunnin]] tra v'ee queig bleeaney d'eash as, lurg shen, ren ad arraghey dys [[Sacramento, California]]; fy yerrey, ren ad arraghey dys [[Los Angeles]] shiaght mee ny s'anmey. Ayns 1987, tra v'ee 12 vleeaney d'eash, hoshee ee craishtey tra ren [[Herb Ritts]] jannoo fotograafyn jee son coodagh yn earishlioar Iddaalagh ''Lei''.<ref name="PurpleLove">{{cite web |title=Millaj:Purple Love |publisher=MillaJ.com |work=Purple magazine |year=1990 |url=http://www.millaj.com/archive/archive09.shtml |accessdate=15 Boaldyn 2013 |archive-date=2013-08-07 |archive-url=https://web.archive.org/web/20130807133606/http://www.millaj.com/archive/archive09.shtml |url-status=dead }}</ref><ref>{{cite web |url=https://www.huffpost.com/entry/milla-jovovich-magazine-cover_n_1018495 |title=Milla Jovovich Magazine Cover, 1987: A Look Back |last1=Leon |first1=Sarah |date=19 Jerrey Fouyir 2011 |work=[[The Huffington Post]] |accessdate=15 Boaldyn 2013}}</ref> Ren [[Richard Avedon]] cur ish ayns ny soilsheenyn "Most Unforgettable Women in the World" liorish [[Revlon]].<ref>{{cite web | url =https://www.papermag.com/milla-jovovichs-paper-covers-a-retrospective-1427178466.html |title=Milla Jovovich's Paper Covers, a Retrospective |work=[[Paper (earishlioar)|Paper]]|first=Maggie|last=Dolan| date=17 Nollick 2013 | archiveurl=https://web.archive.org/web/20190708125354/https://www.papermag.com/milla-jovovichs-paper-covers-a-retrospective-1427178466.html | accessdate =9 Boaldyn 2015 | archivedate=8 Jerrey Souree 2019 }}</ref> Ayns 1988, ren Jovovich cloie da'n chied cheayrt er y scaailan 'sy fillym çhellveeish ''[[The Night Train to Kathmandu]]'' as ren ee cloie 'sy chied mooar-fillym eck, ''[[Two Moon Junction]]''. Hooar Jovovich enney mooar son e paart 'sy fillym romansagh ''[[Return to the Blue Lagoon]]'' (1991) er yn oyr nagh row ee agh 15 bleeaney d'eash.<ref>{{cite web |url=http://www.millaj.com/film/ |title=Milla Jovovich Filmography |author=<!--Staff writer(s); no by-line.--> |website=MillaJ.com |accessdate=28 Sauin 2013 |archive-date=2013-12-04 |archive-url=https://web.archive.org/web/20131204073319/http://www.millaj.com/film/ |url-status=dead }}</ref> T'eh er smooinaghtyn dy nee yn paart v'eck 'sy fillym jantys far-skeealagh sheanse Frangagh ''[[The Fifth Element]]'' (1997) liorish [[Luc Besson]] yn paart foshlee eck. Ren ee as Besson poosey ny s'anmey 'sy vlein shen, agh scarr ad voish y cheilley tammylt veg ny yei. Ren ee cloie y ben-eniagh as y martyr ayns ''[[The Messenger: The Story of Joan of Arc]]'' (1999) liorish Besson. Eddyr ny bleeantyn 2002 as 2016, ren Jovovich cloie Alice 'sy straih fillym atçhim jantys ''[[Resident Evil (straih fillym)|Resident Evil]]'',<ref name="new release date">{{cite news|url=http://www.shocktillyoudrop.com/news/topnews.php?id=13587 |title=Resident Evil: Afterlife Back to 2010 |website=ShockTilYouDrop.com |publisher=[[CraveOnline]] |date=11 Jerrey Geuree 2010 |accessdate=15 Boaldyn 2013 |url-status=dead |archiveurl=https://www.webcitation.org/5qH8LzFMZ?url=http://www.shocktillyoudrop.com/news/topnews.php?id=13587 |archivedate=6 Mean Souree 2010 }}</ref> hie er ve yn straih fillym smoo berçhagh va bunnit er gammanyn-feeshan.<ref>{{cite web |url=https://variety.com/2017/film/global/resident-evil-reboot-cannes-film-festival-1202439086/ |work=Variety |title='Resident Evil' Franchise Set for a Reboot (EXCLUSIVE) |date=21 Boaldyn 2017 |first=John |last=Hopewell |accessdate=19 Mayrnt 2018}}</ref> Ren Jovovich skeaylley magh e chied albym, ''[[The Divine Comedy (albym Milla Jovovich)|The Divine Comedy]]'', ayns 1994, as e nah albym, ''[[The People Tree Sessions]]'', ayns 1998. T'ee foast skeaylley magh prowallyn er yn ynnyd-eggey oikoil eck as dy mennick t'ee cur rish cassanyn-sheean fillym. Ayns 2003, ren ee as y craishteyder Carmen Hawk croo yn linney eaddeeyn [[Jovovich–Hawk]], hie magh derrey 2008. She Creature Entertainment e colught gientyn hene eck. ==Imraaghyn== {{rolleyimraaghyn}} ==Kianglaghyn magh== {{Wikiquote}} {{Commonscategory}} * {{Official website}} * {{IMDb name|0000170}} {{Gurneil eaghtyrys}} {{DEFAULTSORT:Jovovich, Milla}} [[Ronney:Ruggyryn 'sy vlein 1975]] [[Ronney:Feallee vio]] [[Ronney:Aghteyryn ass California]] [[Ronney:Feallee ass Los Angeles]] [[Ronney:Craishteyderyn bwoirrin Americaanagh]] [[Ronney:Aghteyryn fillym bwoirrin Americaanagh]] [[Ronney:Aghteyryn çhellveeish bwoirrin Americaanagh]] [[Ronney:Ellyneyryn SBK Records]] [[Ronney:Ookraanee jeh sluight Serbagh]] [[Ronney:Ookraanee jeh sluight Montenegragh]] [[Ronney:Americaanee jeh sluight Montenegragh]] [[Ronney:Americaanee jeh sluight Rooshagh]] [[Ronney:Americaanee jeh sluight Ookraanagh]] [[Ronney:Ookraanee jeh sluight Rooshagh]] [[Ronney:Arraneyderyn bwoirrin Americaanagh]] [[Ronney:Feallee ass Kyiv]] [[Ronney:Feallee ass Moscow]] noqsyfv9sx67rgj3foxh60rupvtfthv Clowan:Kishtey fys çheer/noa 10 55826 392815 392805 2026-09-06T12:23:46Z MacTire02 219 +lipaid as ream 392815 wikitext text/x-wiki <includeonly> {{Infobox | above = {{#invoke:Kishtey fys çheer|title}} | image = {{#invoke:Kishtey fys çheer|images}} | caption = {{#invoke:Kishtey fys çheer|captions}} | data1 = {{#invoke:Kishtey fys çheer|symbols}} | data2 = {{#invoke:Kishtey fys çheer|map}} | label3 = {{#invoke:Kishtey fys çheer|city_label}} | data3 = {{#invoke:Kishtey fys çheer|city_data}} }} </includeonly> nqp4fqgu9zglyesa08es1hfgosm1s49 392821 392815 2026-09-06T12:36:54Z MacTire02 219 prowal red bentyn rish ny h-ard-valjyn 392821 wikitext text/x-wiki <includeonly> {{Infobox | above = {{#invoke:Kishtey fys çheer|title}} | image = {{#invoke:Kishtey fys çheer|images}} | caption = {{#invoke:Kishtey fys çheer|captions}} | data1 = {{#invoke:Kishtey fys çheer|symbols}} | data2 = {{#invoke:Kishtey fys çheer|map}} | label3 = {{#invoke:Kishtey fys çheer|city_label}} | data3 = {{#invoke:Kishtey fys çheer|city_data}} | data4 = {{#invoke:Kishtey fys çheer|test_largest}} }} </includeonly> g2pe1k35o2065w7sbqrfm36eszivze9 392824 392821 2026-09-06T12:38:37Z MacTire02 219 Undid revision [[Special:Diff/392821|392821]] by [[Special:Contributions/MacTire02|MacTire02]] ([[User talk:MacTire02|talk]]) 392824 wikitext text/x-wiki <includeonly> {{Infobox | above = {{#invoke:Kishtey fys çheer|title}} | image = {{#invoke:Kishtey fys çheer|images}} | caption = {{#invoke:Kishtey fys çheer|captions}} | data1 = {{#invoke:Kishtey fys çheer|symbols}} | data2 = {{#invoke:Kishtey fys çheer|map}} | label3 = {{#invoke:Kishtey fys çheer|city_label}} | data3 = {{#invoke:Kishtey fys çheer|city_data}} }} </includeonly> nqp4fqgu9zglyesa08es1hfgosm1s49 392833 392824 2026-09-06T13:46:26Z MacTire02 219 prowal 392833 wikitext text/x-wiki <includeonly> {{Infobox | above = {{#invoke:Kishtey fys çheer|title}} | image = {{#invoke:Kishtey fys çheer|images}} | caption = {{#invoke:Kishtey fys çheer|captions}} | data1 = {{#invoke:Kishtey fys çheer|symbols}} | data2 = {{#invoke:Kishtey fys çheer|map}} | label3 = {{#invoke:Kishtey fys çheer|city_label}} | data3 = {{#invoke:Kishtey fys çheer|city_data}} | data4 = {{#invoke:Kishtey fys çheer|test_city}} }} </includeonly> dts98z4zvrgx0uf89t2bmbb1a3867sw 392835 392833 2026-09-06T13:50:10Z MacTire02 219 prowal 392835 wikitext text/x-wiki <includeonly> {{Infobox | above = {{#invoke:Kishtey fys çheer|title}} | image = {{#invoke:Kishtey fys çheer|images}} | caption = {{#invoke:Kishtey fys çheer|captions}} | data1 = {{#invoke:Kishtey fys çheer|symbols}} | data2 = {{#invoke:Kishtey fys çheer|map}} | label3 = {{#invoke:Kishtey fys çheer|city_label}} | data3 = {{#invoke:Kishtey fys çheer|city_data}} | data4 = {{#invoke:Kishtey fys çheer|test_city}} | data5 = {{#invoke:Kishtey fys çheer|test_city}} }} </includeonly> er0klcb0vzzg193011m6k7m4gi8nytv 392836 392835 2026-09-06T13:52:29Z MacTire02 219 prowal 392836 wikitext text/x-wiki <includeonly> {{Infobox | above = {{#invoke:Kishtey fys çheer|title}} | image = {{#invoke:Kishtey fys çheer|images}} | caption = {{#invoke:Kishtey fys çheer|captions}} | data1 = {{#invoke:Kishtey fys çheer|symbols}} | data2 = {{#invoke:Kishtey fys çheer|map}} | label3 = {{#invoke:Kishtey fys çheer|city_label}} | data3 = {{#invoke:Kishtey fys çheer|city_data}} | data4 = {{#invoke:Kishtey fys çheer|test_city}} }} </includeonly> j7np7zv4nkaej187t0e2tt8fohdocda 392848 392836 2026-09-06T15:23:01Z MacTire02 219 prowal 392848 wikitext text/x-wiki <includeonly> {{Infobox | above = {{#invoke:Kishtey fys çheer|title}} | image = {{#invoke:Kishtey fys çheer|images}} | caption = {{#invoke:Kishtey fys çheer|captions}} | data1 = {{#invoke:Kishtey fys çheer|symbols}} | data2 = {{#invoke:Kishtey fys çheer|map}} | label3 = {{#invoke:Kishtey fys çheer|city_label}} | data3 = {{#invoke:Kishtey fys çheer|city_data}} }} </includeonly> nqp4fqgu9zglyesa08es1hfgosm1s49 392852 392848 2026-09-06T15:43:51Z MacTire02 219 -- 392852 wikitext text/x-wiki <includeonly>{{#invoke:Kishtey fys çheer|main}}</includeonly> rk4zkhojf4vqfembfx2qzlv5eejqmyv 392858 392852 2026-09-06T16:55:09Z MacTire02 219 ++ 392858 wikitext text/x-wiki <includeonly> {{Infobox | bodyclass = vcard | child = {{{child|}}} | subbox = {{{subbox|}}} | bodystyle = width:23em; line-height:1.5em; border:1px solid #a2a9b1; | {{#invoke:Kishtey fys çheer|main}} }} </includeonly> pfi1qxm39338p1raa8ojpflyki69cxk 392860 392858 2026-09-06T16:58:09Z MacTire02 219 Undid revision [[Special:Diff/392858|392858]] by [[Special:Contributions/MacTire02|MacTire02]] ([[User talk:MacTire02|talk]]) 392860 wikitext text/x-wiki <includeonly>{{#invoke:Kishtey fys çheer|main}}</includeonly> rk4zkhojf4vqfembfx2qzlv5eejqmyv 392877 392860 2026-09-06T20:35:35Z MacTire02 219 prowal 392877 wikitext text/x-wiki <includeonly>{{#invoke:Kishtey fys çheer|debug_render}}</includeonly> ngpm23jjl6s35mgii7ldapa89b5t2v3 392879 392877 2026-09-06T20:39:28Z MacTire02 219 cur reddyn er ash 392879 wikitext text/x-wiki <includeonly>{{#invoke:Kishtey fys çheer|main}}</includeonly> rk4zkhojf4vqfembfx2qzlv5eejqmyv Module:Kishtey fys çheer 828 55827 392811 392810 2026-09-06T12:07:05Z MacTire02 219 ++ 392811 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override local function getArgs(frame) return frame:getParent().args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local value = mainsnak.datavalue.value if value and value ~= "" then return value end end end return nil end ------------------------------------------------------------ -- Wikidata item statement ------------------------------------------------------------ local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end ------------------------------------------------------------ -- Wikidata reference URL ------------------------------------------------------------ local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end ------------------------------------------------------------ -- Wikidata locator map ------------------------------------------------------------ local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Locator map data ------------------------------------------------------------ local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end ------------------------------------------------------------ -- Locator map ------------------------------------------------------------ function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end ------------------------------------------------------------ -- Capital / administrative centre data ------------------------------------------------------------ local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end -------------------------------------------------------- -- Manual capital -------------------------------------------------------- if capital then return { text = capital, entity = nil, reference = nil } end -------------------------------------------------------- -- Wikidata P36 = capital -------------------------------------------------------- local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Administrative centre data ------------------------------------------------------------ local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre } end return nil end ------------------------------------------------------------ -- Largest city / settlement data ------------------------------------------------------------ local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end -------------------------------------------------------- -- Manual largest city -------------------------------------------------------- if city then return { text = city, entity = nil, reference = nil } end -------------------------------------------------------- -- Wikidata P13574 = most populous urban area -------------------------------------------------------- local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Capital / administrative centre labels ------------------------------------------------------------ local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end ------------------------------------------------------------ -- City / settlement data ------------------------------------------------------------ local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end ------------------------------------------------------------ -- Determine whether the capital is the largest city ------------------------------------------------------------ local function capitalIsLargest(capital, largest) if not capital or not largest then return false end -------------------------------------------------------- -- Best method: compare Wikidata entity IDs -------------------------------------------------------- if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end -------------------------------------------------------- -- Fallback: compare displayed names -------------------------------------------------------- local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return capitalText == largestText end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return capitalText == largestText end ------------------------------------------------------------ -- Link city name to its article ------------------------------------------------------------ local function makeCityLink(city) if not city or not city.text then return "" end -------------------------------------------------------- -- If we have the Wikidata entity, use its Manx -- Wikipedia sitelink. -------------------------------------------------------- if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. city.text .. "]]" end end -------------------------------------------------------- -- Fallback: link to the displayed name. -------------------------------------------------------- return "[[" .. city.text .. "|" .. city.text .. "]]" end ------------------------------------------------------------ -- Link city name to its article ------------------------------------------------------------ local function makeCityLink(city) if not city or not city.text then return "" end -------------------------------------------------------- -- If we have the Wikidata entity, use its Manx -- Wikipedia sitelink. -------------------------------------------------------- if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. city.text .. "]]" end end -------------------------------------------------------- -- Fallback: link to the displayed name. -------------------------------------------------------- return "[[" .. city.text .. "|" .. city.text .. "]]" end ------------------------------------------------------------ -- Capital / largest city / administrative centre ------------------------------------------------------------ function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} -------------------------------------------------------- -- Capital / administrative centre -------------------------------------------------------- if capital or administrative then local label local text ---------------------------------------------------- -- Capital ---------------------------------------------------- if capital then -- Always link the label to the Preeu-valley article. label = "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" ------------------------------------------------ -- Capital city ------------------------------------------------ text = makeCityLink(capital) ------------------------------------------------ -- Capital is also largest city ------------------------------------------------ if capitalIsLargest(capital, largest) then text = text .. '<br/><small>(as y balley smoo)</small>' end ------------------------------------------------ -- Coordinates directly underneath city name ------------------------------------------------ if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/>' .. coordinates end end ------------------------------------------------ -- Wikidata reference ------------------------------------------------ if capital.reference then text = text .. capital.reference end ---------------------------------------------------- -- Administrative centre only ---------------------------------------------------- else label = "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" text = makeCityLink(administrative) end table.insert( rows, "'''" .. label .. ":&nbsp;'''" .. text ) ---------------------------------------------------- -- Add largest city when different from capital ---------------------------------------------------- if largest and not capitalIsLargest(capital, largest) then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- No capital or administrative centre -- but largest city exists -------------------------------------------------------- elseif largest then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- Nothing to display -------------------------------------------------------- if #rows == 0 then return nil end return mw.text.listToText( rows, "<br/>", "<br/>" ) end ------------------------------------------------------------ -- Wikidata audio file ------------------------------------------------------------ local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Anthems ------------------------------------------------------------ local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil -- P3831 = object of statement has role. -- This may identify the anthem as national, -- royal, regional, etc. if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { label = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end ------------------------------------------------------------ -- Classify anthems ------------------------------------------------------------ local function classifyAnthems(anthems) local national = {} local royal = {} local other = {} for _, anthem in ipairs(anthems) do local role = anthem.role if role then role = mw.ustring.lower(role) end if role and mw.ustring.find(role, "royal") then table.insert(royal, anthem) elseif role and ( mw.ustring.find(role, "national") or mw.ustring.find(role, "state anthem") ) then table.insert(national, anthem) else table.insert(other, anthem) end end -- If Wikidata has supplied an anthem but has not given -- it a role, treat the first such anthem as the national -- anthem. P85 is normally used for the country's official -- anthem. if #national == 0 and #other > 0 then table.insert(national, other[1]) table.remove(other, 1) end return national, royal, other end ------------------------------------------------------------ -- Anthem data ------------------------------------------------------------ local function getAnthemData(args) local anthems = getAnthems() local national, royal, other = classifyAnthems(anthems) local result = {} -------------------------------------------------------- -- National anthem -------------------------------------------------------- local manualNational = getManual(args, { "arrane_ashoonagh" }) if manualNational then if mw.ustring.lower(manualNational) ~= "none" then result.national = { text = '"' .. manualNational .. '"', reference = getManual(args, { "imraa_arrane_ashoonagh" }), audio = nil } end elseif #national > 0 then result.national = { text = national[1].label, reference = national[1].reference, audio = national[1].audio } end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- local manualRoyal = getManual(args, { "arrane_reeoil" }) if manualRoyal then if mw.ustring.lower(manualRoyal) ~= "none" then result.royal = { text = '"' .. manualRoyal .. '"', reference = getManual(args, { "imraa_arrane_reeoil" }), audio = nil } end elseif #royal > 0 then result.royal = { text = '"' .. royal[1].label .. '"', reference = royal[1].reference, audio = royal[1].audio } end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- local manualOther = getManual(args, { "arrane" }) if manualOther then if mw.ustring.lower(manualOther) ~= "none" then result.other = { text = '"' .. manualOther .. '"', reference = getManual(args, { "imraa_arrane" }), audio = nil } end elseif #other > 0 then result.other = { text = '"' .. other[1].label .. '"', reference = other[1].reference, audio = other[1].audio } end return result end ------------------------------------------------------------ -- Motto ------------------------------------------------------------ local function getMotto() local entity = mw.wikibase.getEntityObject() if not entity then return nil, nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil, nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return value.text, getWikidataReference(statement) end end end return nil, nil end ------------------------------------------------------------ -- Motto data ------------------------------------------------------------ local function getMottoData(args) local manual = getManual(args, { "jarroo-raa_ashoonagh", "jarroo-raa" }) if manual then if mw.ustring.lower(manual) == "none" then return nil end return { text = manual, reference = getManual(args, { "imraa_jarroo-raa" }) } end local text, reference = getMotto() if not text then return nil end return { text = text, reference = reference } end ------------------------------------------------------------ -- Motto and anthem output ------------------------------------------------------------ function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} -------------------------------------------------------- -- Motto -------------------------------------------------------- if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- National anthem -------------------------------------------------------- if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '""' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '""' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end ------------------------------------------------------------ -- Flag ------------------------------------------------------------ local function getFlag(args) -- Manual value takes precedence over Wikidata. local manual = getManual(args, { "jalloo_brattagh" }) if manual then if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P41 = flag image. return getWikidataImage("P41") end ------------------------------------------------------------ -- Coat of arms ------------------------------------------------------------ local function getArms(args) -- Manual value takes precedence over Wikidata. -- jalloo_armys is the preferred new parameter. -- jalloo_cleinney and jalloo_cowrey remain supported -- for compatibility with existing articles. local manual = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if manual then -- Explicitly suppress Wikidata. if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P94 = coat of arms image. return getWikidataImage("P94") end ------------------------------------------------------------ -- Country name ------------------------------------------------------------ local function getCountryName(args) return args.ennym_gienneydagh or args.kianglaghey_ennym or args.ennym or mw.title.getCurrentTitle().text end local function getGenitiveName(args) local name = getCountryName(args) return enmynCheerey.genitive(name) end ------------------------------------------------------------ -- Official name (Wikidata P1448) ------------------------------------------------------------ local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" and value.language and value.language ~= "" then table.insert(names, { text = value.text, lang = mw.ustring.lower(value.language) }) end end end return names end ------------------------------------------------------------ -- Language name ------------------------------------------------------------ local function getLanguageName(code) if not code or code == "" then return code end code = mw.ustring.lower(code) -- Manx Wikipedia language-name override. if langOverrideTable and langOverrideTable[code] then local name = langOverrideTable[code] if type(name) == "table" then return name[1] end return name end -- Standard language-name table. if langNameTable and langNameTable[code] then local name = langNameTable[code] if type(name) == "table" then return name[1] end return name end return code end ------------------------------------------------------------ -- Language label ------------------------------------------------------------ local function makeLanguageLabel(code) local languageName = getLanguageName(code) if not languageName or languageName == "" then return "" end -- The language name is deliberately NOT italicised. return mw.text.tag( "small", {}, "([[" .. languageName .. "|" .. languageName .. "]])" ) end ------------------------------------------------------------ -- Country title ------------------------------------------------------------ function p.title(frame) local args = getArgs(frame) local countryName = getCountryName(args) local officialNames = getOfficialNames() local manxName = nil local otherNames = {} -- Find the Manx official name first. for _, item in ipairs(officialNames) do if item.lang == "gv" then manxName = item.text break end end -- If Wikidata has no Manx P1448, use the short Manx country name. if not manxName then manxName = countryName end local output = {} -- Manx country name. -- Explicitly set the font and weight rather than inheriting -- the styling of the Infobox "above" field. table.insert( output, '<span style="font-family:inherit; font-weight:bold;">' .. manxName .. '</span>' ) -- Other official-language names. -- These must explicitly be normal weight. for _, item in ipairs(officialNames) do if item.lang ~= "gv" then local languageLabel = makeLanguageLabel(item.lang) local line = '<span style="font-weight:normal;">' .. item.text if languageLabel ~= "" then line = line .. " " .. languageLabel end line = line .. "</span>" table.insert(output, line) end end return table.concat(output, "<br>") end ------------------------------------------------------------ -- Images ------------------------------------------------------------ function p.images(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</td>' .. '<td style="width:42%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</td>' .. '</tr></table>', flag, arms, args.lheead_cowrey or "85px" ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</div>', flag ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</div>', arms, args.lheead_cowrey or "85px" ) end ------------------------------------------------------------ -- Captions ------------------------------------------------------------ function p.captions(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end local countryName = getCountryName(args) local genitiveName = getGenitiveName(args) local flagCaption = args["fo-heidyl_brattagh"] or "Brattagh" local armsCaption = args["sorçh_cowrey"] or "Armys" local armsArticle = args["art_sorçh_cowrey"] or "Armys" -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</td>' .. '<td style="width:42%%; text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</td>' .. '</tr></table>', genitiveName, flagCaption, armsArticle, genitiveName, armsCaption ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</div>', genitiveName, flagCaption ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</div>', armsArticle, genitiveName, armsCaption ) end return p 4h7obc66u2zkktrr6ajknw350wvjwbs 392812 392811 2026-09-06T12:11:58Z MacTire02 219 ++ 392812 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override local function getArgs(frame) return frame:getParent().args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local value = mainsnak.datavalue.value if value and value ~= "" then return value end end end return nil end ------------------------------------------------------------ -- Wikidata item statement ------------------------------------------------------------ local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end ------------------------------------------------------------ -- Wikidata reference URL ------------------------------------------------------------ local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end ------------------------------------------------------------ -- Wikidata locator map ------------------------------------------------------------ local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Locator map data ------------------------------------------------------------ local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end ------------------------------------------------------------ -- Locator map ------------------------------------------------------------ function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end ------------------------------------------------------------ -- Capital / administrative centre data ------------------------------------------------------------ local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end -------------------------------------------------------- -- Manual capital -------------------------------------------------------- if capital then return { text = capital, entity = nil, reference = nil } end -------------------------------------------------------- -- Wikidata P36 = capital -------------------------------------------------------- local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Administrative centre data ------------------------------------------------------------ local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre } end return nil end ------------------------------------------------------------ -- Largest city / settlement data ------------------------------------------------------------ local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end -------------------------------------------------------- -- Manual largest city -------------------------------------------------------- if city then return { text = city, entity = nil, reference = nil } end -------------------------------------------------------- -- Wikidata P13574 = most populous urban area -------------------------------------------------------- local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Capital / administrative centre labels ------------------------------------------------------------ local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end ------------------------------------------------------------ -- City / settlement data ------------------------------------------------------------ local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end ------------------------------------------------------------ -- Normalise a city name for comparison ------------------------------------------------------------ local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) -------------------------------------------------------- -- Remove simple wikilink markup -------------------------------------------------------- value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") -------------------------------------------------------- -- If the link has a pipe, retain only the target -------------------------------------------------------- local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end ------------------------------------------------------------ -- Determine whether capital is the largest city ------------------------------------------------------------ local function capitalIsLargest(capital, largest) if not capital or not largest then return false end -------------------------------------------------------- -- Best method: compare Wikidata entity IDs -------------------------------------------------------- if capital.entity and largest.entity then if capital.entity.id and largest.entity.id and capital.entity.id == largest.entity.id then return true end end -------------------------------------------------------- -- Fallback: compare names -------------------------------------------------------- local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end ------------------------------------------------------------ -- Link city name to its article ------------------------------------------------------------ local function makeCityLink(city) if not city or not city.text then return "" end -------------------------------------------------------- -- If we have the Wikidata entity, use its Manx -- Wikipedia sitelink. -------------------------------------------------------- if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. city.text .. "]]" end end -------------------------------------------------------- -- Fallback: link to the displayed name itself. -------------------------------------------------------- return "[[" .. city.text .. "|" .. city.text .. "]]" end ------------------------------------------------------------ -- Coordinates ------------------------------------------------------------ local function makeCoordinates(entity) if not entity then return nil end -------------------------------------------------------- -- Wikidata P625 = coordinate location -------------------------------------------------------- local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return string.format( "{{coord|%s|%s|display=inline}}", value.latitude, value.longitude ) end end end return nil end ------------------------------------------------------------ -- Capital / largest city / administrative centre ------------------------------------------------------------ function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} -------------------------------------------------------- -- Capital / administrative centre -------------------------------------------------------- if capital or administrative then local label local text ---------------------------------------------------- -- Capital ---------------------------------------------------- if capital then ------------------------------------------------ -- Link the label to Preeu-valley ------------------------------------------------ label = "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" ------------------------------------------------ -- Link the capital city ------------------------------------------------ text = makeCityLink(capital) ------------------------------------------------ -- Capital is also largest city ------------------------------------------------ if capitalIsLargest(capital, largest) then text = text .. '<br/><small>(as y balley smoo)</small>' end ------------------------------------------------ -- Coordinates directly underneath the city ------------------------------------------------ if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end ------------------------------------------------ -- Wikidata reference ------------------------------------------------ if capital.reference then text = text .. capital.reference end ---------------------------------------------------- -- Administrative centre only ---------------------------------------------------- else label = "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" text = makeCityLink(administrative) end table.insert( rows, "'''" .. label .. ":&nbsp;'''" .. text ) ---------------------------------------------------- -- Add largest city when different from capital ---------------------------------------------------- if largest and not capitalIsLargest(capital, largest) then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- No capital or administrative centre, -- but largest city exists -------------------------------------------------------- elseif largest then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- Nothing to display -------------------------------------------------------- if #rows == 0 then return nil end return mw.text.listToText( rows, "<br/>", "<br/>" ) end ------------------------------------------------------------ -- Wikidata audio file ------------------------------------------------------------ local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Anthems ------------------------------------------------------------ local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil -- P3831 = object of statement has role. -- This may identify the anthem as national, -- royal, regional, etc. if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { label = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end ------------------------------------------------------------ -- Classify anthems ------------------------------------------------------------ local function classifyAnthems(anthems) local national = {} local royal = {} local other = {} for _, anthem in ipairs(anthems) do local role = anthem.role if role then role = mw.ustring.lower(role) end if role and mw.ustring.find(role, "royal") then table.insert(royal, anthem) elseif role and ( mw.ustring.find(role, "national") or mw.ustring.find(role, "state anthem") ) then table.insert(national, anthem) else table.insert(other, anthem) end end -- If Wikidata has supplied an anthem but has not given -- it a role, treat the first such anthem as the national -- anthem. P85 is normally used for the country's official -- anthem. if #national == 0 and #other > 0 then table.insert(national, other[1]) table.remove(other, 1) end return national, royal, other end ------------------------------------------------------------ -- Anthem data ------------------------------------------------------------ local function getAnthemData(args) local anthems = getAnthems() local national, royal, other = classifyAnthems(anthems) local result = {} -------------------------------------------------------- -- National anthem -------------------------------------------------------- local manualNational = getManual(args, { "arrane_ashoonagh" }) if manualNational then if mw.ustring.lower(manualNational) ~= "none" then result.national = { text = '"' .. manualNational .. '"', reference = getManual(args, { "imraa_arrane_ashoonagh" }), audio = nil } end elseif #national > 0 then result.national = { text = national[1].label, reference = national[1].reference, audio = national[1].audio } end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- local manualRoyal = getManual(args, { "arrane_reeoil" }) if manualRoyal then if mw.ustring.lower(manualRoyal) ~= "none" then result.royal = { text = '"' .. manualRoyal .. '"', reference = getManual(args, { "imraa_arrane_reeoil" }), audio = nil } end elseif #royal > 0 then result.royal = { text = '"' .. royal[1].label .. '"', reference = royal[1].reference, audio = royal[1].audio } end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- local manualOther = getManual(args, { "arrane" }) if manualOther then if mw.ustring.lower(manualOther) ~= "none" then result.other = { text = '"' .. manualOther .. '"', reference = getManual(args, { "imraa_arrane" }), audio = nil } end elseif #other > 0 then result.other = { text = '"' .. other[1].label .. '"', reference = other[1].reference, audio = other[1].audio } end return result end ------------------------------------------------------------ -- Motto ------------------------------------------------------------ local function getMotto() local entity = mw.wikibase.getEntityObject() if not entity then return nil, nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil, nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return value.text, getWikidataReference(statement) end end end return nil, nil end ------------------------------------------------------------ -- Motto data ------------------------------------------------------------ local function getMottoData(args) local manual = getManual(args, { "jarroo-raa_ashoonagh", "jarroo-raa" }) if manual then if mw.ustring.lower(manual) == "none" then return nil end return { text = manual, reference = getManual(args, { "imraa_jarroo-raa" }) } end local text, reference = getMotto() if not text then return nil end return { text = text, reference = reference } end ------------------------------------------------------------ -- Motto and anthem output ------------------------------------------------------------ function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} -------------------------------------------------------- -- Motto -------------------------------------------------------- if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- National anthem -------------------------------------------------------- if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '""' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '""' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end ------------------------------------------------------------ -- Flag ------------------------------------------------------------ local function getFlag(args) -- Manual value takes precedence over Wikidata. local manual = getManual(args, { "jalloo_brattagh" }) if manual then if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P41 = flag image. return getWikidataImage("P41") end ------------------------------------------------------------ -- Coat of arms ------------------------------------------------------------ local function getArms(args) -- Manual value takes precedence over Wikidata. -- jalloo_armys is the preferred new parameter. -- jalloo_cleinney and jalloo_cowrey remain supported -- for compatibility with existing articles. local manual = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if manual then -- Explicitly suppress Wikidata. if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P94 = coat of arms image. return getWikidataImage("P94") end ------------------------------------------------------------ -- Country name ------------------------------------------------------------ local function getCountryName(args) return args.ennym_gienneydagh or args.kianglaghey_ennym or args.ennym or mw.title.getCurrentTitle().text end local function getGenitiveName(args) local name = getCountryName(args) return enmynCheerey.genitive(name) end ------------------------------------------------------------ -- Official name (Wikidata P1448) ------------------------------------------------------------ local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" and value.language and value.language ~= "" then table.insert(names, { text = value.text, lang = mw.ustring.lower(value.language) }) end end end return names end ------------------------------------------------------------ -- Language name ------------------------------------------------------------ local function getLanguageName(code) if not code or code == "" then return code end code = mw.ustring.lower(code) -- Manx Wikipedia language-name override. if langOverrideTable and langOverrideTable[code] then local name = langOverrideTable[code] if type(name) == "table" then return name[1] end return name end -- Standard language-name table. if langNameTable and langNameTable[code] then local name = langNameTable[code] if type(name) == "table" then return name[1] end return name end return code end ------------------------------------------------------------ -- Language label ------------------------------------------------------------ local function makeLanguageLabel(code) local languageName = getLanguageName(code) if not languageName or languageName == "" then return "" end -- The language name is deliberately NOT italicised. return mw.text.tag( "small", {}, "([[" .. languageName .. "|" .. languageName .. "]])" ) end ------------------------------------------------------------ -- Country title ------------------------------------------------------------ function p.title(frame) local args = getArgs(frame) local countryName = getCountryName(args) local officialNames = getOfficialNames() local manxName = nil local otherNames = {} -- Find the Manx official name first. for _, item in ipairs(officialNames) do if item.lang == "gv" then manxName = item.text break end end -- If Wikidata has no Manx P1448, use the short Manx country name. if not manxName then manxName = countryName end local output = {} -- Manx country name. -- Explicitly set the font and weight rather than inheriting -- the styling of the Infobox "above" field. table.insert( output, '<span style="font-family:inherit; font-weight:bold;">' .. manxName .. '</span>' ) -- Other official-language names. -- These must explicitly be normal weight. for _, item in ipairs(officialNames) do if item.lang ~= "gv" then local languageLabel = makeLanguageLabel(item.lang) local line = '<span style="font-weight:normal;">' .. item.text if languageLabel ~= "" then line = line .. " " .. languageLabel end line = line .. "</span>" table.insert(output, line) end end return table.concat(output, "<br>") end ------------------------------------------------------------ -- Images ------------------------------------------------------------ function p.images(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</td>' .. '<td style="width:42%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</td>' .. '</tr></table>', flag, arms, args.lheead_cowrey or "85px" ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</div>', flag ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</div>', arms, args.lheead_cowrey or "85px" ) end ------------------------------------------------------------ -- Captions ------------------------------------------------------------ function p.captions(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end local countryName = getCountryName(args) local genitiveName = getGenitiveName(args) local flagCaption = args["fo-heidyl_brattagh"] or "Brattagh" local armsCaption = args["sorçh_cowrey"] or "Armys" local armsArticle = args["art_sorçh_cowrey"] or "Armys" -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</td>' .. '<td style="width:42%%; text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</td>' .. '</tr></table>', genitiveName, flagCaption, armsArticle, genitiveName, armsCaption ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</div>', genitiveName, flagCaption ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</div>', armsArticle, genitiveName, armsCaption ) end return p mwndn7tzumzg9n3tsw0y3uf46wurkg5 392813 392812 2026-09-06T12:14:01Z MacTire02 219 coordnaidyn 392813 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override local function getArgs(frame) return frame:getParent().args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local value = mainsnak.datavalue.value if value and value ~= "" then return value end end end return nil end ------------------------------------------------------------ -- Wikidata item statement ------------------------------------------------------------ local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end ------------------------------------------------------------ -- Wikidata reference URL ------------------------------------------------------------ local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end ------------------------------------------------------------ -- Wikidata locator map ------------------------------------------------------------ local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Locator map data ------------------------------------------------------------ local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end ------------------------------------------------------------ -- Locator map ------------------------------------------------------------ function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end ------------------------------------------------------------ -- Capital / administrative centre data ------------------------------------------------------------ local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end -------------------------------------------------------- -- Manual capital -------------------------------------------------------- if capital then return { text = capital, entity = nil, reference = nil } end -------------------------------------------------------- -- Wikidata P36 = capital -------------------------------------------------------- local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Administrative centre data ------------------------------------------------------------ local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre } end return nil end ------------------------------------------------------------ -- Largest city / settlement data ------------------------------------------------------------ local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end -------------------------------------------------------- -- Manual largest city -------------------------------------------------------- if city then return { text = city, entity = nil, reference = nil } end -------------------------------------------------------- -- Wikidata P13574 = most populous urban area -------------------------------------------------------- local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Capital / administrative centre labels ------------------------------------------------------------ local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end ------------------------------------------------------------ -- City / settlement data ------------------------------------------------------------ local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end ------------------------------------------------------------ -- Normalise a city name for comparison ------------------------------------------------------------ local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) -------------------------------------------------------- -- Remove simple wikilink markup -------------------------------------------------------- value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") -------------------------------------------------------- -- If the link has a pipe, retain only the target -------------------------------------------------------- local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end ------------------------------------------------------------ -- Determine whether capital is the largest city ------------------------------------------------------------ local function capitalIsLargest(capital, largest) if not capital or not largest then return false end -------------------------------------------------------- -- Best method: compare Wikidata entity IDs -------------------------------------------------------- if capital.entity and largest.entity then if capital.entity.id and largest.entity.id and capital.entity.id == largest.entity.id then return true end end -------------------------------------------------------- -- Fallback: compare names -------------------------------------------------------- local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end ------------------------------------------------------------ -- Link city name to its article ------------------------------------------------------------ local function makeCityLink(city) if not city or not city.text then return "" end -------------------------------------------------------- -- If we have the Wikidata entity, use its Manx -- Wikipedia sitelink. -------------------------------------------------------- if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. city.text .. "]]" end end -------------------------------------------------------- -- Fallback: link to the displayed name itself. -------------------------------------------------------- return "[[" .. city.text .. "|" .. city.text .. "]]" end ------------------------------------------------------------ -- Coordinates ------------------------------------------------------------ local function makeCoordinates(entity) if not entity then return nil end -------------------------------------------------------- -- Wikidata P625 = coordinate location -------------------------------------------------------- local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline" } } end end end return nil end ------------------------------------------------------------ -- Capital / largest city / administrative centre ------------------------------------------------------------ function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} -------------------------------------------------------- -- Capital / administrative centre -------------------------------------------------------- if capital or administrative then local label local text ---------------------------------------------------- -- Capital ---------------------------------------------------- if capital then ------------------------------------------------ -- Link the label to Preeu-valley ------------------------------------------------ label = "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" ------------------------------------------------ -- Link the capital city ------------------------------------------------ text = makeCityLink(capital) ------------------------------------------------ -- Capital is also largest city ------------------------------------------------ if capitalIsLargest(capital, largest) then text = text .. '<br/><small>(as y balley smoo)</small>' end ------------------------------------------------ -- Coordinates directly underneath the city ------------------------------------------------ if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end ------------------------------------------------ -- Wikidata reference ------------------------------------------------ if capital.reference then text = text .. capital.reference end ---------------------------------------------------- -- Administrative centre only ---------------------------------------------------- else label = "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" text = makeCityLink(administrative) end table.insert( rows, "'''" .. label .. ":&nbsp;'''" .. text ) ---------------------------------------------------- -- Add largest city when different from capital ---------------------------------------------------- if largest and not capitalIsLargest(capital, largest) then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- No capital or administrative centre, -- but largest city exists -------------------------------------------------------- elseif largest then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- Nothing to display -------------------------------------------------------- if #rows == 0 then return nil end return mw.text.listToText( rows, "<br/>", "<br/>" ) end ------------------------------------------------------------ -- Wikidata audio file ------------------------------------------------------------ local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Anthems ------------------------------------------------------------ local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil -- P3831 = object of statement has role. -- This may identify the anthem as national, -- royal, regional, etc. if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { label = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end ------------------------------------------------------------ -- Classify anthems ------------------------------------------------------------ local function classifyAnthems(anthems) local national = {} local royal = {} local other = {} for _, anthem in ipairs(anthems) do local role = anthem.role if role then role = mw.ustring.lower(role) end if role and mw.ustring.find(role, "royal") then table.insert(royal, anthem) elseif role and ( mw.ustring.find(role, "national") or mw.ustring.find(role, "state anthem") ) then table.insert(national, anthem) else table.insert(other, anthem) end end -- If Wikidata has supplied an anthem but has not given -- it a role, treat the first such anthem as the national -- anthem. P85 is normally used for the country's official -- anthem. if #national == 0 and #other > 0 then table.insert(national, other[1]) table.remove(other, 1) end return national, royal, other end ------------------------------------------------------------ -- Anthem data ------------------------------------------------------------ local function getAnthemData(args) local anthems = getAnthems() local national, royal, other = classifyAnthems(anthems) local result = {} -------------------------------------------------------- -- National anthem -------------------------------------------------------- local manualNational = getManual(args, { "arrane_ashoonagh" }) if manualNational then if mw.ustring.lower(manualNational) ~= "none" then result.national = { text = '"' .. manualNational .. '"', reference = getManual(args, { "imraa_arrane_ashoonagh" }), audio = nil } end elseif #national > 0 then result.national = { text = national[1].label, reference = national[1].reference, audio = national[1].audio } end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- local manualRoyal = getManual(args, { "arrane_reeoil" }) if manualRoyal then if mw.ustring.lower(manualRoyal) ~= "none" then result.royal = { text = '"' .. manualRoyal .. '"', reference = getManual(args, { "imraa_arrane_reeoil" }), audio = nil } end elseif #royal > 0 then result.royal = { text = '"' .. royal[1].label .. '"', reference = royal[1].reference, audio = royal[1].audio } end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- local manualOther = getManual(args, { "arrane" }) if manualOther then if mw.ustring.lower(manualOther) ~= "none" then result.other = { text = '"' .. manualOther .. '"', reference = getManual(args, { "imraa_arrane" }), audio = nil } end elseif #other > 0 then result.other = { text = '"' .. other[1].label .. '"', reference = other[1].reference, audio = other[1].audio } end return result end ------------------------------------------------------------ -- Motto ------------------------------------------------------------ local function getMotto() local entity = mw.wikibase.getEntityObject() if not entity then return nil, nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil, nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return value.text, getWikidataReference(statement) end end end return nil, nil end ------------------------------------------------------------ -- Motto data ------------------------------------------------------------ local function getMottoData(args) local manual = getManual(args, { "jarroo-raa_ashoonagh", "jarroo-raa" }) if manual then if mw.ustring.lower(manual) == "none" then return nil end return { text = manual, reference = getManual(args, { "imraa_jarroo-raa" }) } end local text, reference = getMotto() if not text then return nil end return { text = text, reference = reference } end ------------------------------------------------------------ -- Motto and anthem output ------------------------------------------------------------ function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} -------------------------------------------------------- -- Motto -------------------------------------------------------- if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- National anthem -------------------------------------------------------- if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '""' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '""' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end ------------------------------------------------------------ -- Flag ------------------------------------------------------------ local function getFlag(args) -- Manual value takes precedence over Wikidata. local manual = getManual(args, { "jalloo_brattagh" }) if manual then if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P41 = flag image. return getWikidataImage("P41") end ------------------------------------------------------------ -- Coat of arms ------------------------------------------------------------ local function getArms(args) -- Manual value takes precedence over Wikidata. -- jalloo_armys is the preferred new parameter. -- jalloo_cleinney and jalloo_cowrey remain supported -- for compatibility with existing articles. local manual = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if manual then -- Explicitly suppress Wikidata. if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P94 = coat of arms image. return getWikidataImage("P94") end ------------------------------------------------------------ -- Country name ------------------------------------------------------------ local function getCountryName(args) return args.ennym_gienneydagh or args.kianglaghey_ennym or args.ennym or mw.title.getCurrentTitle().text end local function getGenitiveName(args) local name = getCountryName(args) return enmynCheerey.genitive(name) end ------------------------------------------------------------ -- Official name (Wikidata P1448) ------------------------------------------------------------ local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" and value.language and value.language ~= "" then table.insert(names, { text = value.text, lang = mw.ustring.lower(value.language) }) end end end return names end ------------------------------------------------------------ -- Language name ------------------------------------------------------------ local function getLanguageName(code) if not code or code == "" then return code end code = mw.ustring.lower(code) -- Manx Wikipedia language-name override. if langOverrideTable and langOverrideTable[code] then local name = langOverrideTable[code] if type(name) == "table" then return name[1] end return name end -- Standard language-name table. if langNameTable and langNameTable[code] then local name = langNameTable[code] if type(name) == "table" then return name[1] end return name end return code end ------------------------------------------------------------ -- Language label ------------------------------------------------------------ local function makeLanguageLabel(code) local languageName = getLanguageName(code) if not languageName or languageName == "" then return "" end -- The language name is deliberately NOT italicised. return mw.text.tag( "small", {}, "([[" .. languageName .. "|" .. languageName .. "]])" ) end ------------------------------------------------------------ -- Country title ------------------------------------------------------------ function p.title(frame) local args = getArgs(frame) local countryName = getCountryName(args) local officialNames = getOfficialNames() local manxName = nil local otherNames = {} -- Find the Manx official name first. for _, item in ipairs(officialNames) do if item.lang == "gv" then manxName = item.text break end end -- If Wikidata has no Manx P1448, use the short Manx country name. if not manxName then manxName = countryName end local output = {} -- Manx country name. -- Explicitly set the font and weight rather than inheriting -- the styling of the Infobox "above" field. table.insert( output, '<span style="font-family:inherit; font-weight:bold;">' .. manxName .. '</span>' ) -- Other official-language names. -- These must explicitly be normal weight. for _, item in ipairs(officialNames) do if item.lang ~= "gv" then local languageLabel = makeLanguageLabel(item.lang) local line = '<span style="font-weight:normal;">' .. item.text if languageLabel ~= "" then line = line .. " " .. languageLabel end line = line .. "</span>" table.insert(output, line) end end return table.concat(output, "<br>") end ------------------------------------------------------------ -- Images ------------------------------------------------------------ function p.images(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</td>' .. '<td style="width:42%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</td>' .. '</tr></table>', flag, arms, args.lheead_cowrey or "85px" ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</div>', flag ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</div>', arms, args.lheead_cowrey or "85px" ) end ------------------------------------------------------------ -- Captions ------------------------------------------------------------ function p.captions(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end local countryName = getCountryName(args) local genitiveName = getGenitiveName(args) local flagCaption = args["fo-heidyl_brattagh"] or "Brattagh" local armsCaption = args["sorçh_cowrey"] or "Armys" local armsArticle = args["art_sorçh_cowrey"] or "Armys" -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</td>' .. '<td style="width:42%%; text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</td>' .. '</tr></table>', genitiveName, flagCaption, armsArticle, genitiveName, armsCaption ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</div>', genitiveName, flagCaption ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</div>', armsArticle, genitiveName, armsCaption ) end return p hkh7631coxxx412p0suqaapx40nybze 392814 392813 2026-09-06T12:19:17Z MacTire02 219 soiaghey yn lipaid as y clowan {{coord}} 392814 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override local function getArgs(frame) return frame:getParent().args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local value = mainsnak.datavalue.value if value and value ~= "" then return value end end end return nil end ------------------------------------------------------------ -- Wikidata item statement ------------------------------------------------------------ local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end ------------------------------------------------------------ -- Wikidata reference URL ------------------------------------------------------------ local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end ------------------------------------------------------------ -- Wikidata locator map ------------------------------------------------------------ local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Locator map data ------------------------------------------------------------ local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end ------------------------------------------------------------ -- Locator map ------------------------------------------------------------ function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end ------------------------------------------------------------ -- Capital / administrative centre data ------------------------------------------------------------ local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end -------------------------------------------------------- -- Manual capital -------------------------------------------------------- if capital then return { text = capital, entity = nil, reference = nil } end -------------------------------------------------------- -- Wikidata P36 = capital -------------------------------------------------------- local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Administrative centre data ------------------------------------------------------------ local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre } end return nil end ------------------------------------------------------------ -- Largest city / settlement data ------------------------------------------------------------ local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end -------------------------------------------------------- -- Manual largest city -------------------------------------------------------- if city then return { text = city, entity = nil, reference = nil } end -------------------------------------------------------- -- Wikidata P13574 = most populous urban area -------------------------------------------------------- local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Capital / administrative centre labels ------------------------------------------------------------ local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end ------------------------------------------------------------ -- City / settlement data ------------------------------------------------------------ local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end ------------------------------------------------------------ -- Normalise a city name for comparison ------------------------------------------------------------ local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) -------------------------------------------------------- -- Remove simple wikilink markup -------------------------------------------------------- value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") -------------------------------------------------------- -- If the link has a pipe, retain only the target -------------------------------------------------------- local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end ------------------------------------------------------------ -- Determine whether capital is the largest city ------------------------------------------------------------ local function capitalIsLargest(capital, largest) if not capital or not largest then return false end -------------------------------------------------------- -- Best method: compare Wikidata entity IDs -------------------------------------------------------- if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end -------------------------------------------------------- -- Fallback: compare names -------------------------------------------------------- local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end ------------------------------------------------------------ -- Link city name to its article ------------------------------------------------------------ local function makeCityLink(city) if not city or not city.text then return "" end -------------------------------------------------------- -- If we have the Wikidata entity, use its Manx -- Wikipedia sitelink. -------------------------------------------------------- if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. city.text .. "]]" end end -------------------------------------------------------- -- Fallback: link to the displayed name itself. -------------------------------------------------------- return "[[" .. city.text .. "|" .. city.text .. "]]" end ------------------------------------------------------------ -- Coordinates ------------------------------------------------------------ local function makeCoordinates(entity) if not entity then return nil end -------------------------------------------------------- -- Wikidata P625 = coordinate location -------------------------------------------------------- local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline" } } end end end return nil end ------------------------------------------------------------ -- Capital / largest city / administrative centre ------------------------------------------------------------ function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} -------------------------------------------------------- -- Capital / administrative centre -------------------------------------------------------- if capital or administrative then local label local text ---------------------------------------------------- -- Capital ---------------------------------------------------- if capital then ------------------------------------------------ -- Link the label to Preeu-valley ------------------------------------------------ label = "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" ------------------------------------------------ -- Link the capital city ------------------------------------------------ text = makeCityLink(capital) ------------------------------------------------ -- Capital is also largest city ------------------------------------------------ if capitalIsLargest(capital, largest) then text = text .. '<br/><small>(as y balley smoo)</small>' end ------------------------------------------------ -- Coordinates directly underneath the city ------------------------------------------------ if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/>' .. coordinates end end ------------------------------------------------ -- Wikidata reference ------------------------------------------------ if capital.reference then text = text .. capital.reference end ---------------------------------------------------- -- Administrative centre only ---------------------------------------------------- else label = "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" text = makeCityLink(administrative) end table.insert( rows, "'''" .. label .. ":&nbsp;'''" .. text ) ---------------------------------------------------- -- Add largest city when different from capital ---------------------------------------------------- if largest and not capitalIsLargest(capital, largest) then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- No capital or administrative centre, -- but largest city exists -------------------------------------------------------- elseif largest then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- Nothing to display -------------------------------------------------------- if #rows == 0 then return nil end return mw.text.listToText( rows, "<br/>", "<br/>" ) end ------------------------------------------------------------ -- Wikidata audio file ------------------------------------------------------------ local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Anthems ------------------------------------------------------------ local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil -- P3831 = object of statement has role. -- This may identify the anthem as national, -- royal, regional, etc. if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { label = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end ------------------------------------------------------------ -- Classify anthems ------------------------------------------------------------ local function classifyAnthems(anthems) local national = {} local royal = {} local other = {} for _, anthem in ipairs(anthems) do local role = anthem.role if role then role = mw.ustring.lower(role) end if role and mw.ustring.find(role, "royal") then table.insert(royal, anthem) elseif role and ( mw.ustring.find(role, "national") or mw.ustring.find(role, "state anthem") ) then table.insert(national, anthem) else table.insert(other, anthem) end end -- If Wikidata has supplied an anthem but has not given -- it a role, treat the first such anthem as the national -- anthem. P85 is normally used for the country's official -- anthem. if #national == 0 and #other > 0 then table.insert(national, other[1]) table.remove(other, 1) end return national, royal, other end ------------------------------------------------------------ -- Anthem data ------------------------------------------------------------ local function getAnthemData(args) local anthems = getAnthems() local national, royal, other = classifyAnthems(anthems) local result = {} -------------------------------------------------------- -- National anthem -------------------------------------------------------- local manualNational = getManual(args, { "arrane_ashoonagh" }) if manualNational then if mw.ustring.lower(manualNational) ~= "none" then result.national = { text = '"' .. manualNational .. '"', reference = getManual(args, { "imraa_arrane_ashoonagh" }), audio = nil } end elseif #national > 0 then result.national = { text = national[1].label, reference = national[1].reference, audio = national[1].audio } end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- local manualRoyal = getManual(args, { "arrane_reeoil" }) if manualRoyal then if mw.ustring.lower(manualRoyal) ~= "none" then result.royal = { text = '"' .. manualRoyal .. '"', reference = getManual(args, { "imraa_arrane_reeoil" }), audio = nil } end elseif #royal > 0 then result.royal = { text = '"' .. royal[1].label .. '"', reference = royal[1].reference, audio = royal[1].audio } end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- local manualOther = getManual(args, { "arrane" }) if manualOther then if mw.ustring.lower(manualOther) ~= "none" then result.other = { text = '"' .. manualOther .. '"', reference = getManual(args, { "imraa_arrane" }), audio = nil } end elseif #other > 0 then result.other = { text = '"' .. other[1].label .. '"', reference = other[1].reference, audio = other[1].audio } end return result end ------------------------------------------------------------ -- Motto ------------------------------------------------------------ local function getMotto() local entity = mw.wikibase.getEntityObject() if not entity then return nil, nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil, nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return value.text, getWikidataReference(statement) end end end return nil, nil end ------------------------------------------------------------ -- Motto data ------------------------------------------------------------ local function getMottoData(args) local manual = getManual(args, { "jarroo-raa_ashoonagh", "jarroo-raa" }) if manual then if mw.ustring.lower(manual) == "none" then return nil end return { text = manual, reference = getManual(args, { "imraa_jarroo-raa" }) } end local text, reference = getMotto() if not text then return nil end return { text = text, reference = reference } end ------------------------------------------------------------ -- Motto and anthem output ------------------------------------------------------------ function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} -------------------------------------------------------- -- Motto -------------------------------------------------------- if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- National anthem -------------------------------------------------------- if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '""' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '""' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end ------------------------------------------------------------ -- Flag ------------------------------------------------------------ local function getFlag(args) -- Manual value takes precedence over Wikidata. local manual = getManual(args, { "jalloo_brattagh" }) if manual then if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P41 = flag image. return getWikidataImage("P41") end ------------------------------------------------------------ -- Coat of arms ------------------------------------------------------------ local function getArms(args) -- Manual value takes precedence over Wikidata. -- jalloo_armys is the preferred new parameter. -- jalloo_cleinney and jalloo_cowrey remain supported -- for compatibility with existing articles. local manual = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if manual then -- Explicitly suppress Wikidata. if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P94 = coat of arms image. return getWikidataImage("P94") end ------------------------------------------------------------ -- Country name ------------------------------------------------------------ local function getCountryName(args) return args.ennym_gienneydagh or args.kianglaghey_ennym or args.ennym or mw.title.getCurrentTitle().text end local function getGenitiveName(args) local name = getCountryName(args) return enmynCheerey.genitive(name) end ------------------------------------------------------------ -- Official name (Wikidata P1448) ------------------------------------------------------------ local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" and value.language and value.language ~= "" then table.insert(names, { text = value.text, lang = mw.ustring.lower(value.language) }) end end end return names end ------------------------------------------------------------ -- Language name ------------------------------------------------------------ local function getLanguageName(code) if not code or code == "" then return code end code = mw.ustring.lower(code) -- Manx Wikipedia language-name override. if langOverrideTable and langOverrideTable[code] then local name = langOverrideTable[code] if type(name) == "table" then return name[1] end return name end -- Standard language-name table. if langNameTable and langNameTable[code] then local name = langNameTable[code] if type(name) == "table" then return name[1] end return name end return code end ------------------------------------------------------------ -- Language label ------------------------------------------------------------ local function makeLanguageLabel(code) local languageName = getLanguageName(code) if not languageName or languageName == "" then return "" end -- The language name is deliberately NOT italicised. return mw.text.tag( "small", {}, "([[" .. languageName .. "|" .. languageName .. "]])" ) end ------------------------------------------------------------ -- Country title ------------------------------------------------------------ function p.title(frame) local args = getArgs(frame) local countryName = getCountryName(args) local officialNames = getOfficialNames() local manxName = nil local otherNames = {} -- Find the Manx official name first. for _, item in ipairs(officialNames) do if item.lang == "gv" then manxName = item.text break end end -- If Wikidata has no Manx P1448, use the short Manx country name. if not manxName then manxName = countryName end local output = {} -- Manx country name. -- Explicitly set the font and weight rather than inheriting -- the styling of the Infobox "above" field. table.insert( output, '<span style="font-family:inherit; font-weight:bold;">' .. manxName .. '</span>' ) -- Other official-language names. -- These must explicitly be normal weight. for _, item in ipairs(officialNames) do if item.lang ~= "gv" then local languageLabel = makeLanguageLabel(item.lang) local line = '<span style="font-weight:normal;">' .. item.text if languageLabel ~= "" then line = line .. " " .. languageLabel end line = line .. "</span>" table.insert(output, line) end end return table.concat(output, "<br>") end ------------------------------------------------------------ -- Images ------------------------------------------------------------ function p.images(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</td>' .. '<td style="width:42%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</td>' .. '</tr></table>', flag, arms, args.lheead_cowrey or "85px" ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</div>', flag ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</div>', arms, args.lheead_cowrey or "85px" ) end ------------------------------------------------------------ -- Captions ------------------------------------------------------------ function p.captions(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end local countryName = getCountryName(args) local genitiveName = getGenitiveName(args) local flagCaption = args["fo-heidyl_brattagh"] or "Brattagh" local armsCaption = args["sorçh_cowrey"] or "Armys" local armsArticle = args["art_sorçh_cowrey"] or "Armys" -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</td>' .. '<td style="width:42%%; text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</td>' .. '</tr></table>', genitiveName, flagCaption, armsArticle, genitiveName, armsCaption ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</div>', genitiveName, flagCaption ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</div>', armsArticle, genitiveName, armsCaption ) end return p 55rc0vrbc33w8dtt7jy8mkpmhwedctu 392816 392814 2026-09-06T12:26:19Z MacTire02 219 ++ 392816 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override local function getArgs(frame) return frame:getParent().args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local value = mainsnak.datavalue.value if value and value ~= "" then return value end end end return nil end ------------------------------------------------------------ -- Wikidata item statement ------------------------------------------------------------ local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end ------------------------------------------------------------ -- Wikidata reference URL ------------------------------------------------------------ local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end ------------------------------------------------------------ -- Wikidata locator map ------------------------------------------------------------ local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Locator map data ------------------------------------------------------------ local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end ------------------------------------------------------------ -- Locator map ------------------------------------------------------------ function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end ------------------------------------------------------------ -- Capital / administrative centre data ------------------------------------------------------------ local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end -------------------------------------------------------- -- Manual capital -------------------------------------------------------- if capital then return { text = capital, entity = nil, reference = nil } end -------------------------------------------------------- -- Wikidata P36 = capital -------------------------------------------------------- local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Administrative centre data ------------------------------------------------------------ local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre } end return nil end ------------------------------------------------------------ -- Largest city / settlement data ------------------------------------------------------------ local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end -------------------------------------------------------- -- Manual largest city -------------------------------------------------------- if city then return { text = city, entity = nil, reference = nil } end -------------------------------------------------------- -- Wikidata P13574 = most populous urban area -------------------------------------------------------- local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Capital / administrative centre labels ------------------------------------------------------------ local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end ------------------------------------------------------------ -- City / settlement data ------------------------------------------------------------ local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end ------------------------------------------------------------ -- Normalise a city name for comparison ------------------------------------------------------------ local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) -------------------------------------------------------- -- Remove simple wikilink markup -------------------------------------------------------- value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") -------------------------------------------------------- -- If the link has a pipe, retain only the target -------------------------------------------------------- local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end ------------------------------------------------------------ -- Determine whether capital is the largest city ------------------------------------------------------------ local function capitalIsLargest(capital, largest) if not capital or not largest then return false end -------------------------------------------------------- -- Best method: compare Wikidata entity IDs -------------------------------------------------------- if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end -------------------------------------------------------- -- Fallback: compare names -------------------------------------------------------- local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end ------------------------------------------------------------ -- Link city name to its article ------------------------------------------------------------ local function makeCityLink(city) if not city or not city.text then return "" end -------------------------------------------------------- -- If we have the Wikidata entity, use its Manx -- Wikipedia sitelink. -------------------------------------------------------- if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. city.text .. "]]" end end -------------------------------------------------------- -- Fallback: link to the displayed name itself. -------------------------------------------------------- return "[[" .. city.text .. "|" .. city.text .. "]]" end ------------------------------------------------------------ -- Coordinates ------------------------------------------------------------ local function makeCoordinates(entity) if not entity then return nil end -------------------------------------------------------- -- Wikidata P625 = coordinate location -------------------------------------------------------- local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline" } } end end end return nil end ------------------------------------------------------------ -- Capital / largest city / administrative centre ------------------------------------------------------------ function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local labels = cityData.labels if cityData.capital then return "'''[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]:&nbsp;'''" end if cityData.administrative then return "'''[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]:&nbsp;'''" end if cityData.largest then return "'''Balley smoo:&nbsp;'''" end return nil end function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capitalIsLargest(capital, largest) then text = text .. '<br/><small>(as y balley smoo)</small>' end if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then return makeCityLink(administrative) elseif largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end return text end return nil end function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} -------------------------------------------------------- -- Capital / administrative centre -------------------------------------------------------- if capital or administrative then local label local text ---------------------------------------------------- -- Capital ---------------------------------------------------- if capital then ------------------------------------------------ -- Link the label to Preeu-valley ------------------------------------------------ label = "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" ------------------------------------------------ -- Link the capital city ------------------------------------------------ text = makeCityLink(capital) ------------------------------------------------ -- Capital is also largest city ------------------------------------------------ if capitalIsLargest(capital, largest) then text = text .. '<br/><small>(as y balley smoo)</small>' end ------------------------------------------------ -- Coordinates directly underneath the city ------------------------------------------------ if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/>' .. coordinates end end ------------------------------------------------ -- Wikidata reference ------------------------------------------------ if capital.reference then text = text .. capital.reference end ---------------------------------------------------- -- Administrative centre only ---------------------------------------------------- else label = "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" text = makeCityLink(administrative) end table.insert( rows, "'''" .. label .. ":&nbsp;'''" .. text ) ---------------------------------------------------- -- Add largest city when different from capital ---------------------------------------------------- if largest and not capitalIsLargest(capital, largest) then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- No capital or administrative centre, -- but largest city exists -------------------------------------------------------- elseif largest then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- Nothing to display -------------------------------------------------------- if #rows == 0 then return nil end return mw.text.listToText( rows, "<br/>", "<br/>" ) end ------------------------------------------------------------ -- Wikidata audio file ------------------------------------------------------------ local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Anthems ------------------------------------------------------------ local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil -- P3831 = object of statement has role. -- This may identify the anthem as national, -- royal, regional, etc. if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { label = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end ------------------------------------------------------------ -- Classify anthems ------------------------------------------------------------ local function classifyAnthems(anthems) local national = {} local royal = {} local other = {} for _, anthem in ipairs(anthems) do local role = anthem.role if role then role = mw.ustring.lower(role) end if role and mw.ustring.find(role, "royal") then table.insert(royal, anthem) elseif role and ( mw.ustring.find(role, "national") or mw.ustring.find(role, "state anthem") ) then table.insert(national, anthem) else table.insert(other, anthem) end end -- If Wikidata has supplied an anthem but has not given -- it a role, treat the first such anthem as the national -- anthem. P85 is normally used for the country's official -- anthem. if #national == 0 and #other > 0 then table.insert(national, other[1]) table.remove(other, 1) end return national, royal, other end ------------------------------------------------------------ -- Anthem data ------------------------------------------------------------ local function getAnthemData(args) local anthems = getAnthems() local national, royal, other = classifyAnthems(anthems) local result = {} -------------------------------------------------------- -- National anthem -------------------------------------------------------- local manualNational = getManual(args, { "arrane_ashoonagh" }) if manualNational then if mw.ustring.lower(manualNational) ~= "none" then result.national = { text = '"' .. manualNational .. '"', reference = getManual(args, { "imraa_arrane_ashoonagh" }), audio = nil } end elseif #national > 0 then result.national = { text = national[1].label, reference = national[1].reference, audio = national[1].audio } end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- local manualRoyal = getManual(args, { "arrane_reeoil" }) if manualRoyal then if mw.ustring.lower(manualRoyal) ~= "none" then result.royal = { text = '"' .. manualRoyal .. '"', reference = getManual(args, { "imraa_arrane_reeoil" }), audio = nil } end elseif #royal > 0 then result.royal = { text = '"' .. royal[1].label .. '"', reference = royal[1].reference, audio = royal[1].audio } end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- local manualOther = getManual(args, { "arrane" }) if manualOther then if mw.ustring.lower(manualOther) ~= "none" then result.other = { text = '"' .. manualOther .. '"', reference = getManual(args, { "imraa_arrane" }), audio = nil } end elseif #other > 0 then result.other = { text = '"' .. other[1].label .. '"', reference = other[1].reference, audio = other[1].audio } end return result end ------------------------------------------------------------ -- Motto ------------------------------------------------------------ local function getMotto() local entity = mw.wikibase.getEntityObject() if not entity then return nil, nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil, nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return value.text, getWikidataReference(statement) end end end return nil, nil end ------------------------------------------------------------ -- Motto data ------------------------------------------------------------ local function getMottoData(args) local manual = getManual(args, { "jarroo-raa_ashoonagh", "jarroo-raa" }) if manual then if mw.ustring.lower(manual) == "none" then return nil end return { text = manual, reference = getManual(args, { "imraa_jarroo-raa" }) } end local text, reference = getMotto() if not text then return nil end return { text = text, reference = reference } end ------------------------------------------------------------ -- Motto and anthem output ------------------------------------------------------------ function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} -------------------------------------------------------- -- Motto -------------------------------------------------------- if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- National anthem -------------------------------------------------------- if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '""' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '""' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end ------------------------------------------------------------ -- Flag ------------------------------------------------------------ local function getFlag(args) -- Manual value takes precedence over Wikidata. local manual = getManual(args, { "jalloo_brattagh" }) if manual then if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P41 = flag image. return getWikidataImage("P41") end ------------------------------------------------------------ -- Coat of arms ------------------------------------------------------------ local function getArms(args) -- Manual value takes precedence over Wikidata. -- jalloo_armys is the preferred new parameter. -- jalloo_cleinney and jalloo_cowrey remain supported -- for compatibility with existing articles. local manual = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if manual then -- Explicitly suppress Wikidata. if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P94 = coat of arms image. return getWikidataImage("P94") end ------------------------------------------------------------ -- Country name ------------------------------------------------------------ local function getCountryName(args) return args.ennym_gienneydagh or args.kianglaghey_ennym or args.ennym or mw.title.getCurrentTitle().text end local function getGenitiveName(args) local name = getCountryName(args) return enmynCheerey.genitive(name) end ------------------------------------------------------------ -- Official name (Wikidata P1448) ------------------------------------------------------------ local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" and value.language and value.language ~= "" then table.insert(names, { text = value.text, lang = mw.ustring.lower(value.language) }) end end end return names end ------------------------------------------------------------ -- Language name ------------------------------------------------------------ local function getLanguageName(code) if not code or code == "" then return code end code = mw.ustring.lower(code) -- Manx Wikipedia language-name override. if langOverrideTable and langOverrideTable[code] then local name = langOverrideTable[code] if type(name) == "table" then return name[1] end return name end -- Standard language-name table. if langNameTable and langNameTable[code] then local name = langNameTable[code] if type(name) == "table" then return name[1] end return name end return code end ------------------------------------------------------------ -- Language label ------------------------------------------------------------ local function makeLanguageLabel(code) local languageName = getLanguageName(code) if not languageName or languageName == "" then return "" end -- The language name is deliberately NOT italicised. return mw.text.tag( "small", {}, "([[" .. languageName .. "|" .. languageName .. "]])" ) end ------------------------------------------------------------ -- Country title ------------------------------------------------------------ function p.title(frame) local args = getArgs(frame) local countryName = getCountryName(args) local officialNames = getOfficialNames() local manxName = nil local otherNames = {} -- Find the Manx official name first. for _, item in ipairs(officialNames) do if item.lang == "gv" then manxName = item.text break end end -- If Wikidata has no Manx P1448, use the short Manx country name. if not manxName then manxName = countryName end local output = {} -- Manx country name. -- Explicitly set the font and weight rather than inheriting -- the styling of the Infobox "above" field. table.insert( output, '<span style="font-family:inherit; font-weight:bold;">' .. manxName .. '</span>' ) -- Other official-language names. -- These must explicitly be normal weight. for _, item in ipairs(officialNames) do if item.lang ~= "gv" then local languageLabel = makeLanguageLabel(item.lang) local line = '<span style="font-weight:normal;">' .. item.text if languageLabel ~= "" then line = line .. " " .. languageLabel end line = line .. "</span>" table.insert(output, line) end end return table.concat(output, "<br>") end ------------------------------------------------------------ -- Images ------------------------------------------------------------ function p.images(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</td>' .. '<td style="width:42%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</td>' .. '</tr></table>', flag, arms, args.lheead_cowrey or "85px" ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</div>', flag ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</div>', arms, args.lheead_cowrey or "85px" ) end ------------------------------------------------------------ -- Captions ------------------------------------------------------------ function p.captions(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end local countryName = getCountryName(args) local genitiveName = getGenitiveName(args) local flagCaption = args["fo-heidyl_brattagh"] or "Brattagh" local armsCaption = args["sorçh_cowrey"] or "Armys" local armsArticle = args["art_sorçh_cowrey"] or "Armys" -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</td>' .. '<td style="width:42%%; text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</td>' .. '</tr></table>', genitiveName, flagCaption, armsArticle, genitiveName, armsCaption ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</div>', genitiveName, flagCaption ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</div>', armsArticle, genitiveName, armsCaption ) end return p rdl2btyy2ufcq43osbo6yhqg32bnzxv 392817 392816 2026-09-06T12:28:57Z MacTire02 219 jeihoilanyn -> dms 392817 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override local function getArgs(frame) return frame:getParent().args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local value = mainsnak.datavalue.value if value and value ~= "" then return value end end end return nil end ------------------------------------------------------------ -- Wikidata item statement ------------------------------------------------------------ local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end ------------------------------------------------------------ -- Wikidata reference URL ------------------------------------------------------------ local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end ------------------------------------------------------------ -- Wikidata locator map ------------------------------------------------------------ local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Locator map data ------------------------------------------------------------ local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end ------------------------------------------------------------ -- Locator map ------------------------------------------------------------ function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end ------------------------------------------------------------ -- Capital / administrative centre data ------------------------------------------------------------ local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end -------------------------------------------------------- -- Manual capital -------------------------------------------------------- if capital then return { text = capital, entity = nil, reference = nil } end -------------------------------------------------------- -- Wikidata P36 = capital -------------------------------------------------------- local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Administrative centre data ------------------------------------------------------------ local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre } end return nil end ------------------------------------------------------------ -- Largest city / settlement data ------------------------------------------------------------ local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end -------------------------------------------------------- -- Manual largest city -------------------------------------------------------- if city then return { text = city, entity = nil, reference = nil } end -------------------------------------------------------- -- Wikidata P13574 = most populous urban area -------------------------------------------------------- local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Capital / administrative centre labels ------------------------------------------------------------ local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end ------------------------------------------------------------ -- City / settlement data ------------------------------------------------------------ local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end ------------------------------------------------------------ -- Normalise a city name for comparison ------------------------------------------------------------ local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) -------------------------------------------------------- -- Remove simple wikilink markup -------------------------------------------------------- value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") -------------------------------------------------------- -- If the link has a pipe, retain only the target -------------------------------------------------------- local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end ------------------------------------------------------------ -- Determine whether capital is the largest city ------------------------------------------------------------ local function capitalIsLargest(capital, largest) if not capital or not largest then return false end -------------------------------------------------------- -- Best method: compare Wikidata entity IDs -------------------------------------------------------- if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end -------------------------------------------------------- -- Fallback: compare names -------------------------------------------------------- local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end ------------------------------------------------------------ -- Link city name to its article ------------------------------------------------------------ local function makeCityLink(city) if not city or not city.text then return "" end -------------------------------------------------------- -- If we have the Wikidata entity, use its Manx -- Wikipedia sitelink. -------------------------------------------------------- if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. city.text .. "]]" end end -------------------------------------------------------- -- Fallback: link to the displayed name itself. -------------------------------------------------------- return "[[" .. city.text .. "|" .. city.text .. "]]" end ------------------------------------------------------------ -- Coordinates ------------------------------------------------------------ local function makeCoordinates(entity) if not entity then return nil end -------------------------------------------------------- -- Wikidata P625 = coordinate location -------------------------------------------------------- local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end ------------------------------------------------------------ -- Capital / largest city / administrative centre ------------------------------------------------------------ function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local labels = cityData.labels if cityData.capital then return "'''[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]:&nbsp;'''" end if cityData.administrative then return "'''[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]:&nbsp;'''" end if cityData.largest then return "'''Balley smoo:&nbsp;'''" end return nil end function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capitalIsLargest(capital, largest) then text = text .. '<br/><small>(as y balley smoo)</small>' end if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then return makeCityLink(administrative) elseif largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end return text end return nil end function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} -------------------------------------------------------- -- Capital / administrative centre -------------------------------------------------------- if capital or administrative then local label local text ---------------------------------------------------- -- Capital ---------------------------------------------------- if capital then ------------------------------------------------ -- Link the label to Preeu-valley ------------------------------------------------ label = "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" ------------------------------------------------ -- Link the capital city ------------------------------------------------ text = makeCityLink(capital) ------------------------------------------------ -- Capital is also largest city ------------------------------------------------ if capitalIsLargest(capital, largest) then text = text .. '<br/><small>(as y balley smoo)</small>' end ------------------------------------------------ -- Coordinates directly underneath the city ------------------------------------------------ if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/>' .. coordinates end end ------------------------------------------------ -- Wikidata reference ------------------------------------------------ if capital.reference then text = text .. capital.reference end ---------------------------------------------------- -- Administrative centre only ---------------------------------------------------- else label = "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" text = makeCityLink(administrative) end table.insert( rows, "'''" .. label .. ":&nbsp;'''" .. text ) ---------------------------------------------------- -- Add largest city when different from capital ---------------------------------------------------- if largest and not capitalIsLargest(capital, largest) then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- No capital or administrative centre, -- but largest city exists -------------------------------------------------------- elseif largest then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- Nothing to display -------------------------------------------------------- if #rows == 0 then return nil end return mw.text.listToText( rows, "<br/>", "<br/>" ) end ------------------------------------------------------------ -- Wikidata audio file ------------------------------------------------------------ local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Anthems ------------------------------------------------------------ local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil -- P3831 = object of statement has role. -- This may identify the anthem as national, -- royal, regional, etc. if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { label = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end ------------------------------------------------------------ -- Classify anthems ------------------------------------------------------------ local function classifyAnthems(anthems) local national = {} local royal = {} local other = {} for _, anthem in ipairs(anthems) do local role = anthem.role if role then role = mw.ustring.lower(role) end if role and mw.ustring.find(role, "royal") then table.insert(royal, anthem) elseif role and ( mw.ustring.find(role, "national") or mw.ustring.find(role, "state anthem") ) then table.insert(national, anthem) else table.insert(other, anthem) end end -- If Wikidata has supplied an anthem but has not given -- it a role, treat the first such anthem as the national -- anthem. P85 is normally used for the country's official -- anthem. if #national == 0 and #other > 0 then table.insert(national, other[1]) table.remove(other, 1) end return national, royal, other end ------------------------------------------------------------ -- Anthem data ------------------------------------------------------------ local function getAnthemData(args) local anthems = getAnthems() local national, royal, other = classifyAnthems(anthems) local result = {} -------------------------------------------------------- -- National anthem -------------------------------------------------------- local manualNational = getManual(args, { "arrane_ashoonagh" }) if manualNational then if mw.ustring.lower(manualNational) ~= "none" then result.national = { text = '"' .. manualNational .. '"', reference = getManual(args, { "imraa_arrane_ashoonagh" }), audio = nil } end elseif #national > 0 then result.national = { text = national[1].label, reference = national[1].reference, audio = national[1].audio } end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- local manualRoyal = getManual(args, { "arrane_reeoil" }) if manualRoyal then if mw.ustring.lower(manualRoyal) ~= "none" then result.royal = { text = '"' .. manualRoyal .. '"', reference = getManual(args, { "imraa_arrane_reeoil" }), audio = nil } end elseif #royal > 0 then result.royal = { text = '"' .. royal[1].label .. '"', reference = royal[1].reference, audio = royal[1].audio } end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- local manualOther = getManual(args, { "arrane" }) if manualOther then if mw.ustring.lower(manualOther) ~= "none" then result.other = { text = '"' .. manualOther .. '"', reference = getManual(args, { "imraa_arrane" }), audio = nil } end elseif #other > 0 then result.other = { text = '"' .. other[1].label .. '"', reference = other[1].reference, audio = other[1].audio } end return result end ------------------------------------------------------------ -- Motto ------------------------------------------------------------ local function getMotto() local entity = mw.wikibase.getEntityObject() if not entity then return nil, nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil, nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return value.text, getWikidataReference(statement) end end end return nil, nil end ------------------------------------------------------------ -- Motto data ------------------------------------------------------------ local function getMottoData(args) local manual = getManual(args, { "jarroo-raa_ashoonagh", "jarroo-raa" }) if manual then if mw.ustring.lower(manual) == "none" then return nil end return { text = manual, reference = getManual(args, { "imraa_jarroo-raa" }) } end local text, reference = getMotto() if not text then return nil end return { text = text, reference = reference } end ------------------------------------------------------------ -- Motto and anthem output ------------------------------------------------------------ function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} -------------------------------------------------------- -- Motto -------------------------------------------------------- if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- National anthem -------------------------------------------------------- if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '""' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '""' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end ------------------------------------------------------------ -- Flag ------------------------------------------------------------ local function getFlag(args) -- Manual value takes precedence over Wikidata. local manual = getManual(args, { "jalloo_brattagh" }) if manual then if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P41 = flag image. return getWikidataImage("P41") end ------------------------------------------------------------ -- Coat of arms ------------------------------------------------------------ local function getArms(args) -- Manual value takes precedence over Wikidata. -- jalloo_armys is the preferred new parameter. -- jalloo_cleinney and jalloo_cowrey remain supported -- for compatibility with existing articles. local manual = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if manual then -- Explicitly suppress Wikidata. if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P94 = coat of arms image. return getWikidataImage("P94") end ------------------------------------------------------------ -- Country name ------------------------------------------------------------ local function getCountryName(args) return args.ennym_gienneydagh or args.kianglaghey_ennym or args.ennym or mw.title.getCurrentTitle().text end local function getGenitiveName(args) local name = getCountryName(args) return enmynCheerey.genitive(name) end ------------------------------------------------------------ -- Official name (Wikidata P1448) ------------------------------------------------------------ local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" and value.language and value.language ~= "" then table.insert(names, { text = value.text, lang = mw.ustring.lower(value.language) }) end end end return names end ------------------------------------------------------------ -- Language name ------------------------------------------------------------ local function getLanguageName(code) if not code or code == "" then return code end code = mw.ustring.lower(code) -- Manx Wikipedia language-name override. if langOverrideTable and langOverrideTable[code] then local name = langOverrideTable[code] if type(name) == "table" then return name[1] end return name end -- Standard language-name table. if langNameTable and langNameTable[code] then local name = langNameTable[code] if type(name) == "table" then return name[1] end return name end return code end ------------------------------------------------------------ -- Language label ------------------------------------------------------------ local function makeLanguageLabel(code) local languageName = getLanguageName(code) if not languageName or languageName == "" then return "" end -- The language name is deliberately NOT italicised. return mw.text.tag( "small", {}, "([[" .. languageName .. "|" .. languageName .. "]])" ) end ------------------------------------------------------------ -- Country title ------------------------------------------------------------ function p.title(frame) local args = getArgs(frame) local countryName = getCountryName(args) local officialNames = getOfficialNames() local manxName = nil local otherNames = {} -- Find the Manx official name first. for _, item in ipairs(officialNames) do if item.lang == "gv" then manxName = item.text break end end -- If Wikidata has no Manx P1448, use the short Manx country name. if not manxName then manxName = countryName end local output = {} -- Manx country name. -- Explicitly set the font and weight rather than inheriting -- the styling of the Infobox "above" field. table.insert( output, '<span style="font-family:inherit; font-weight:bold;">' .. manxName .. '</span>' ) -- Other official-language names. -- These must explicitly be normal weight. for _, item in ipairs(officialNames) do if item.lang ~= "gv" then local languageLabel = makeLanguageLabel(item.lang) local line = '<span style="font-weight:normal;">' .. item.text if languageLabel ~= "" then line = line .. " " .. languageLabel end line = line .. "</span>" table.insert(output, line) end end return table.concat(output, "<br>") end ------------------------------------------------------------ -- Images ------------------------------------------------------------ function p.images(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</td>' .. '<td style="width:42%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</td>' .. '</tr></table>', flag, arms, args.lheead_cowrey or "85px" ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</div>', flag ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</div>', arms, args.lheead_cowrey or "85px" ) end ------------------------------------------------------------ -- Captions ------------------------------------------------------------ function p.captions(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end local countryName = getCountryName(args) local genitiveName = getGenitiveName(args) local flagCaption = args["fo-heidyl_brattagh"] or "Brattagh" local armsCaption = args["sorçh_cowrey"] or "Armys" local armsArticle = args["art_sorçh_cowrey"] or "Armys" -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</td>' .. '<td style="width:42%%; text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</td>' .. '</tr></table>', genitiveName, flagCaption, armsArticle, genitiveName, armsCaption ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</div>', genitiveName, flagCaption ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</div>', armsArticle, genitiveName, armsCaption ) end return p 31jgwuyzv1dd6bnj86kbwl89mgsuuv1 392818 392817 2026-09-06T12:32:07Z MacTire02 219 ++ 392818 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override local function getArgs(frame) return frame:getParent().args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local value = mainsnak.datavalue.value if value and value ~= "" then return value end end end return nil end ------------------------------------------------------------ -- Wikidata item statement ------------------------------------------------------------ local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end ------------------------------------------------------------ -- Wikidata reference URL ------------------------------------------------------------ local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end ------------------------------------------------------------ -- Wikidata locator map ------------------------------------------------------------ local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Locator map data ------------------------------------------------------------ local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end ------------------------------------------------------------ -- Locator map ------------------------------------------------------------ function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end ------------------------------------------------------------ -- Capital / administrative centre data ------------------------------------------------------------ local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end -------------------------------------------------------- -- Manual capital -------------------------------------------------------- if capital then return { text = capital, entity = nil, reference = nil } end -------------------------------------------------------- -- Wikidata P36 = capital -------------------------------------------------------- local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Administrative centre data ------------------------------------------------------------ local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre } end return nil end ------------------------------------------------------------ -- Largest city / settlement data ------------------------------------------------------------ local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end -------------------------------------------------------- -- Manual largest city -------------------------------------------------------- if city then return { text = city, entity = nil, reference = nil } end -------------------------------------------------------- -- Wikidata P13574 = most populous urban area -------------------------------------------------------- local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Capital / administrative centre labels ------------------------------------------------------------ local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end ------------------------------------------------------------ -- City / settlement data ------------------------------------------------------------ local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end ------------------------------------------------------------ -- Normalise a city name for comparison ------------------------------------------------------------ local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) -------------------------------------------------------- -- Remove simple wikilink markup -------------------------------------------------------- value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") -------------------------------------------------------- -- If the link has a pipe, retain only the target -------------------------------------------------------- local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end ------------------------------------------------------------ -- Determine whether capital is the largest city ------------------------------------------------------------ local function capitalIsLargest(capital, largest) if not capital or not largest then return false end -------------------------------------------------------- -- Best method: compare Wikidata entity IDs -------------------------------------------------------- if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end -------------------------------------------------------- -- Fallback: compare names -------------------------------------------------------- local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end ------------------------------------------------------------ -- Link city name to its article ------------------------------------------------------------ local function makeCityLink(city) if not city or not city.text then return "" end -------------------------------------------------------- -- If we have the Wikidata entity, use its Manx -- Wikipedia sitelink. -------------------------------------------------------- if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. city.text .. "]]" end end -------------------------------------------------------- -- Fallback: link to the displayed name itself. -------------------------------------------------------- return "[[" .. city.text .. "|" .. city.text .. "]]" end ------------------------------------------------------------ -- Coordinates ------------------------------------------------------------ local function makeCoordinates(entity) if not entity then return nil end -------------------------------------------------------- -- Wikidata P625 = coordinate location -------------------------------------------------------- local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end ------------------------------------------------------------ -- Capital / largest city / administrative centre ------------------------------------------------------------ function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local labels = cityData.labels if cityData.capital then return "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]:" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]:" end if cityData.largest then return "Balley smoo:" end return nil end function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capitalIsLargest(capital, largest) then text = text .. '<br/><small>(as y balley smoo)</small>' end if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then return makeCityLink(administrative) elseif largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end return text end return nil end function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} -------------------------------------------------------- -- Capital / administrative centre -------------------------------------------------------- if capital or administrative then local label local text ---------------------------------------------------- -- Capital ---------------------------------------------------- if capital then ------------------------------------------------ -- Link the label to Preeu-valley ------------------------------------------------ label = "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" ------------------------------------------------ -- Link the capital city ------------------------------------------------ text = makeCityLink(capital) ------------------------------------------------ -- Capital is also largest city ------------------------------------------------ if capitalIsLargest(capital, largest) then text = text .. '<br/><small>(as y balley smoo)</small>' end ------------------------------------------------ -- Coordinates directly underneath the city ------------------------------------------------ if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/>' .. coordinates end end ------------------------------------------------ -- Wikidata reference ------------------------------------------------ if capital.reference then text = text .. capital.reference end ---------------------------------------------------- -- Administrative centre only ---------------------------------------------------- else label = "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" text = makeCityLink(administrative) end table.insert( rows, "'''" .. label .. ":&nbsp;'''" .. text ) ---------------------------------------------------- -- Add largest city when different from capital ---------------------------------------------------- if largest and not capitalIsLargest(capital, largest) then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- No capital or administrative centre, -- but largest city exists -------------------------------------------------------- elseif largest then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- Nothing to display -------------------------------------------------------- if #rows == 0 then return nil end return mw.text.listToText( rows, "<br/>", "<br/>" ) end ------------------------------------------------------------ -- Wikidata audio file ------------------------------------------------------------ local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Anthems ------------------------------------------------------------ local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil -- P3831 = object of statement has role. -- This may identify the anthem as national, -- royal, regional, etc. if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { label = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end ------------------------------------------------------------ -- Classify anthems ------------------------------------------------------------ local function classifyAnthems(anthems) local national = {} local royal = {} local other = {} for _, anthem in ipairs(anthems) do local role = anthem.role if role then role = mw.ustring.lower(role) end if role and mw.ustring.find(role, "royal") then table.insert(royal, anthem) elseif role and ( mw.ustring.find(role, "national") or mw.ustring.find(role, "state anthem") ) then table.insert(national, anthem) else table.insert(other, anthem) end end -- If Wikidata has supplied an anthem but has not given -- it a role, treat the first such anthem as the national -- anthem. P85 is normally used for the country's official -- anthem. if #national == 0 and #other > 0 then table.insert(national, other[1]) table.remove(other, 1) end return national, royal, other end ------------------------------------------------------------ -- Anthem data ------------------------------------------------------------ local function getAnthemData(args) local anthems = getAnthems() local national, royal, other = classifyAnthems(anthems) local result = {} -------------------------------------------------------- -- National anthem -------------------------------------------------------- local manualNational = getManual(args, { "arrane_ashoonagh" }) if manualNational then if mw.ustring.lower(manualNational) ~= "none" then result.national = { text = '"' .. manualNational .. '"', reference = getManual(args, { "imraa_arrane_ashoonagh" }), audio = nil } end elseif #national > 0 then result.national = { text = national[1].label, reference = national[1].reference, audio = national[1].audio } end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- local manualRoyal = getManual(args, { "arrane_reeoil" }) if manualRoyal then if mw.ustring.lower(manualRoyal) ~= "none" then result.royal = { text = '"' .. manualRoyal .. '"', reference = getManual(args, { "imraa_arrane_reeoil" }), audio = nil } end elseif #royal > 0 then result.royal = { text = '"' .. royal[1].label .. '"', reference = royal[1].reference, audio = royal[1].audio } end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- local manualOther = getManual(args, { "arrane" }) if manualOther then if mw.ustring.lower(manualOther) ~= "none" then result.other = { text = '"' .. manualOther .. '"', reference = getManual(args, { "imraa_arrane" }), audio = nil } end elseif #other > 0 then result.other = { text = '"' .. other[1].label .. '"', reference = other[1].reference, audio = other[1].audio } end return result end ------------------------------------------------------------ -- Motto ------------------------------------------------------------ local function getMotto() local entity = mw.wikibase.getEntityObject() if not entity then return nil, nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil, nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return value.text, getWikidataReference(statement) end end end return nil, nil end ------------------------------------------------------------ -- Motto data ------------------------------------------------------------ local function getMottoData(args) local manual = getManual(args, { "jarroo-raa_ashoonagh", "jarroo-raa" }) if manual then if mw.ustring.lower(manual) == "none" then return nil end return { text = manual, reference = getManual(args, { "imraa_jarroo-raa" }) } end local text, reference = getMotto() if not text then return nil end return { text = text, reference = reference } end ------------------------------------------------------------ -- Motto and anthem output ------------------------------------------------------------ function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} -------------------------------------------------------- -- Motto -------------------------------------------------------- if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- National anthem -------------------------------------------------------- if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '""' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '""' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end ------------------------------------------------------------ -- Flag ------------------------------------------------------------ local function getFlag(args) -- Manual value takes precedence over Wikidata. local manual = getManual(args, { "jalloo_brattagh" }) if manual then if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P41 = flag image. return getWikidataImage("P41") end ------------------------------------------------------------ -- Coat of arms ------------------------------------------------------------ local function getArms(args) -- Manual value takes precedence over Wikidata. -- jalloo_armys is the preferred new parameter. -- jalloo_cleinney and jalloo_cowrey remain supported -- for compatibility with existing articles. local manual = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if manual then -- Explicitly suppress Wikidata. if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P94 = coat of arms image. return getWikidataImage("P94") end ------------------------------------------------------------ -- Country name ------------------------------------------------------------ local function getCountryName(args) return args.ennym_gienneydagh or args.kianglaghey_ennym or args.ennym or mw.title.getCurrentTitle().text end local function getGenitiveName(args) local name = getCountryName(args) return enmynCheerey.genitive(name) end ------------------------------------------------------------ -- Official name (Wikidata P1448) ------------------------------------------------------------ local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" and value.language and value.language ~= "" then table.insert(names, { text = value.text, lang = mw.ustring.lower(value.language) }) end end end return names end ------------------------------------------------------------ -- Language name ------------------------------------------------------------ local function getLanguageName(code) if not code or code == "" then return code end code = mw.ustring.lower(code) -- Manx Wikipedia language-name override. if langOverrideTable and langOverrideTable[code] then local name = langOverrideTable[code] if type(name) == "table" then return name[1] end return name end -- Standard language-name table. if langNameTable and langNameTable[code] then local name = langNameTable[code] if type(name) == "table" then return name[1] end return name end return code end ------------------------------------------------------------ -- Language label ------------------------------------------------------------ local function makeLanguageLabel(code) local languageName = getLanguageName(code) if not languageName or languageName == "" then return "" end -- The language name is deliberately NOT italicised. return mw.text.tag( "small", {}, "([[" .. languageName .. "|" .. languageName .. "]])" ) end ------------------------------------------------------------ -- Country title ------------------------------------------------------------ function p.title(frame) local args = getArgs(frame) local countryName = getCountryName(args) local officialNames = getOfficialNames() local manxName = nil local otherNames = {} -- Find the Manx official name first. for _, item in ipairs(officialNames) do if item.lang == "gv" then manxName = item.text break end end -- If Wikidata has no Manx P1448, use the short Manx country name. if not manxName then manxName = countryName end local output = {} -- Manx country name. -- Explicitly set the font and weight rather than inheriting -- the styling of the Infobox "above" field. table.insert( output, '<span style="font-family:inherit; font-weight:bold;">' .. manxName .. '</span>' ) -- Other official-language names. -- These must explicitly be normal weight. for _, item in ipairs(officialNames) do if item.lang ~= "gv" then local languageLabel = makeLanguageLabel(item.lang) local line = '<span style="font-weight:normal;">' .. item.text if languageLabel ~= "" then line = line .. " " .. languageLabel end line = line .. "</span>" table.insert(output, line) end end return table.concat(output, "<br>") end ------------------------------------------------------------ -- Images ------------------------------------------------------------ function p.images(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</td>' .. '<td style="width:42%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</td>' .. '</tr></table>', flag, arms, args.lheead_cowrey or "85px" ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</div>', flag ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</div>', arms, args.lheead_cowrey or "85px" ) end ------------------------------------------------------------ -- Captions ------------------------------------------------------------ function p.captions(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end local countryName = getCountryName(args) local genitiveName = getGenitiveName(args) local flagCaption = args["fo-heidyl_brattagh"] or "Brattagh" local armsCaption = args["sorçh_cowrey"] or "Armys" local armsArticle = args["art_sorçh_cowrey"] or "Armys" -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</td>' .. '<td style="width:42%%; text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</td>' .. '</tr></table>', genitiveName, flagCaption, armsArticle, genitiveName, armsCaption ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</div>', genitiveName, flagCaption ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</div>', armsArticle, genitiveName, armsCaption ) end return p 55geyzi0isjm8cdi1d2kq4ksz8phgoi 392819 392818 2026-09-06T12:33:34Z MacTire02 219 as y balley smoo 392819 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override local function getArgs(frame) return frame:getParent().args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local value = mainsnak.datavalue.value if value and value ~= "" then return value end end end return nil end ------------------------------------------------------------ -- Wikidata item statement ------------------------------------------------------------ local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end ------------------------------------------------------------ -- Wikidata reference URL ------------------------------------------------------------ local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end ------------------------------------------------------------ -- Wikidata locator map ------------------------------------------------------------ local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Locator map data ------------------------------------------------------------ local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end ------------------------------------------------------------ -- Locator map ------------------------------------------------------------ function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end ------------------------------------------------------------ -- Capital / administrative centre data ------------------------------------------------------------ local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end -------------------------------------------------------- -- Manual capital -------------------------------------------------------- if capital then return { text = capital, entity = nil, reference = nil } end -------------------------------------------------------- -- Wikidata P36 = capital -------------------------------------------------------- local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Administrative centre data ------------------------------------------------------------ local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre } end return nil end ------------------------------------------------------------ -- Largest city / settlement data ------------------------------------------------------------ local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end -------------------------------------------------------- -- Manual largest city -------------------------------------------------------- if city then return { text = city, entity = nil, reference = nil } end -------------------------------------------------------- -- Wikidata P13574 = most populous urban area -------------------------------------------------------- local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Capital / administrative centre labels ------------------------------------------------------------ local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end ------------------------------------------------------------ -- City / settlement data ------------------------------------------------------------ local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end ------------------------------------------------------------ -- Normalise a city name for comparison ------------------------------------------------------------ local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) -------------------------------------------------------- -- Remove simple wikilink markup -------------------------------------------------------- value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") -------------------------------------------------------- -- If the link has a pipe, retain only the target -------------------------------------------------------- local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end ------------------------------------------------------------ -- Determine whether capital is the largest city ------------------------------------------------------------ local function capitalIsLargest(capital, largest) if not capital or not largest then return false end -------------------------------------------------------- -- Best method: compare Wikidata entity IDs -------------------------------------------------------- if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end -------------------------------------------------------- -- Fallback: compare names -------------------------------------------------------- local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end ------------------------------------------------------------ -- Link city name to its article ------------------------------------------------------------ local function makeCityLink(city) if not city or not city.text then return "" end -------------------------------------------------------- -- If we have the Wikidata entity, use its Manx -- Wikipedia sitelink. -------------------------------------------------------- if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. city.text .. "]]" end end -------------------------------------------------------- -- Fallback: link to the displayed name itself. -------------------------------------------------------- return "[[" .. city.text .. "|" .. city.text .. "]]" end ------------------------------------------------------------ -- Coordinates ------------------------------------------------------------ local function makeCoordinates(entity) if not entity then return nil end -------------------------------------------------------- -- Wikidata P625 = coordinate location -------------------------------------------------------- local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end ------------------------------------------------------------ -- Capital / largest city / administrative centre ------------------------------------------------------------ function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]:" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end return label end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]:" end if largest then return "Balley smoo:" end return nil end function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capitalIsLargest(capital, largest) then text = text .. '<br/><small>(as y balley smoo)</small>' end if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then return makeCityLink(administrative) elseif largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end return text end return nil end function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} -------------------------------------------------------- -- Capital / administrative centre -------------------------------------------------------- if capital or administrative then local label local text ---------------------------------------------------- -- Capital ---------------------------------------------------- if capital then ------------------------------------------------ -- Link the label to Preeu-valley ------------------------------------------------ label = "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" ------------------------------------------------ -- Link the capital city ------------------------------------------------ text = makeCityLink(capital) ------------------------------------------------ -- Capital is also largest city ------------------------------------------------ if capitalIsLargest(capital, largest) then text = text .. '<br/><small>(as y balley smoo)</small>' end ------------------------------------------------ -- Coordinates directly underneath the city ------------------------------------------------ if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/>' .. coordinates end end ------------------------------------------------ -- Wikidata reference ------------------------------------------------ if capital.reference then text = text .. capital.reference end ---------------------------------------------------- -- Administrative centre only ---------------------------------------------------- else label = "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" text = makeCityLink(administrative) end table.insert( rows, "'''" .. label .. ":&nbsp;'''" .. text ) ---------------------------------------------------- -- Add largest city when different from capital ---------------------------------------------------- if largest and not capitalIsLargest(capital, largest) then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- No capital or administrative centre, -- but largest city exists -------------------------------------------------------- elseif largest then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- Nothing to display -------------------------------------------------------- if #rows == 0 then return nil end return mw.text.listToText( rows, "<br/>", "<br/>" ) end ------------------------------------------------------------ -- Wikidata audio file ------------------------------------------------------------ local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Anthems ------------------------------------------------------------ local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil -- P3831 = object of statement has role. -- This may identify the anthem as national, -- royal, regional, etc. if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { label = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end ------------------------------------------------------------ -- Classify anthems ------------------------------------------------------------ local function classifyAnthems(anthems) local national = {} local royal = {} local other = {} for _, anthem in ipairs(anthems) do local role = anthem.role if role then role = mw.ustring.lower(role) end if role and mw.ustring.find(role, "royal") then table.insert(royal, anthem) elseif role and ( mw.ustring.find(role, "national") or mw.ustring.find(role, "state anthem") ) then table.insert(national, anthem) else table.insert(other, anthem) end end -- If Wikidata has supplied an anthem but has not given -- it a role, treat the first such anthem as the national -- anthem. P85 is normally used for the country's official -- anthem. if #national == 0 and #other > 0 then table.insert(national, other[1]) table.remove(other, 1) end return national, royal, other end ------------------------------------------------------------ -- Anthem data ------------------------------------------------------------ local function getAnthemData(args) local anthems = getAnthems() local national, royal, other = classifyAnthems(anthems) local result = {} -------------------------------------------------------- -- National anthem -------------------------------------------------------- local manualNational = getManual(args, { "arrane_ashoonagh" }) if manualNational then if mw.ustring.lower(manualNational) ~= "none" then result.national = { text = '"' .. manualNational .. '"', reference = getManual(args, { "imraa_arrane_ashoonagh" }), audio = nil } end elseif #national > 0 then result.national = { text = national[1].label, reference = national[1].reference, audio = national[1].audio } end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- local manualRoyal = getManual(args, { "arrane_reeoil" }) if manualRoyal then if mw.ustring.lower(manualRoyal) ~= "none" then result.royal = { text = '"' .. manualRoyal .. '"', reference = getManual(args, { "imraa_arrane_reeoil" }), audio = nil } end elseif #royal > 0 then result.royal = { text = '"' .. royal[1].label .. '"', reference = royal[1].reference, audio = royal[1].audio } end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- local manualOther = getManual(args, { "arrane" }) if manualOther then if mw.ustring.lower(manualOther) ~= "none" then result.other = { text = '"' .. manualOther .. '"', reference = getManual(args, { "imraa_arrane" }), audio = nil } end elseif #other > 0 then result.other = { text = '"' .. other[1].label .. '"', reference = other[1].reference, audio = other[1].audio } end return result end ------------------------------------------------------------ -- Motto ------------------------------------------------------------ local function getMotto() local entity = mw.wikibase.getEntityObject() if not entity then return nil, nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil, nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return value.text, getWikidataReference(statement) end end end return nil, nil end ------------------------------------------------------------ -- Motto data ------------------------------------------------------------ local function getMottoData(args) local manual = getManual(args, { "jarroo-raa_ashoonagh", "jarroo-raa" }) if manual then if mw.ustring.lower(manual) == "none" then return nil end return { text = manual, reference = getManual(args, { "imraa_jarroo-raa" }) } end local text, reference = getMotto() if not text then return nil end return { text = text, reference = reference } end ------------------------------------------------------------ -- Motto and anthem output ------------------------------------------------------------ function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} -------------------------------------------------------- -- Motto -------------------------------------------------------- if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- National anthem -------------------------------------------------------- if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '""' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '""' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end ------------------------------------------------------------ -- Flag ------------------------------------------------------------ local function getFlag(args) -- Manual value takes precedence over Wikidata. local manual = getManual(args, { "jalloo_brattagh" }) if manual then if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P41 = flag image. return getWikidataImage("P41") end ------------------------------------------------------------ -- Coat of arms ------------------------------------------------------------ local function getArms(args) -- Manual value takes precedence over Wikidata. -- jalloo_armys is the preferred new parameter. -- jalloo_cleinney and jalloo_cowrey remain supported -- for compatibility with existing articles. local manual = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if manual then -- Explicitly suppress Wikidata. if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P94 = coat of arms image. return getWikidataImage("P94") end ------------------------------------------------------------ -- Country name ------------------------------------------------------------ local function getCountryName(args) return args.ennym_gienneydagh or args.kianglaghey_ennym or args.ennym or mw.title.getCurrentTitle().text end local function getGenitiveName(args) local name = getCountryName(args) return enmynCheerey.genitive(name) end ------------------------------------------------------------ -- Official name (Wikidata P1448) ------------------------------------------------------------ local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" and value.language and value.language ~= "" then table.insert(names, { text = value.text, lang = mw.ustring.lower(value.language) }) end end end return names end ------------------------------------------------------------ -- Language name ------------------------------------------------------------ local function getLanguageName(code) if not code or code == "" then return code end code = mw.ustring.lower(code) -- Manx Wikipedia language-name override. if langOverrideTable and langOverrideTable[code] then local name = langOverrideTable[code] if type(name) == "table" then return name[1] end return name end -- Standard language-name table. if langNameTable and langNameTable[code] then local name = langNameTable[code] if type(name) == "table" then return name[1] end return name end return code end ------------------------------------------------------------ -- Language label ------------------------------------------------------------ local function makeLanguageLabel(code) local languageName = getLanguageName(code) if not languageName or languageName == "" then return "" end -- The language name is deliberately NOT italicised. return mw.text.tag( "small", {}, "([[" .. languageName .. "|" .. languageName .. "]])" ) end ------------------------------------------------------------ -- Country title ------------------------------------------------------------ function p.title(frame) local args = getArgs(frame) local countryName = getCountryName(args) local officialNames = getOfficialNames() local manxName = nil local otherNames = {} -- Find the Manx official name first. for _, item in ipairs(officialNames) do if item.lang == "gv" then manxName = item.text break end end -- If Wikidata has no Manx P1448, use the short Manx country name. if not manxName then manxName = countryName end local output = {} -- Manx country name. -- Explicitly set the font and weight rather than inheriting -- the styling of the Infobox "above" field. table.insert( output, '<span style="font-family:inherit; font-weight:bold;">' .. manxName .. '</span>' ) -- Other official-language names. -- These must explicitly be normal weight. for _, item in ipairs(officialNames) do if item.lang ~= "gv" then local languageLabel = makeLanguageLabel(item.lang) local line = '<span style="font-weight:normal;">' .. item.text if languageLabel ~= "" then line = line .. " " .. languageLabel end line = line .. "</span>" table.insert(output, line) end end return table.concat(output, "<br>") end ------------------------------------------------------------ -- Images ------------------------------------------------------------ function p.images(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</td>' .. '<td style="width:42%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</td>' .. '</tr></table>', flag, arms, args.lheead_cowrey or "85px" ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</div>', flag ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</div>', arms, args.lheead_cowrey or "85px" ) end ------------------------------------------------------------ -- Captions ------------------------------------------------------------ function p.captions(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end local countryName = getCountryName(args) local genitiveName = getGenitiveName(args) local flagCaption = args["fo-heidyl_brattagh"] or "Brattagh" local armsCaption = args["sorçh_cowrey"] or "Armys" local armsArticle = args["art_sorçh_cowrey"] or "Armys" -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</td>' .. '<td style="width:42%%; text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</td>' .. '</tr></table>', genitiveName, flagCaption, armsArticle, genitiveName, armsCaption ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</div>', genitiveName, flagCaption ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</div>', armsArticle, genitiveName, armsCaption ) end return p 32ldbpma537yqf6jnjuzmpf9jsp2a4f 392820 392819 2026-09-06T12:34:36Z MacTire02 219 ++ 392820 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override local function getArgs(frame) return frame:getParent().args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local value = mainsnak.datavalue.value if value and value ~= "" then return value end end end return nil end ------------------------------------------------------------ -- Wikidata item statement ------------------------------------------------------------ local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end ------------------------------------------------------------ -- Wikidata reference URL ------------------------------------------------------------ local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end ------------------------------------------------------------ -- Wikidata locator map ------------------------------------------------------------ local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Locator map data ------------------------------------------------------------ local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end ------------------------------------------------------------ -- Locator map ------------------------------------------------------------ function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end ------------------------------------------------------------ -- Capital / administrative centre data ------------------------------------------------------------ local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end -------------------------------------------------------- -- Manual capital -------------------------------------------------------- if capital then return { text = capital, entity = nil, reference = nil } end -------------------------------------------------------- -- Wikidata P36 = capital -------------------------------------------------------- local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Administrative centre data ------------------------------------------------------------ local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre } end return nil end ------------------------------------------------------------ -- Largest city / settlement data ------------------------------------------------------------ local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end -------------------------------------------------------- -- Manual largest city -------------------------------------------------------- if city then return { text = city, entity = nil, reference = nil } end -------------------------------------------------------- -- Wikidata P13574 = most populous urban area -------------------------------------------------------- local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Capital / administrative centre labels ------------------------------------------------------------ local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end ------------------------------------------------------------ -- City / settlement data ------------------------------------------------------------ local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end ------------------------------------------------------------ -- Normalise a city name for comparison ------------------------------------------------------------ local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) -------------------------------------------------------- -- Remove simple wikilink markup -------------------------------------------------------- value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") -------------------------------------------------------- -- If the link has a pipe, retain only the target -------------------------------------------------------- local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end ------------------------------------------------------------ -- Determine whether capital is the largest city ------------------------------------------------------------ local function capitalIsLargest(capital, largest) if not capital or not largest then return false end -------------------------------------------------------- -- Best method: compare Wikidata entity IDs -------------------------------------------------------- if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end -------------------------------------------------------- -- Fallback: compare names -------------------------------------------------------- local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end ------------------------------------------------------------ -- Link city name to its article ------------------------------------------------------------ local function makeCityLink(city) if not city or not city.text then return "" end -------------------------------------------------------- -- If we have the Wikidata entity, use its Manx -- Wikipedia sitelink. -------------------------------------------------------- if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. city.text .. "]]" end end -------------------------------------------------------- -- Fallback: link to the displayed name itself. -------------------------------------------------------- return "[[" .. city.text .. "|" .. city.text .. "]]" end ------------------------------------------------------------ -- Coordinates ------------------------------------------------------------ local function makeCoordinates(entity) if not entity then return nil end -------------------------------------------------------- -- Wikidata P625 = coordinate location -------------------------------------------------------- local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end ------------------------------------------------------------ -- Capital / largest city / administrative centre ------------------------------------------------------------ function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]:" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end return label end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]:" end if largest then return "Balley smoo:" end return nil end function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then return makeCityLink(administrative) elseif largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end return text end return nil end function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} -------------------------------------------------------- -- Capital / administrative centre -------------------------------------------------------- if capital or administrative then local label local text ---------------------------------------------------- -- Capital ---------------------------------------------------- if capital then ------------------------------------------------ -- Link the label to Preeu-valley ------------------------------------------------ label = "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" ------------------------------------------------ -- Link the capital city ------------------------------------------------ text = makeCityLink(capital) ------------------------------------------------ -- Capital is also largest city ------------------------------------------------ if capitalIsLargest(capital, largest) then text = text .. '<br/><small>(as y balley smoo)</small>' end ------------------------------------------------ -- Coordinates directly underneath the city ------------------------------------------------ if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/>' .. coordinates end end ------------------------------------------------ -- Wikidata reference ------------------------------------------------ if capital.reference then text = text .. capital.reference end ---------------------------------------------------- -- Administrative centre only ---------------------------------------------------- else label = "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" text = makeCityLink(administrative) end table.insert( rows, "'''" .. label .. ":&nbsp;'''" .. text ) ---------------------------------------------------- -- Add largest city when different from capital ---------------------------------------------------- if largest and not capitalIsLargest(capital, largest) then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- No capital or administrative centre, -- but largest city exists -------------------------------------------------------- elseif largest then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- Nothing to display -------------------------------------------------------- if #rows == 0 then return nil end return mw.text.listToText( rows, "<br/>", "<br/>" ) end ------------------------------------------------------------ -- Wikidata audio file ------------------------------------------------------------ local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Anthems ------------------------------------------------------------ local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil -- P3831 = object of statement has role. -- This may identify the anthem as national, -- royal, regional, etc. if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { label = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end ------------------------------------------------------------ -- Classify anthems ------------------------------------------------------------ local function classifyAnthems(anthems) local national = {} local royal = {} local other = {} for _, anthem in ipairs(anthems) do local role = anthem.role if role then role = mw.ustring.lower(role) end if role and mw.ustring.find(role, "royal") then table.insert(royal, anthem) elseif role and ( mw.ustring.find(role, "national") or mw.ustring.find(role, "state anthem") ) then table.insert(national, anthem) else table.insert(other, anthem) end end -- If Wikidata has supplied an anthem but has not given -- it a role, treat the first such anthem as the national -- anthem. P85 is normally used for the country's official -- anthem. if #national == 0 and #other > 0 then table.insert(national, other[1]) table.remove(other, 1) end return national, royal, other end ------------------------------------------------------------ -- Anthem data ------------------------------------------------------------ local function getAnthemData(args) local anthems = getAnthems() local national, royal, other = classifyAnthems(anthems) local result = {} -------------------------------------------------------- -- National anthem -------------------------------------------------------- local manualNational = getManual(args, { "arrane_ashoonagh" }) if manualNational then if mw.ustring.lower(manualNational) ~= "none" then result.national = { text = '"' .. manualNational .. '"', reference = getManual(args, { "imraa_arrane_ashoonagh" }), audio = nil } end elseif #national > 0 then result.national = { text = national[1].label, reference = national[1].reference, audio = national[1].audio } end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- local manualRoyal = getManual(args, { "arrane_reeoil" }) if manualRoyal then if mw.ustring.lower(manualRoyal) ~= "none" then result.royal = { text = '"' .. manualRoyal .. '"', reference = getManual(args, { "imraa_arrane_reeoil" }), audio = nil } end elseif #royal > 0 then result.royal = { text = '"' .. royal[1].label .. '"', reference = royal[1].reference, audio = royal[1].audio } end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- local manualOther = getManual(args, { "arrane" }) if manualOther then if mw.ustring.lower(manualOther) ~= "none" then result.other = { text = '"' .. manualOther .. '"', reference = getManual(args, { "imraa_arrane" }), audio = nil } end elseif #other > 0 then result.other = { text = '"' .. other[1].label .. '"', reference = other[1].reference, audio = other[1].audio } end return result end ------------------------------------------------------------ -- Motto ------------------------------------------------------------ local function getMotto() local entity = mw.wikibase.getEntityObject() if not entity then return nil, nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil, nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return value.text, getWikidataReference(statement) end end end return nil, nil end ------------------------------------------------------------ -- Motto data ------------------------------------------------------------ local function getMottoData(args) local manual = getManual(args, { "jarroo-raa_ashoonagh", "jarroo-raa" }) if manual then if mw.ustring.lower(manual) == "none" then return nil end return { text = manual, reference = getManual(args, { "imraa_jarroo-raa" }) } end local text, reference = getMotto() if not text then return nil end return { text = text, reference = reference } end ------------------------------------------------------------ -- Motto and anthem output ------------------------------------------------------------ function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} -------------------------------------------------------- -- Motto -------------------------------------------------------- if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- National anthem -------------------------------------------------------- if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '""' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '""' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end ------------------------------------------------------------ -- Flag ------------------------------------------------------------ local function getFlag(args) -- Manual value takes precedence over Wikidata. local manual = getManual(args, { "jalloo_brattagh" }) if manual then if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P41 = flag image. return getWikidataImage("P41") end ------------------------------------------------------------ -- Coat of arms ------------------------------------------------------------ local function getArms(args) -- Manual value takes precedence over Wikidata. -- jalloo_armys is the preferred new parameter. -- jalloo_cleinney and jalloo_cowrey remain supported -- for compatibility with existing articles. local manual = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if manual then -- Explicitly suppress Wikidata. if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P94 = coat of arms image. return getWikidataImage("P94") end ------------------------------------------------------------ -- Country name ------------------------------------------------------------ local function getCountryName(args) return args.ennym_gienneydagh or args.kianglaghey_ennym or args.ennym or mw.title.getCurrentTitle().text end local function getGenitiveName(args) local name = getCountryName(args) return enmynCheerey.genitive(name) end ------------------------------------------------------------ -- Official name (Wikidata P1448) ------------------------------------------------------------ local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" and value.language and value.language ~= "" then table.insert(names, { text = value.text, lang = mw.ustring.lower(value.language) }) end end end return names end ------------------------------------------------------------ -- Language name ------------------------------------------------------------ local function getLanguageName(code) if not code or code == "" then return code end code = mw.ustring.lower(code) -- Manx Wikipedia language-name override. if langOverrideTable and langOverrideTable[code] then local name = langOverrideTable[code] if type(name) == "table" then return name[1] end return name end -- Standard language-name table. if langNameTable and langNameTable[code] then local name = langNameTable[code] if type(name) == "table" then return name[1] end return name end return code end ------------------------------------------------------------ -- Language label ------------------------------------------------------------ local function makeLanguageLabel(code) local languageName = getLanguageName(code) if not languageName or languageName == "" then return "" end -- The language name is deliberately NOT italicised. return mw.text.tag( "small", {}, "([[" .. languageName .. "|" .. languageName .. "]])" ) end ------------------------------------------------------------ -- Country title ------------------------------------------------------------ function p.title(frame) local args = getArgs(frame) local countryName = getCountryName(args) local officialNames = getOfficialNames() local manxName = nil local otherNames = {} -- Find the Manx official name first. for _, item in ipairs(officialNames) do if item.lang == "gv" then manxName = item.text break end end -- If Wikidata has no Manx P1448, use the short Manx country name. if not manxName then manxName = countryName end local output = {} -- Manx country name. -- Explicitly set the font and weight rather than inheriting -- the styling of the Infobox "above" field. table.insert( output, '<span style="font-family:inherit; font-weight:bold;">' .. manxName .. '</span>' ) -- Other official-language names. -- These must explicitly be normal weight. for _, item in ipairs(officialNames) do if item.lang ~= "gv" then local languageLabel = makeLanguageLabel(item.lang) local line = '<span style="font-weight:normal;">' .. item.text if languageLabel ~= "" then line = line .. " " .. languageLabel end line = line .. "</span>" table.insert(output, line) end end return table.concat(output, "<br>") end ------------------------------------------------------------ -- Images ------------------------------------------------------------ function p.images(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</td>' .. '<td style="width:42%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</td>' .. '</tr></table>', flag, arms, args.lheead_cowrey or "85px" ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</div>', flag ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</div>', arms, args.lheead_cowrey or "85px" ) end ------------------------------------------------------------ -- Captions ------------------------------------------------------------ function p.captions(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end local countryName = getCountryName(args) local genitiveName = getGenitiveName(args) local flagCaption = args["fo-heidyl_brattagh"] or "Brattagh" local armsCaption = args["sorçh_cowrey"] or "Armys" local armsArticle = args["art_sorçh_cowrey"] or "Armys" -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</td>' .. '<td style="width:42%%; text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</td>' .. '</tr></table>', genitiveName, flagCaption, armsArticle, genitiveName, armsCaption ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</div>', genitiveName, flagCaption ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</div>', armsArticle, genitiveName, armsCaption ) end return p 5be67wv11caoaw27n31oeyd15dytuf2 392822 392820 2026-09-06T12:37:06Z MacTire02 219 prowal red bentyn rish ny h-ard-valjyn 392822 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override local function getArgs(frame) return frame:getParent().args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local value = mainsnak.datavalue.value if value and value ~= "" then return value end end end return nil end ------------------------------------------------------------ -- Wikidata item statement ------------------------------------------------------------ local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end ------------------------------------------------------------ -- Wikidata reference URL ------------------------------------------------------------ local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end ------------------------------------------------------------ -- Wikidata locator map ------------------------------------------------------------ local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Locator map data ------------------------------------------------------------ local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end ------------------------------------------------------------ -- Locator map ------------------------------------------------------------ function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end ------------------------------------------------------------ -- Capital / administrative centre data ------------------------------------------------------------ local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end -------------------------------------------------------- -- Manual capital -------------------------------------------------------- if capital then return { text = capital, entity = nil, reference = nil } end -------------------------------------------------------- -- Wikidata P36 = capital -------------------------------------------------------- local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Administrative centre data ------------------------------------------------------------ local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre } end return nil end ------------------------------------------------------------ -- Largest city / settlement data ------------------------------------------------------------ local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end -------------------------------------------------------- -- Manual largest city -------------------------------------------------------- if city then return { text = city, entity = nil, reference = nil } end -------------------------------------------------------- -- Wikidata P13574 = most populous urban area -------------------------------------------------------- local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Capital / administrative centre labels ------------------------------------------------------------ local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end ------------------------------------------------------------ -- City / settlement data ------------------------------------------------------------ local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end ------------------------------------------------------------ -- Normalise a city name for comparison ------------------------------------------------------------ local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) -------------------------------------------------------- -- Remove simple wikilink markup -------------------------------------------------------- value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") -------------------------------------------------------- -- If the link has a pipe, retain only the target -------------------------------------------------------- local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end ------------------------------------------------------------ -- Determine whether capital is the largest city ------------------------------------------------------------ local function capitalIsLargest(capital, largest) if not capital or not largest then return false end -------------------------------------------------------- -- Best method: compare Wikidata entity IDs -------------------------------------------------------- if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end -------------------------------------------------------- -- Fallback: compare names -------------------------------------------------------- local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end ------------------------------------------------------------ -- Link city name to its article ------------------------------------------------------------ local function makeCityLink(city) if not city or not city.text then return "" end -------------------------------------------------------- -- If we have the Wikidata entity, use its Manx -- Wikipedia sitelink. -------------------------------------------------------- if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. city.text .. "]]" end end -------------------------------------------------------- -- Fallback: link to the displayed name itself. -------------------------------------------------------- return "[[" .. city.text .. "|" .. city.text .. "]]" end ------------------------------------------------------------ -- Coordinates ------------------------------------------------------------ local function makeCoordinates(entity) if not entity then return nil end -------------------------------------------------------- -- Wikidata P625 = coordinate location -------------------------------------------------------- local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end ------------------------------------------------------------ -- Capital / largest city / administrative centre ------------------------------------------------------------ function p.test_largest(frame) local entity, statement = getWikidataItem("P13574") if not entity then return "P13574: nil" end return "P13574: " .. (entity:getLabel() or "no label") end function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]:" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end return label end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]:" end if largest then return "Balley smoo:" end return nil end function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then return makeCityLink(administrative) elseif largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end return text end return nil end function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} -------------------------------------------------------- -- Capital / administrative centre -------------------------------------------------------- if capital or administrative then local label local text ---------------------------------------------------- -- Capital ---------------------------------------------------- if capital then ------------------------------------------------ -- Link the label to Preeu-valley ------------------------------------------------ label = "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" ------------------------------------------------ -- Link the capital city ------------------------------------------------ text = makeCityLink(capital) ------------------------------------------------ -- Capital is also largest city ------------------------------------------------ if capitalIsLargest(capital, largest) then text = text .. '<br/><small>(as y balley smoo)</small>' end ------------------------------------------------ -- Coordinates directly underneath the city ------------------------------------------------ if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/>' .. coordinates end end ------------------------------------------------ -- Wikidata reference ------------------------------------------------ if capital.reference then text = text .. capital.reference end ---------------------------------------------------- -- Administrative centre only ---------------------------------------------------- else label = "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" text = makeCityLink(administrative) end table.insert( rows, "'''" .. label .. ":&nbsp;'''" .. text ) ---------------------------------------------------- -- Add largest city when different from capital ---------------------------------------------------- if largest and not capitalIsLargest(capital, largest) then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- No capital or administrative centre, -- but largest city exists -------------------------------------------------------- elseif largest then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- Nothing to display -------------------------------------------------------- if #rows == 0 then return nil end return mw.text.listToText( rows, "<br/>", "<br/>" ) end ------------------------------------------------------------ -- Wikidata audio file ------------------------------------------------------------ local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Anthems ------------------------------------------------------------ local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil -- P3831 = object of statement has role. -- This may identify the anthem as national, -- royal, regional, etc. if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { label = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end ------------------------------------------------------------ -- Classify anthems ------------------------------------------------------------ local function classifyAnthems(anthems) local national = {} local royal = {} local other = {} for _, anthem in ipairs(anthems) do local role = anthem.role if role then role = mw.ustring.lower(role) end if role and mw.ustring.find(role, "royal") then table.insert(royal, anthem) elseif role and ( mw.ustring.find(role, "national") or mw.ustring.find(role, "state anthem") ) then table.insert(national, anthem) else table.insert(other, anthem) end end -- If Wikidata has supplied an anthem but has not given -- it a role, treat the first such anthem as the national -- anthem. P85 is normally used for the country's official -- anthem. if #national == 0 and #other > 0 then table.insert(national, other[1]) table.remove(other, 1) end return national, royal, other end ------------------------------------------------------------ -- Anthem data ------------------------------------------------------------ local function getAnthemData(args) local anthems = getAnthems() local national, royal, other = classifyAnthems(anthems) local result = {} -------------------------------------------------------- -- National anthem -------------------------------------------------------- local manualNational = getManual(args, { "arrane_ashoonagh" }) if manualNational then if mw.ustring.lower(manualNational) ~= "none" then result.national = { text = '"' .. manualNational .. '"', reference = getManual(args, { "imraa_arrane_ashoonagh" }), audio = nil } end elseif #national > 0 then result.national = { text = national[1].label, reference = national[1].reference, audio = national[1].audio } end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- local manualRoyal = getManual(args, { "arrane_reeoil" }) if manualRoyal then if mw.ustring.lower(manualRoyal) ~= "none" then result.royal = { text = '"' .. manualRoyal .. '"', reference = getManual(args, { "imraa_arrane_reeoil" }), audio = nil } end elseif #royal > 0 then result.royal = { text = '"' .. royal[1].label .. '"', reference = royal[1].reference, audio = royal[1].audio } end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- local manualOther = getManual(args, { "arrane" }) if manualOther then if mw.ustring.lower(manualOther) ~= "none" then result.other = { text = '"' .. manualOther .. '"', reference = getManual(args, { "imraa_arrane" }), audio = nil } end elseif #other > 0 then result.other = { text = '"' .. other[1].label .. '"', reference = other[1].reference, audio = other[1].audio } end return result end ------------------------------------------------------------ -- Motto ------------------------------------------------------------ local function getMotto() local entity = mw.wikibase.getEntityObject() if not entity then return nil, nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil, nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return value.text, getWikidataReference(statement) end end end return nil, nil end ------------------------------------------------------------ -- Motto data ------------------------------------------------------------ local function getMottoData(args) local manual = getManual(args, { "jarroo-raa_ashoonagh", "jarroo-raa" }) if manual then if mw.ustring.lower(manual) == "none" then return nil end return { text = manual, reference = getManual(args, { "imraa_jarroo-raa" }) } end local text, reference = getMotto() if not text then return nil end return { text = text, reference = reference } end ------------------------------------------------------------ -- Motto and anthem output ------------------------------------------------------------ function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} -------------------------------------------------------- -- Motto -------------------------------------------------------- if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- National anthem -------------------------------------------------------- if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '""' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '""' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end ------------------------------------------------------------ -- Flag ------------------------------------------------------------ local function getFlag(args) -- Manual value takes precedence over Wikidata. local manual = getManual(args, { "jalloo_brattagh" }) if manual then if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P41 = flag image. return getWikidataImage("P41") end ------------------------------------------------------------ -- Coat of arms ------------------------------------------------------------ local function getArms(args) -- Manual value takes precedence over Wikidata. -- jalloo_armys is the preferred new parameter. -- jalloo_cleinney and jalloo_cowrey remain supported -- for compatibility with existing articles. local manual = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if manual then -- Explicitly suppress Wikidata. if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P94 = coat of arms image. return getWikidataImage("P94") end ------------------------------------------------------------ -- Country name ------------------------------------------------------------ local function getCountryName(args) return args.ennym_gienneydagh or args.kianglaghey_ennym or args.ennym or mw.title.getCurrentTitle().text end local function getGenitiveName(args) local name = getCountryName(args) return enmynCheerey.genitive(name) end ------------------------------------------------------------ -- Official name (Wikidata P1448) ------------------------------------------------------------ local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" and value.language and value.language ~= "" then table.insert(names, { text = value.text, lang = mw.ustring.lower(value.language) }) end end end return names end ------------------------------------------------------------ -- Language name ------------------------------------------------------------ local function getLanguageName(code) if not code or code == "" then return code end code = mw.ustring.lower(code) -- Manx Wikipedia language-name override. if langOverrideTable and langOverrideTable[code] then local name = langOverrideTable[code] if type(name) == "table" then return name[1] end return name end -- Standard language-name table. if langNameTable and langNameTable[code] then local name = langNameTable[code] if type(name) == "table" then return name[1] end return name end return code end ------------------------------------------------------------ -- Language label ------------------------------------------------------------ local function makeLanguageLabel(code) local languageName = getLanguageName(code) if not languageName or languageName == "" then return "" end -- The language name is deliberately NOT italicised. return mw.text.tag( "small", {}, "([[" .. languageName .. "|" .. languageName .. "]])" ) end ------------------------------------------------------------ -- Country title ------------------------------------------------------------ function p.title(frame) local args = getArgs(frame) local countryName = getCountryName(args) local officialNames = getOfficialNames() local manxName = nil local otherNames = {} -- Find the Manx official name first. for _, item in ipairs(officialNames) do if item.lang == "gv" then manxName = item.text break end end -- If Wikidata has no Manx P1448, use the short Manx country name. if not manxName then manxName = countryName end local output = {} -- Manx country name. -- Explicitly set the font and weight rather than inheriting -- the styling of the Infobox "above" field. table.insert( output, '<span style="font-family:inherit; font-weight:bold;">' .. manxName .. '</span>' ) -- Other official-language names. -- These must explicitly be normal weight. for _, item in ipairs(officialNames) do if item.lang ~= "gv" then local languageLabel = makeLanguageLabel(item.lang) local line = '<span style="font-weight:normal;">' .. item.text if languageLabel ~= "" then line = line .. " " .. languageLabel end line = line .. "</span>" table.insert(output, line) end end return table.concat(output, "<br>") end ------------------------------------------------------------ -- Images ------------------------------------------------------------ function p.images(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</td>' .. '<td style="width:42%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</td>' .. '</tr></table>', flag, arms, args.lheead_cowrey or "85px" ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</div>', flag ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</div>', arms, args.lheead_cowrey or "85px" ) end ------------------------------------------------------------ -- Captions ------------------------------------------------------------ function p.captions(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end local countryName = getCountryName(args) local genitiveName = getGenitiveName(args) local flagCaption = args["fo-heidyl_brattagh"] or "Brattagh" local armsCaption = args["sorçh_cowrey"] or "Armys" local armsArticle = args["art_sorçh_cowrey"] or "Armys" -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</td>' .. '<td style="width:42%%; text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</td>' .. '</tr></table>', genitiveName, flagCaption, armsArticle, genitiveName, armsCaption ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</div>', genitiveName, flagCaption ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</div>', armsArticle, genitiveName, armsCaption ) end return p 4mkjqkcyfqrxrcpzz195s1p2p33jbsh 392823 392822 2026-09-06T12:38:24Z MacTire02 219 Undid revision [[Special:Diff/392822|392822]] by [[Special:Contributions/MacTire02|MacTire02]] ([[User talk:MacTire02|talk]]) 392823 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override local function getArgs(frame) return frame:getParent().args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local value = mainsnak.datavalue.value if value and value ~= "" then return value end end end return nil end ------------------------------------------------------------ -- Wikidata item statement ------------------------------------------------------------ local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end ------------------------------------------------------------ -- Wikidata reference URL ------------------------------------------------------------ local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end ------------------------------------------------------------ -- Wikidata locator map ------------------------------------------------------------ local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Locator map data ------------------------------------------------------------ local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end ------------------------------------------------------------ -- Locator map ------------------------------------------------------------ function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end ------------------------------------------------------------ -- Capital / administrative centre data ------------------------------------------------------------ local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end -------------------------------------------------------- -- Manual capital -------------------------------------------------------- if capital then return { text = capital, entity = nil, reference = nil } end -------------------------------------------------------- -- Wikidata P36 = capital -------------------------------------------------------- local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Administrative centre data ------------------------------------------------------------ local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre } end return nil end ------------------------------------------------------------ -- Largest city / settlement data ------------------------------------------------------------ local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end -------------------------------------------------------- -- Manual largest city -------------------------------------------------------- if city then return { text = city, entity = nil, reference = nil } end -------------------------------------------------------- -- Wikidata P13574 = most populous urban area -------------------------------------------------------- local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Capital / administrative centre labels ------------------------------------------------------------ local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end ------------------------------------------------------------ -- City / settlement data ------------------------------------------------------------ local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end ------------------------------------------------------------ -- Normalise a city name for comparison ------------------------------------------------------------ local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) -------------------------------------------------------- -- Remove simple wikilink markup -------------------------------------------------------- value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") -------------------------------------------------------- -- If the link has a pipe, retain only the target -------------------------------------------------------- local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end ------------------------------------------------------------ -- Determine whether capital is the largest city ------------------------------------------------------------ local function capitalIsLargest(capital, largest) if not capital or not largest then return false end -------------------------------------------------------- -- Best method: compare Wikidata entity IDs -------------------------------------------------------- if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end -------------------------------------------------------- -- Fallback: compare names -------------------------------------------------------- local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end ------------------------------------------------------------ -- Link city name to its article ------------------------------------------------------------ local function makeCityLink(city) if not city or not city.text then return "" end -------------------------------------------------------- -- If we have the Wikidata entity, use its Manx -- Wikipedia sitelink. -------------------------------------------------------- if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. city.text .. "]]" end end -------------------------------------------------------- -- Fallback: link to the displayed name itself. -------------------------------------------------------- return "[[" .. city.text .. "|" .. city.text .. "]]" end ------------------------------------------------------------ -- Coordinates ------------------------------------------------------------ local function makeCoordinates(entity) if not entity then return nil end -------------------------------------------------------- -- Wikidata P625 = coordinate location -------------------------------------------------------- local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end ------------------------------------------------------------ -- Capital / largest city / administrative centre ------------------------------------------------------------ function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]:" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end return label end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]:" end if largest then return "Balley smoo:" end return nil end function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then return makeCityLink(administrative) elseif largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end return text end return nil end function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} -------------------------------------------------------- -- Capital / administrative centre -------------------------------------------------------- if capital or administrative then local label local text ---------------------------------------------------- -- Capital ---------------------------------------------------- if capital then ------------------------------------------------ -- Link the label to Preeu-valley ------------------------------------------------ label = "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" ------------------------------------------------ -- Link the capital city ------------------------------------------------ text = makeCityLink(capital) ------------------------------------------------ -- Capital is also largest city ------------------------------------------------ if capitalIsLargest(capital, largest) then text = text .. '<br/><small>(as y balley smoo)</small>' end ------------------------------------------------ -- Coordinates directly underneath the city ------------------------------------------------ if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/>' .. coordinates end end ------------------------------------------------ -- Wikidata reference ------------------------------------------------ if capital.reference then text = text .. capital.reference end ---------------------------------------------------- -- Administrative centre only ---------------------------------------------------- else label = "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" text = makeCityLink(administrative) end table.insert( rows, "'''" .. label .. ":&nbsp;'''" .. text ) ---------------------------------------------------- -- Add largest city when different from capital ---------------------------------------------------- if largest and not capitalIsLargest(capital, largest) then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- No capital or administrative centre, -- but largest city exists -------------------------------------------------------- elseif largest then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- Nothing to display -------------------------------------------------------- if #rows == 0 then return nil end return mw.text.listToText( rows, "<br/>", "<br/>" ) end ------------------------------------------------------------ -- Wikidata audio file ------------------------------------------------------------ local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Anthems ------------------------------------------------------------ local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil -- P3831 = object of statement has role. -- This may identify the anthem as national, -- royal, regional, etc. if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { label = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end ------------------------------------------------------------ -- Classify anthems ------------------------------------------------------------ local function classifyAnthems(anthems) local national = {} local royal = {} local other = {} for _, anthem in ipairs(anthems) do local role = anthem.role if role then role = mw.ustring.lower(role) end if role and mw.ustring.find(role, "royal") then table.insert(royal, anthem) elseif role and ( mw.ustring.find(role, "national") or mw.ustring.find(role, "state anthem") ) then table.insert(national, anthem) else table.insert(other, anthem) end end -- If Wikidata has supplied an anthem but has not given -- it a role, treat the first such anthem as the national -- anthem. P85 is normally used for the country's official -- anthem. if #national == 0 and #other > 0 then table.insert(national, other[1]) table.remove(other, 1) end return national, royal, other end ------------------------------------------------------------ -- Anthem data ------------------------------------------------------------ local function getAnthemData(args) local anthems = getAnthems() local national, royal, other = classifyAnthems(anthems) local result = {} -------------------------------------------------------- -- National anthem -------------------------------------------------------- local manualNational = getManual(args, { "arrane_ashoonagh" }) if manualNational then if mw.ustring.lower(manualNational) ~= "none" then result.national = { text = '"' .. manualNational .. '"', reference = getManual(args, { "imraa_arrane_ashoonagh" }), audio = nil } end elseif #national > 0 then result.national = { text = national[1].label, reference = national[1].reference, audio = national[1].audio } end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- local manualRoyal = getManual(args, { "arrane_reeoil" }) if manualRoyal then if mw.ustring.lower(manualRoyal) ~= "none" then result.royal = { text = '"' .. manualRoyal .. '"', reference = getManual(args, { "imraa_arrane_reeoil" }), audio = nil } end elseif #royal > 0 then result.royal = { text = '"' .. royal[1].label .. '"', reference = royal[1].reference, audio = royal[1].audio } end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- local manualOther = getManual(args, { "arrane" }) if manualOther then if mw.ustring.lower(manualOther) ~= "none" then result.other = { text = '"' .. manualOther .. '"', reference = getManual(args, { "imraa_arrane" }), audio = nil } end elseif #other > 0 then result.other = { text = '"' .. other[1].label .. '"', reference = other[1].reference, audio = other[1].audio } end return result end ------------------------------------------------------------ -- Motto ------------------------------------------------------------ local function getMotto() local entity = mw.wikibase.getEntityObject() if not entity then return nil, nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil, nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return value.text, getWikidataReference(statement) end end end return nil, nil end ------------------------------------------------------------ -- Motto data ------------------------------------------------------------ local function getMottoData(args) local manual = getManual(args, { "jarroo-raa_ashoonagh", "jarroo-raa" }) if manual then if mw.ustring.lower(manual) == "none" then return nil end return { text = manual, reference = getManual(args, { "imraa_jarroo-raa" }) } end local text, reference = getMotto() if not text then return nil end return { text = text, reference = reference } end ------------------------------------------------------------ -- Motto and anthem output ------------------------------------------------------------ function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} -------------------------------------------------------- -- Motto -------------------------------------------------------- if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- National anthem -------------------------------------------------------- if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '""' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '""' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end ------------------------------------------------------------ -- Flag ------------------------------------------------------------ local function getFlag(args) -- Manual value takes precedence over Wikidata. local manual = getManual(args, { "jalloo_brattagh" }) if manual then if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P41 = flag image. return getWikidataImage("P41") end ------------------------------------------------------------ -- Coat of arms ------------------------------------------------------------ local function getArms(args) -- Manual value takes precedence over Wikidata. -- jalloo_armys is the preferred new parameter. -- jalloo_cleinney and jalloo_cowrey remain supported -- for compatibility with existing articles. local manual = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if manual then -- Explicitly suppress Wikidata. if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P94 = coat of arms image. return getWikidataImage("P94") end ------------------------------------------------------------ -- Country name ------------------------------------------------------------ local function getCountryName(args) return args.ennym_gienneydagh or args.kianglaghey_ennym or args.ennym or mw.title.getCurrentTitle().text end local function getGenitiveName(args) local name = getCountryName(args) return enmynCheerey.genitive(name) end ------------------------------------------------------------ -- Official name (Wikidata P1448) ------------------------------------------------------------ local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" and value.language and value.language ~= "" then table.insert(names, { text = value.text, lang = mw.ustring.lower(value.language) }) end end end return names end ------------------------------------------------------------ -- Language name ------------------------------------------------------------ local function getLanguageName(code) if not code or code == "" then return code end code = mw.ustring.lower(code) -- Manx Wikipedia language-name override. if langOverrideTable and langOverrideTable[code] then local name = langOverrideTable[code] if type(name) == "table" then return name[1] end return name end -- Standard language-name table. if langNameTable and langNameTable[code] then local name = langNameTable[code] if type(name) == "table" then return name[1] end return name end return code end ------------------------------------------------------------ -- Language label ------------------------------------------------------------ local function makeLanguageLabel(code) local languageName = getLanguageName(code) if not languageName or languageName == "" then return "" end -- The language name is deliberately NOT italicised. return mw.text.tag( "small", {}, "([[" .. languageName .. "|" .. languageName .. "]])" ) end ------------------------------------------------------------ -- Country title ------------------------------------------------------------ function p.title(frame) local args = getArgs(frame) local countryName = getCountryName(args) local officialNames = getOfficialNames() local manxName = nil local otherNames = {} -- Find the Manx official name first. for _, item in ipairs(officialNames) do if item.lang == "gv" then manxName = item.text break end end -- If Wikidata has no Manx P1448, use the short Manx country name. if not manxName then manxName = countryName end local output = {} -- Manx country name. -- Explicitly set the font and weight rather than inheriting -- the styling of the Infobox "above" field. table.insert( output, '<span style="font-family:inherit; font-weight:bold;">' .. manxName .. '</span>' ) -- Other official-language names. -- These must explicitly be normal weight. for _, item in ipairs(officialNames) do if item.lang ~= "gv" then local languageLabel = makeLanguageLabel(item.lang) local line = '<span style="font-weight:normal;">' .. item.text if languageLabel ~= "" then line = line .. " " .. languageLabel end line = line .. "</span>" table.insert(output, line) end end return table.concat(output, "<br>") end ------------------------------------------------------------ -- Images ------------------------------------------------------------ function p.images(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</td>' .. '<td style="width:42%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</td>' .. '</tr></table>', flag, arms, args.lheead_cowrey or "85px" ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</div>', flag ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</div>', arms, args.lheead_cowrey or "85px" ) end ------------------------------------------------------------ -- Captions ------------------------------------------------------------ function p.captions(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end local countryName = getCountryName(args) local genitiveName = getGenitiveName(args) local flagCaption = args["fo-heidyl_brattagh"] or "Brattagh" local armsCaption = args["sorçh_cowrey"] or "Armys" local armsArticle = args["art_sorçh_cowrey"] or "Armys" -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</td>' .. '<td style="width:42%%; text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</td>' .. '</tr></table>', genitiveName, flagCaption, armsArticle, genitiveName, armsCaption ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</div>', genitiveName, flagCaption ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</div>', armsArticle, genitiveName, armsCaption ) end return p 5be67wv11caoaw27n31oeyd15dytuf2 392825 392823 2026-09-06T13:29:50Z MacTire02 219 ++ 392825 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override local function getArgs(frame) return frame:getParent().args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local value = mainsnak.datavalue.value if value and value ~= "" then return value end end end return nil end ------------------------------------------------------------ -- Wikidata item statement ------------------------------------------------------------ local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end ------------------------------------------------------------ -- Wikidata reference URL ------------------------------------------------------------ local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end ------------------------------------------------------------ -- Wikidata locator map ------------------------------------------------------------ local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Locator map data ------------------------------------------------------------ local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end ------------------------------------------------------------ -- Locator map ------------------------------------------------------------ function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end ------------------------------------------------------------ -- Capital / administrative centre data ------------------------------------------------------------ local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end -------------------------------------------------------- -- Manual capital -------------------------------------------------------- if capital then return { text = capital, entity = nil, reference = nil } end -------------------------------------------------------- -- Wikidata P36 = capital -------------------------------------------------------- local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Administrative centre data ------------------------------------------------------------ local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre } end return nil end ------------------------------------------------------------ -- Normalise a city name for comparison ------------------------------------------------------------ local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) -------------------------------------------------------- -- Remove simple wikilink markup -------------------------------------------------------- value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") -------------------------------------------------------- -- If the link has a pipe, retain only the target -------------------------------------------------------- local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end ------------------------------------------------------------ -- Largest city / settlement data ------------------------------------------------------------ local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = normaliseCityName(city) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = city, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Capital / administrative centre labels ------------------------------------------------------------ local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end ------------------------------------------------------------ -- City / settlement data ------------------------------------------------------------ local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end ------------------------------------------------------------ -- Determine whether capital is the largest city ------------------------------------------------------------ local function capitalIsLargest(capital, largest) if not capital or not largest then return false end -------------------------------------------------------- -- Best method: compare Wikidata entity IDs -------------------------------------------------------- if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end -------------------------------------------------------- -- Fallback: compare names -------------------------------------------------------- local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end ------------------------------------------------------------ -- Link city name to its article ------------------------------------------------------------ local function makeCityLink(city) if not city or not city.text then return "" end -------------------------------------------------------- -- If we have the Wikidata entity, use its Manx -- Wikipedia sitelink. -------------------------------------------------------- if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. city.text .. "]]" end end -------------------------------------------------------- -- Fallback: link to the displayed name itself. -------------------------------------------------------- return "[[" .. city.text .. "|" .. city.text .. "]]" end ------------------------------------------------------------ -- Coordinates ------------------------------------------------------------ local function makeCoordinates(entity) if not entity then return nil end -------------------------------------------------------- -- Wikidata P625 = coordinate location -------------------------------------------------------- local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end ------------------------------------------------------------ -- Capital / largest city / administrative centre ------------------------------------------------------------ function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]:" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end return label end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]:" end if largest then return "Balley smoo:" end return nil end function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then return makeCityLink(administrative) elseif largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end return text end return nil end function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} -------------------------------------------------------- -- Capital / administrative centre -------------------------------------------------------- if capital or administrative then local label local text ---------------------------------------------------- -- Capital ---------------------------------------------------- if capital then ------------------------------------------------ -- Link the label to Preeu-valley ------------------------------------------------ label = "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" ------------------------------------------------ -- Link the capital city ------------------------------------------------ text = makeCityLink(capital) ------------------------------------------------ -- Capital is also largest city ------------------------------------------------ if capitalIsLargest(capital, largest) then text = text .. '<br/><small>(as y balley smoo)</small>' end ------------------------------------------------ -- Coordinates directly underneath the city ------------------------------------------------ if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/>' .. coordinates end end ------------------------------------------------ -- Wikidata reference ------------------------------------------------ if capital.reference then text = text .. capital.reference end ---------------------------------------------------- -- Administrative centre only ---------------------------------------------------- else label = "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" text = makeCityLink(administrative) end table.insert( rows, "'''" .. label .. ":&nbsp;'''" .. text ) ---------------------------------------------------- -- Add largest city when different from capital ---------------------------------------------------- if largest and not capitalIsLargest(capital, largest) then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- No capital or administrative centre, -- but largest city exists -------------------------------------------------------- elseif largest then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- Nothing to display -------------------------------------------------------- if #rows == 0 then return nil end return mw.text.listToText( rows, "<br/>", "<br/>" ) end ------------------------------------------------------------ -- Wikidata audio file ------------------------------------------------------------ local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Anthems ------------------------------------------------------------ local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil -- P3831 = object of statement has role. -- This may identify the anthem as national, -- royal, regional, etc. if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { label = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end ------------------------------------------------------------ -- Classify anthems ------------------------------------------------------------ local function classifyAnthems(anthems) local national = {} local royal = {} local other = {} for _, anthem in ipairs(anthems) do local role = anthem.role if role then role = mw.ustring.lower(role) end if role and mw.ustring.find(role, "royal") then table.insert(royal, anthem) elseif role and ( mw.ustring.find(role, "national") or mw.ustring.find(role, "state anthem") ) then table.insert(national, anthem) else table.insert(other, anthem) end end -- If Wikidata has supplied an anthem but has not given -- it a role, treat the first such anthem as the national -- anthem. P85 is normally used for the country's official -- anthem. if #national == 0 and #other > 0 then table.insert(national, other[1]) table.remove(other, 1) end return national, royal, other end ------------------------------------------------------------ -- Anthem data ------------------------------------------------------------ local function getAnthemData(args) local anthems = getAnthems() local national, royal, other = classifyAnthems(anthems) local result = {} -------------------------------------------------------- -- National anthem -------------------------------------------------------- local manualNational = getManual(args, { "arrane_ashoonagh" }) if manualNational then if mw.ustring.lower(manualNational) ~= "none" then result.national = { text = '"' .. manualNational .. '"', reference = getManual(args, { "imraa_arrane_ashoonagh" }), audio = nil } end elseif #national > 0 then result.national = { text = national[1].label, reference = national[1].reference, audio = national[1].audio } end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- local manualRoyal = getManual(args, { "arrane_reeoil" }) if manualRoyal then if mw.ustring.lower(manualRoyal) ~= "none" then result.royal = { text = '"' .. manualRoyal .. '"', reference = getManual(args, { "imraa_arrane_reeoil" }), audio = nil } end elseif #royal > 0 then result.royal = { text = '"' .. royal[1].label .. '"', reference = royal[1].reference, audio = royal[1].audio } end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- local manualOther = getManual(args, { "arrane" }) if manualOther then if mw.ustring.lower(manualOther) ~= "none" then result.other = { text = '"' .. manualOther .. '"', reference = getManual(args, { "imraa_arrane" }), audio = nil } end elseif #other > 0 then result.other = { text = '"' .. other[1].label .. '"', reference = other[1].reference, audio = other[1].audio } end return result end ------------------------------------------------------------ -- Motto ------------------------------------------------------------ local function getMotto() local entity = mw.wikibase.getEntityObject() if not entity then return nil, nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil, nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return value.text, getWikidataReference(statement) end end end return nil, nil end ------------------------------------------------------------ -- Motto data ------------------------------------------------------------ local function getMottoData(args) local manual = getManual(args, { "jarroo-raa_ashoonagh", "jarroo-raa" }) if manual then if mw.ustring.lower(manual) == "none" then return nil end return { text = manual, reference = getManual(args, { "imraa_jarroo-raa" }) } end local text, reference = getMotto() if not text then return nil end return { text = text, reference = reference } end ------------------------------------------------------------ -- Motto and anthem output ------------------------------------------------------------ function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} -------------------------------------------------------- -- Motto -------------------------------------------------------- if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- National anthem -------------------------------------------------------- if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '""' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '""' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end ------------------------------------------------------------ -- Flag ------------------------------------------------------------ local function getFlag(args) -- Manual value takes precedence over Wikidata. local manual = getManual(args, { "jalloo_brattagh" }) if manual then if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P41 = flag image. return getWikidataImage("P41") end ------------------------------------------------------------ -- Coat of arms ------------------------------------------------------------ local function getArms(args) -- Manual value takes precedence over Wikidata. -- jalloo_armys is the preferred new parameter. -- jalloo_cleinney and jalloo_cowrey remain supported -- for compatibility with existing articles. local manual = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if manual then -- Explicitly suppress Wikidata. if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P94 = coat of arms image. return getWikidataImage("P94") end ------------------------------------------------------------ -- Country name ------------------------------------------------------------ local function getCountryName(args) return args.ennym_gienneydagh or args.kianglaghey_ennym or args.ennym or mw.title.getCurrentTitle().text end local function getGenitiveName(args) local name = getCountryName(args) return enmynCheerey.genitive(name) end ------------------------------------------------------------ -- Official name (Wikidata P1448) ------------------------------------------------------------ local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" and value.language and value.language ~= "" then table.insert(names, { text = value.text, lang = mw.ustring.lower(value.language) }) end end end return names end ------------------------------------------------------------ -- Language name ------------------------------------------------------------ local function getLanguageName(code) if not code or code == "" then return code end code = mw.ustring.lower(code) -- Manx Wikipedia language-name override. if langOverrideTable and langOverrideTable[code] then local name = langOverrideTable[code] if type(name) == "table" then return name[1] end return name end -- Standard language-name table. if langNameTable and langNameTable[code] then local name = langNameTable[code] if type(name) == "table" then return name[1] end return name end return code end ------------------------------------------------------------ -- Language label ------------------------------------------------------------ local function makeLanguageLabel(code) local languageName = getLanguageName(code) if not languageName or languageName == "" then return "" end -- The language name is deliberately NOT italicised. return mw.text.tag( "small", {}, "([[" .. languageName .. "|" .. languageName .. "]])" ) end ------------------------------------------------------------ -- Country title ------------------------------------------------------------ function p.title(frame) local args = getArgs(frame) local countryName = getCountryName(args) local officialNames = getOfficialNames() local manxName = nil local otherNames = {} -- Find the Manx official name first. for _, item in ipairs(officialNames) do if item.lang == "gv" then manxName = item.text break end end -- If Wikidata has no Manx P1448, use the short Manx country name. if not manxName then manxName = countryName end local output = {} -- Manx country name. -- Explicitly set the font and weight rather than inheriting -- the styling of the Infobox "above" field. table.insert( output, '<span style="font-family:inherit; font-weight:bold;">' .. manxName .. '</span>' ) -- Other official-language names. -- These must explicitly be normal weight. for _, item in ipairs(officialNames) do if item.lang ~= "gv" then local languageLabel = makeLanguageLabel(item.lang) local line = '<span style="font-weight:normal;">' .. item.text if languageLabel ~= "" then line = line .. " " .. languageLabel end line = line .. "</span>" table.insert(output, line) end end return table.concat(output, "<br>") end ------------------------------------------------------------ -- Images ------------------------------------------------------------ function p.images(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</td>' .. '<td style="width:42%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</td>' .. '</tr></table>', flag, arms, args.lheead_cowrey or "85px" ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</div>', flag ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</div>', arms, args.lheead_cowrey or "85px" ) end ------------------------------------------------------------ -- Captions ------------------------------------------------------------ function p.captions(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end local countryName = getCountryName(args) local genitiveName = getGenitiveName(args) local flagCaption = args["fo-heidyl_brattagh"] or "Brattagh" local armsCaption = args["sorçh_cowrey"] or "Armys" local armsArticle = args["art_sorçh_cowrey"] or "Armys" -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</td>' .. '<td style="width:42%%; text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</td>' .. '</tr></table>', genitiveName, flagCaption, armsArticle, genitiveName, armsCaption ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</div>', genitiveName, flagCaption ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</div>', armsArticle, genitiveName, armsCaption ) end return p golo64xylkq1liywmap2rygk4lay952 392826 392825 2026-09-06T13:31:39Z MacTire02 219 -colon 392826 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override local function getArgs(frame) return frame:getParent().args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local value = mainsnak.datavalue.value if value and value ~= "" then return value end end end return nil end ------------------------------------------------------------ -- Wikidata item statement ------------------------------------------------------------ local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end ------------------------------------------------------------ -- Wikidata reference URL ------------------------------------------------------------ local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end ------------------------------------------------------------ -- Wikidata locator map ------------------------------------------------------------ local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Locator map data ------------------------------------------------------------ local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end ------------------------------------------------------------ -- Locator map ------------------------------------------------------------ function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end ------------------------------------------------------------ -- Capital / administrative centre data ------------------------------------------------------------ local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end -------------------------------------------------------- -- Manual capital -------------------------------------------------------- if capital then return { text = capital, entity = nil, reference = nil } end -------------------------------------------------------- -- Wikidata P36 = capital -------------------------------------------------------- local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Administrative centre data ------------------------------------------------------------ local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre } end return nil end ------------------------------------------------------------ -- Normalise a city name for comparison ------------------------------------------------------------ local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) -------------------------------------------------------- -- Remove simple wikilink markup -------------------------------------------------------- value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") -------------------------------------------------------- -- If the link has a pipe, retain only the target -------------------------------------------------------- local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end ------------------------------------------------------------ -- Largest city / settlement data ------------------------------------------------------------ local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = normaliseCityName(city) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = city, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Capital / administrative centre labels ------------------------------------------------------------ local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end ------------------------------------------------------------ -- City / settlement data ------------------------------------------------------------ local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end ------------------------------------------------------------ -- Determine whether capital is the largest city ------------------------------------------------------------ local function capitalIsLargest(capital, largest) if not capital or not largest then return false end -------------------------------------------------------- -- Best method: compare Wikidata entity IDs -------------------------------------------------------- if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end -------------------------------------------------------- -- Fallback: compare names -------------------------------------------------------- local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end ------------------------------------------------------------ -- Link city name to its article ------------------------------------------------------------ local function makeCityLink(city) if not city or not city.text then return "" end -------------------------------------------------------- -- If we have the Wikidata entity, use its Manx -- Wikipedia sitelink. -------------------------------------------------------- if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. city.text .. "]]" end end -------------------------------------------------------- -- Fallback: link to the displayed name itself. -------------------------------------------------------- return "[[" .. city.text .. "|" .. city.text .. "]]" end ------------------------------------------------------------ -- Coordinates ------------------------------------------------------------ local function makeCoordinates(entity) if not entity then return nil end -------------------------------------------------------- -- Wikidata P625 = coordinate location -------------------------------------------------------- local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end ------------------------------------------------------------ -- Capital / largest city / administrative centre ------------------------------------------------------------ function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end return label end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]:" end if largest then return "Balley smoo:" end return nil end function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then return makeCityLink(administrative) elseif largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end return text end return nil end function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} -------------------------------------------------------- -- Capital / administrative centre -------------------------------------------------------- if capital or administrative then local label local text ---------------------------------------------------- -- Capital ---------------------------------------------------- if capital then ------------------------------------------------ -- Link the label to Preeu-valley ------------------------------------------------ label = "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" ------------------------------------------------ -- Link the capital city ------------------------------------------------ text = makeCityLink(capital) ------------------------------------------------ -- Capital is also largest city ------------------------------------------------ if capitalIsLargest(capital, largest) then text = text .. '<br/><small>(as y balley smoo)</small>' end ------------------------------------------------ -- Coordinates directly underneath the city ------------------------------------------------ if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/>' .. coordinates end end ------------------------------------------------ -- Wikidata reference ------------------------------------------------ if capital.reference then text = text .. capital.reference end ---------------------------------------------------- -- Administrative centre only ---------------------------------------------------- else label = "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" text = makeCityLink(administrative) end table.insert( rows, "'''" .. label .. ":&nbsp;'''" .. text ) ---------------------------------------------------- -- Add largest city when different from capital ---------------------------------------------------- if largest and not capitalIsLargest(capital, largest) then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- No capital or administrative centre, -- but largest city exists -------------------------------------------------------- elseif largest then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- Nothing to display -------------------------------------------------------- if #rows == 0 then return nil end return mw.text.listToText( rows, "<br/>", "<br/>" ) end ------------------------------------------------------------ -- Wikidata audio file ------------------------------------------------------------ local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Anthems ------------------------------------------------------------ local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil -- P3831 = object of statement has role. -- This may identify the anthem as national, -- royal, regional, etc. if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { label = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end ------------------------------------------------------------ -- Classify anthems ------------------------------------------------------------ local function classifyAnthems(anthems) local national = {} local royal = {} local other = {} for _, anthem in ipairs(anthems) do local role = anthem.role if role then role = mw.ustring.lower(role) end if role and mw.ustring.find(role, "royal") then table.insert(royal, anthem) elseif role and ( mw.ustring.find(role, "national") or mw.ustring.find(role, "state anthem") ) then table.insert(national, anthem) else table.insert(other, anthem) end end -- If Wikidata has supplied an anthem but has not given -- it a role, treat the first such anthem as the national -- anthem. P85 is normally used for the country's official -- anthem. if #national == 0 and #other > 0 then table.insert(national, other[1]) table.remove(other, 1) end return national, royal, other end ------------------------------------------------------------ -- Anthem data ------------------------------------------------------------ local function getAnthemData(args) local anthems = getAnthems() local national, royal, other = classifyAnthems(anthems) local result = {} -------------------------------------------------------- -- National anthem -------------------------------------------------------- local manualNational = getManual(args, { "arrane_ashoonagh" }) if manualNational then if mw.ustring.lower(manualNational) ~= "none" then result.national = { text = '"' .. manualNational .. '"', reference = getManual(args, { "imraa_arrane_ashoonagh" }), audio = nil } end elseif #national > 0 then result.national = { text = national[1].label, reference = national[1].reference, audio = national[1].audio } end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- local manualRoyal = getManual(args, { "arrane_reeoil" }) if manualRoyal then if mw.ustring.lower(manualRoyal) ~= "none" then result.royal = { text = '"' .. manualRoyal .. '"', reference = getManual(args, { "imraa_arrane_reeoil" }), audio = nil } end elseif #royal > 0 then result.royal = { text = '"' .. royal[1].label .. '"', reference = royal[1].reference, audio = royal[1].audio } end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- local manualOther = getManual(args, { "arrane" }) if manualOther then if mw.ustring.lower(manualOther) ~= "none" then result.other = { text = '"' .. manualOther .. '"', reference = getManual(args, { "imraa_arrane" }), audio = nil } end elseif #other > 0 then result.other = { text = '"' .. other[1].label .. '"', reference = other[1].reference, audio = other[1].audio } end return result end ------------------------------------------------------------ -- Motto ------------------------------------------------------------ local function getMotto() local entity = mw.wikibase.getEntityObject() if not entity then return nil, nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil, nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return value.text, getWikidataReference(statement) end end end return nil, nil end ------------------------------------------------------------ -- Motto data ------------------------------------------------------------ local function getMottoData(args) local manual = getManual(args, { "jarroo-raa_ashoonagh", "jarroo-raa" }) if manual then if mw.ustring.lower(manual) == "none" then return nil end return { text = manual, reference = getManual(args, { "imraa_jarroo-raa" }) } end local text, reference = getMotto() if not text then return nil end return { text = text, reference = reference } end ------------------------------------------------------------ -- Motto and anthem output ------------------------------------------------------------ function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} -------------------------------------------------------- -- Motto -------------------------------------------------------- if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- National anthem -------------------------------------------------------- if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '""' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '""' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end ------------------------------------------------------------ -- Flag ------------------------------------------------------------ local function getFlag(args) -- Manual value takes precedence over Wikidata. local manual = getManual(args, { "jalloo_brattagh" }) if manual then if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P41 = flag image. return getWikidataImage("P41") end ------------------------------------------------------------ -- Coat of arms ------------------------------------------------------------ local function getArms(args) -- Manual value takes precedence over Wikidata. -- jalloo_armys is the preferred new parameter. -- jalloo_cleinney and jalloo_cowrey remain supported -- for compatibility with existing articles. local manual = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if manual then -- Explicitly suppress Wikidata. if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P94 = coat of arms image. return getWikidataImage("P94") end ------------------------------------------------------------ -- Country name ------------------------------------------------------------ local function getCountryName(args) return args.ennym_gienneydagh or args.kianglaghey_ennym or args.ennym or mw.title.getCurrentTitle().text end local function getGenitiveName(args) local name = getCountryName(args) return enmynCheerey.genitive(name) end ------------------------------------------------------------ -- Official name (Wikidata P1448) ------------------------------------------------------------ local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" and value.language and value.language ~= "" then table.insert(names, { text = value.text, lang = mw.ustring.lower(value.language) }) end end end return names end ------------------------------------------------------------ -- Language name ------------------------------------------------------------ local function getLanguageName(code) if not code or code == "" then return code end code = mw.ustring.lower(code) -- Manx Wikipedia language-name override. if langOverrideTable and langOverrideTable[code] then local name = langOverrideTable[code] if type(name) == "table" then return name[1] end return name end -- Standard language-name table. if langNameTable and langNameTable[code] then local name = langNameTable[code] if type(name) == "table" then return name[1] end return name end return code end ------------------------------------------------------------ -- Language label ------------------------------------------------------------ local function makeLanguageLabel(code) local languageName = getLanguageName(code) if not languageName or languageName == "" then return "" end -- The language name is deliberately NOT italicised. return mw.text.tag( "small", {}, "([[" .. languageName .. "|" .. languageName .. "]])" ) end ------------------------------------------------------------ -- Country title ------------------------------------------------------------ function p.title(frame) local args = getArgs(frame) local countryName = getCountryName(args) local officialNames = getOfficialNames() local manxName = nil local otherNames = {} -- Find the Manx official name first. for _, item in ipairs(officialNames) do if item.lang == "gv" then manxName = item.text break end end -- If Wikidata has no Manx P1448, use the short Manx country name. if not manxName then manxName = countryName end local output = {} -- Manx country name. -- Explicitly set the font and weight rather than inheriting -- the styling of the Infobox "above" field. table.insert( output, '<span style="font-family:inherit; font-weight:bold;">' .. manxName .. '</span>' ) -- Other official-language names. -- These must explicitly be normal weight. for _, item in ipairs(officialNames) do if item.lang ~= "gv" then local languageLabel = makeLanguageLabel(item.lang) local line = '<span style="font-weight:normal;">' .. item.text if languageLabel ~= "" then line = line .. " " .. languageLabel end line = line .. "</span>" table.insert(output, line) end end return table.concat(output, "<br>") end ------------------------------------------------------------ -- Images ------------------------------------------------------------ function p.images(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</td>' .. '<td style="width:42%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</td>' .. '</tr></table>', flag, arms, args.lheead_cowrey or "85px" ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</div>', flag ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</div>', arms, args.lheead_cowrey or "85px" ) end ------------------------------------------------------------ -- Captions ------------------------------------------------------------ function p.captions(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end local countryName = getCountryName(args) local genitiveName = getGenitiveName(args) local flagCaption = args["fo-heidyl_brattagh"] or "Brattagh" local armsCaption = args["sorçh_cowrey"] or "Armys" local armsArticle = args["art_sorçh_cowrey"] or "Armys" -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</td>' .. '<td style="width:42%%; text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</td>' .. '</tr></table>', genitiveName, flagCaption, armsArticle, genitiveName, armsCaption ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</div>', genitiveName, flagCaption ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</div>', armsArticle, genitiveName, armsCaption ) end return p 33hjwuyxshv42qsbb2zmorvfe52pr6c 392827 392826 2026-09-06T13:35:02Z MacTire02 219 -- 392827 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override local function getArgs(frame) return frame:getParent().args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local value = mainsnak.datavalue.value if value and value ~= "" then return value end end end return nil end ------------------------------------------------------------ -- Wikidata item statement ------------------------------------------------------------ local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end ------------------------------------------------------------ -- Wikidata reference URL ------------------------------------------------------------ local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end ------------------------------------------------------------ -- Wikidata locator map ------------------------------------------------------------ local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Locator map data ------------------------------------------------------------ local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end ------------------------------------------------------------ -- Locator map ------------------------------------------------------------ function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end ------------------------------------------------------------ -- Capital / administrative centre data ------------------------------------------------------------ local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end -------------------------------------------------------- -- Manual capital -------------------------------------------------------- if capital then return { text = capital, entity = nil, reference = nil } end -------------------------------------------------------- -- Wikidata P36 = capital -------------------------------------------------------- local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Administrative centre data ------------------------------------------------------------ local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre } end return nil end ------------------------------------------------------------ -- Normalise a city name for comparison ------------------------------------------------------------ local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) -------------------------------------------------------- -- Remove simple wikilink markup -------------------------------------------------------- value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") -------------------------------------------------------- -- If the link has a pipe, retain only the target -------------------------------------------------------- local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end ------------------------------------------------------------ -- Largest city / settlement data ------------------------------------------------------------ local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = normaliseCityName(city) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = city, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Capital / administrative centre labels ------------------------------------------------------------ local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end ------------------------------------------------------------ -- City / settlement data ------------------------------------------------------------ local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end ------------------------------------------------------------ -- Determine whether capital is the largest city ------------------------------------------------------------ local function capitalIsLargest(capital, largest) if not capital or not largest then return false end -------------------------------------------------------- -- Best method: compare Wikidata entity IDs -------------------------------------------------------- if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end -------------------------------------------------------- -- Fallback: compare names -------------------------------------------------------- local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end ------------------------------------------------------------ -- Link city name to its article ------------------------------------------------------------ local function makeCityLink(city) if not city or not city.text then return "" end -------------------------------------------------------- -- If we have the Wikidata entity, use its Manx -- Wikipedia sitelink. -------------------------------------------------------- if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. city.text .. "]]" end end -------------------------------------------------------- -- Fallback: link to the displayed name itself. -------------------------------------------------------- return "[[" .. city.text .. "|" .. city.text .. "]]" end ------------------------------------------------------------ -- Coordinates ------------------------------------------------------------ local function makeCoordinates(entity) if not entity then return nil end -------------------------------------------------------- -- Wikidata P625 = coordinate location -------------------------------------------------------- local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end ------------------------------------------------------------ -- Capital / largest city / administrative centre ------------------------------------------------------------ function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">(as y balley smoo)</small>' end return label end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then return makeCityLink(administrative) elseif largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end return text end return nil end function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} -------------------------------------------------------- -- Capital / administrative centre -------------------------------------------------------- if capital or administrative then local label local text ---------------------------------------------------- -- Capital ---------------------------------------------------- if capital then ------------------------------------------------ -- Link the label to Preeu-valley ------------------------------------------------ label = "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" ------------------------------------------------ -- Link the capital city ------------------------------------------------ text = makeCityLink(capital) ------------------------------------------------ -- Capital is also largest city ------------------------------------------------ if capitalIsLargest(capital, largest) then text = text .. '<br/><small>(as y balley smoo)</small>' end ------------------------------------------------ -- Coordinates directly underneath the city ------------------------------------------------ if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/>' .. coordinates end end ------------------------------------------------ -- Wikidata reference ------------------------------------------------ if capital.reference then text = text .. capital.reference end ---------------------------------------------------- -- Administrative centre only ---------------------------------------------------- else label = "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" text = makeCityLink(administrative) end table.insert( rows, "'''" .. label .. ":&nbsp;'''" .. text ) ---------------------------------------------------- -- Add largest city when different from capital ---------------------------------------------------- if largest and not capitalIsLargest(capital, largest) then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- No capital or administrative centre, -- but largest city exists -------------------------------------------------------- elseif largest then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- Nothing to display -------------------------------------------------------- if #rows == 0 then return nil end return mw.text.listToText( rows, "<br/>", "<br/>" ) end ------------------------------------------------------------ -- Wikidata audio file ------------------------------------------------------------ local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Anthems ------------------------------------------------------------ local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil -- P3831 = object of statement has role. -- This may identify the anthem as national, -- royal, regional, etc. if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { label = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end ------------------------------------------------------------ -- Classify anthems ------------------------------------------------------------ local function classifyAnthems(anthems) local national = {} local royal = {} local other = {} for _, anthem in ipairs(anthems) do local role = anthem.role if role then role = mw.ustring.lower(role) end if role and mw.ustring.find(role, "royal") then table.insert(royal, anthem) elseif role and ( mw.ustring.find(role, "national") or mw.ustring.find(role, "state anthem") ) then table.insert(national, anthem) else table.insert(other, anthem) end end -- If Wikidata has supplied an anthem but has not given -- it a role, treat the first such anthem as the national -- anthem. P85 is normally used for the country's official -- anthem. if #national == 0 and #other > 0 then table.insert(national, other[1]) table.remove(other, 1) end return national, royal, other end ------------------------------------------------------------ -- Anthem data ------------------------------------------------------------ local function getAnthemData(args) local anthems = getAnthems() local national, royal, other = classifyAnthems(anthems) local result = {} -------------------------------------------------------- -- National anthem -------------------------------------------------------- local manualNational = getManual(args, { "arrane_ashoonagh" }) if manualNational then if mw.ustring.lower(manualNational) ~= "none" then result.national = { text = '"' .. manualNational .. '"', reference = getManual(args, { "imraa_arrane_ashoonagh" }), audio = nil } end elseif #national > 0 then result.national = { text = national[1].label, reference = national[1].reference, audio = national[1].audio } end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- local manualRoyal = getManual(args, { "arrane_reeoil" }) if manualRoyal then if mw.ustring.lower(manualRoyal) ~= "none" then result.royal = { text = '"' .. manualRoyal .. '"', reference = getManual(args, { "imraa_arrane_reeoil" }), audio = nil } end elseif #royal > 0 then result.royal = { text = '"' .. royal[1].label .. '"', reference = royal[1].reference, audio = royal[1].audio } end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- local manualOther = getManual(args, { "arrane" }) if manualOther then if mw.ustring.lower(manualOther) ~= "none" then result.other = { text = '"' .. manualOther .. '"', reference = getManual(args, { "imraa_arrane" }), audio = nil } end elseif #other > 0 then result.other = { text = '"' .. other[1].label .. '"', reference = other[1].reference, audio = other[1].audio } end return result end ------------------------------------------------------------ -- Motto ------------------------------------------------------------ local function getMotto() local entity = mw.wikibase.getEntityObject() if not entity then return nil, nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil, nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return value.text, getWikidataReference(statement) end end end return nil, nil end ------------------------------------------------------------ -- Motto data ------------------------------------------------------------ local function getMottoData(args) local manual = getManual(args, { "jarroo-raa_ashoonagh", "jarroo-raa" }) if manual then if mw.ustring.lower(manual) == "none" then return nil end return { text = manual, reference = getManual(args, { "imraa_jarroo-raa" }) } end local text, reference = getMotto() if not text then return nil end return { text = text, reference = reference } end ------------------------------------------------------------ -- Motto and anthem output ------------------------------------------------------------ function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} -------------------------------------------------------- -- Motto -------------------------------------------------------- if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- National anthem -------------------------------------------------------- if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '""' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '""' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end ------------------------------------------------------------ -- Flag ------------------------------------------------------------ local function getFlag(args) -- Manual value takes precedence over Wikidata. local manual = getManual(args, { "jalloo_brattagh" }) if manual then if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P41 = flag image. return getWikidataImage("P41") end ------------------------------------------------------------ -- Coat of arms ------------------------------------------------------------ local function getArms(args) -- Manual value takes precedence over Wikidata. -- jalloo_armys is the preferred new parameter. -- jalloo_cleinney and jalloo_cowrey remain supported -- for compatibility with existing articles. local manual = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if manual then -- Explicitly suppress Wikidata. if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P94 = coat of arms image. return getWikidataImage("P94") end ------------------------------------------------------------ -- Country name ------------------------------------------------------------ local function getCountryName(args) return args.ennym_gienneydagh or args.kianglaghey_ennym or args.ennym or mw.title.getCurrentTitle().text end local function getGenitiveName(args) local name = getCountryName(args) return enmynCheerey.genitive(name) end ------------------------------------------------------------ -- Official name (Wikidata P1448) ------------------------------------------------------------ local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" and value.language and value.language ~= "" then table.insert(names, { text = value.text, lang = mw.ustring.lower(value.language) }) end end end return names end ------------------------------------------------------------ -- Language name ------------------------------------------------------------ local function getLanguageName(code) if not code or code == "" then return code end code = mw.ustring.lower(code) -- Manx Wikipedia language-name override. if langOverrideTable and langOverrideTable[code] then local name = langOverrideTable[code] if type(name) == "table" then return name[1] end return name end -- Standard language-name table. if langNameTable and langNameTable[code] then local name = langNameTable[code] if type(name) == "table" then return name[1] end return name end return code end ------------------------------------------------------------ -- Language label ------------------------------------------------------------ local function makeLanguageLabel(code) local languageName = getLanguageName(code) if not languageName or languageName == "" then return "" end -- The language name is deliberately NOT italicised. return mw.text.tag( "small", {}, "([[" .. languageName .. "|" .. languageName .. "]])" ) end ------------------------------------------------------------ -- Country title ------------------------------------------------------------ function p.title(frame) local args = getArgs(frame) local countryName = getCountryName(args) local officialNames = getOfficialNames() local manxName = nil local otherNames = {} -- Find the Manx official name first. for _, item in ipairs(officialNames) do if item.lang == "gv" then manxName = item.text break end end -- If Wikidata has no Manx P1448, use the short Manx country name. if not manxName then manxName = countryName end local output = {} -- Manx country name. -- Explicitly set the font and weight rather than inheriting -- the styling of the Infobox "above" field. table.insert( output, '<span style="font-family:inherit; font-weight:bold;">' .. manxName .. '</span>' ) -- Other official-language names. -- These must explicitly be normal weight. for _, item in ipairs(officialNames) do if item.lang ~= "gv" then local languageLabel = makeLanguageLabel(item.lang) local line = '<span style="font-weight:normal;">' .. item.text if languageLabel ~= "" then line = line .. " " .. languageLabel end line = line .. "</span>" table.insert(output, line) end end return table.concat(output, "<br>") end ------------------------------------------------------------ -- Images ------------------------------------------------------------ function p.images(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</td>' .. '<td style="width:42%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</td>' .. '</tr></table>', flag, arms, args.lheead_cowrey or "85px" ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</div>', flag ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</div>', arms, args.lheead_cowrey or "85px" ) end ------------------------------------------------------------ -- Captions ------------------------------------------------------------ function p.captions(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end local countryName = getCountryName(args) local genitiveName = getGenitiveName(args) local flagCaption = args["fo-heidyl_brattagh"] or "Brattagh" local armsCaption = args["sorçh_cowrey"] or "Armys" local armsArticle = args["art_sorçh_cowrey"] or "Armys" -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</td>' .. '<td style="width:42%%; text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</td>' .. '</tr></table>', genitiveName, flagCaption, armsArticle, genitiveName, armsCaption ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</div>', genitiveName, flagCaption ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</div>', armsArticle, genitiveName, armsCaption ) end return p g4pfu8uvzrq2b2u57zvn3ff36e84cag 392828 392827 2026-09-06T13:36:48Z MacTire02 219 soiaghey yn teks 392828 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override local function getArgs(frame) return frame:getParent().args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local value = mainsnak.datavalue.value if value and value ~= "" then return value end end end return nil end ------------------------------------------------------------ -- Wikidata item statement ------------------------------------------------------------ local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end ------------------------------------------------------------ -- Wikidata reference URL ------------------------------------------------------------ local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end ------------------------------------------------------------ -- Wikidata locator map ------------------------------------------------------------ local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Locator map data ------------------------------------------------------------ local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end ------------------------------------------------------------ -- Locator map ------------------------------------------------------------ function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end ------------------------------------------------------------ -- Capital / administrative centre data ------------------------------------------------------------ local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end -------------------------------------------------------- -- Manual capital -------------------------------------------------------- if capital then return { text = capital, entity = nil, reference = nil } end -------------------------------------------------------- -- Wikidata P36 = capital -------------------------------------------------------- local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Administrative centre data ------------------------------------------------------------ local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre } end return nil end ------------------------------------------------------------ -- Normalise a city name for comparison ------------------------------------------------------------ local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) -------------------------------------------------------- -- Remove simple wikilink markup -------------------------------------------------------- value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") -------------------------------------------------------- -- If the link has a pipe, retain only the target -------------------------------------------------------- local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end ------------------------------------------------------------ -- Largest city / settlement data ------------------------------------------------------------ local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = normaliseCityName(city) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = city, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Capital / administrative centre labels ------------------------------------------------------------ local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end ------------------------------------------------------------ -- City / settlement data ------------------------------------------------------------ local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end ------------------------------------------------------------ -- Determine whether capital is the largest city ------------------------------------------------------------ local function capitalIsLargest(capital, largest) if not capital or not largest then return false end -------------------------------------------------------- -- Best method: compare Wikidata entity IDs -------------------------------------------------------- if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end -------------------------------------------------------- -- Fallback: compare names -------------------------------------------------------- local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end ------------------------------------------------------------ -- Link city name to its article ------------------------------------------------------------ local function makeCityLink(city) if not city or not city.text then return "" end -------------------------------------------------------- -- If we have the Wikidata entity, use its Manx -- Wikipedia sitelink. -------------------------------------------------------- if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. city.text .. "]]" end end -------------------------------------------------------- -- Fallback: link to the displayed name itself. -------------------------------------------------------- return "[[" .. city.text .. "|" .. city.text .. "]]" end ------------------------------------------------------------ -- Coordinates ------------------------------------------------------------ local function makeCoordinates(entity) if not entity then return nil end -------------------------------------------------------- -- Wikidata P625 = coordinate location -------------------------------------------------------- local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end ------------------------------------------------------------ -- Capital / largest city / administrative centre ------------------------------------------------------------ function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal; display:inline-block; margin-left:0;">(as y balley smoo)</small>' end return label end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then return makeCityLink(administrative) elseif largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end return text end return nil end function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} -------------------------------------------------------- -- Capital / administrative centre -------------------------------------------------------- if capital or administrative then local label local text ---------------------------------------------------- -- Capital ---------------------------------------------------- if capital then ------------------------------------------------ -- Link the label to Preeu-valley ------------------------------------------------ label = "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" ------------------------------------------------ -- Link the capital city ------------------------------------------------ text = makeCityLink(capital) ------------------------------------------------ -- Capital is also largest city ------------------------------------------------ if capitalIsLargest(capital, largest) then text = text .. '<br/><small>(as y balley smoo)</small>' end ------------------------------------------------ -- Coordinates directly underneath the city ------------------------------------------------ if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/>' .. coordinates end end ------------------------------------------------ -- Wikidata reference ------------------------------------------------ if capital.reference then text = text .. capital.reference end ---------------------------------------------------- -- Administrative centre only ---------------------------------------------------- else label = "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" text = makeCityLink(administrative) end table.insert( rows, "'''" .. label .. ":&nbsp;'''" .. text ) ---------------------------------------------------- -- Add largest city when different from capital ---------------------------------------------------- if largest and not capitalIsLargest(capital, largest) then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- No capital or administrative centre, -- but largest city exists -------------------------------------------------------- elseif largest then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- Nothing to display -------------------------------------------------------- if #rows == 0 then return nil end return mw.text.listToText( rows, "<br/>", "<br/>" ) end ------------------------------------------------------------ -- Wikidata audio file ------------------------------------------------------------ local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Anthems ------------------------------------------------------------ local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil -- P3831 = object of statement has role. -- This may identify the anthem as national, -- royal, regional, etc. if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { label = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end ------------------------------------------------------------ -- Classify anthems ------------------------------------------------------------ local function classifyAnthems(anthems) local national = {} local royal = {} local other = {} for _, anthem in ipairs(anthems) do local role = anthem.role if role then role = mw.ustring.lower(role) end if role and mw.ustring.find(role, "royal") then table.insert(royal, anthem) elseif role and ( mw.ustring.find(role, "national") or mw.ustring.find(role, "state anthem") ) then table.insert(national, anthem) else table.insert(other, anthem) end end -- If Wikidata has supplied an anthem but has not given -- it a role, treat the first such anthem as the national -- anthem. P85 is normally used for the country's official -- anthem. if #national == 0 and #other > 0 then table.insert(national, other[1]) table.remove(other, 1) end return national, royal, other end ------------------------------------------------------------ -- Anthem data ------------------------------------------------------------ local function getAnthemData(args) local anthems = getAnthems() local national, royal, other = classifyAnthems(anthems) local result = {} -------------------------------------------------------- -- National anthem -------------------------------------------------------- local manualNational = getManual(args, { "arrane_ashoonagh" }) if manualNational then if mw.ustring.lower(manualNational) ~= "none" then result.national = { text = '"' .. manualNational .. '"', reference = getManual(args, { "imraa_arrane_ashoonagh" }), audio = nil } end elseif #national > 0 then result.national = { text = national[1].label, reference = national[1].reference, audio = national[1].audio } end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- local manualRoyal = getManual(args, { "arrane_reeoil" }) if manualRoyal then if mw.ustring.lower(manualRoyal) ~= "none" then result.royal = { text = '"' .. manualRoyal .. '"', reference = getManual(args, { "imraa_arrane_reeoil" }), audio = nil } end elseif #royal > 0 then result.royal = { text = '"' .. royal[1].label .. '"', reference = royal[1].reference, audio = royal[1].audio } end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- local manualOther = getManual(args, { "arrane" }) if manualOther then if mw.ustring.lower(manualOther) ~= "none" then result.other = { text = '"' .. manualOther .. '"', reference = getManual(args, { "imraa_arrane" }), audio = nil } end elseif #other > 0 then result.other = { text = '"' .. other[1].label .. '"', reference = other[1].reference, audio = other[1].audio } end return result end ------------------------------------------------------------ -- Motto ------------------------------------------------------------ local function getMotto() local entity = mw.wikibase.getEntityObject() if not entity then return nil, nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil, nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return value.text, getWikidataReference(statement) end end end return nil, nil end ------------------------------------------------------------ -- Motto data ------------------------------------------------------------ local function getMottoData(args) local manual = getManual(args, { "jarroo-raa_ashoonagh", "jarroo-raa" }) if manual then if mw.ustring.lower(manual) == "none" then return nil end return { text = manual, reference = getManual(args, { "imraa_jarroo-raa" }) } end local text, reference = getMotto() if not text then return nil end return { text = text, reference = reference } end ------------------------------------------------------------ -- Motto and anthem output ------------------------------------------------------------ function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} -------------------------------------------------------- -- Motto -------------------------------------------------------- if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- National anthem -------------------------------------------------------- if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '""' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '""' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end ------------------------------------------------------------ -- Flag ------------------------------------------------------------ local function getFlag(args) -- Manual value takes precedence over Wikidata. local manual = getManual(args, { "jalloo_brattagh" }) if manual then if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P41 = flag image. return getWikidataImage("P41") end ------------------------------------------------------------ -- Coat of arms ------------------------------------------------------------ local function getArms(args) -- Manual value takes precedence over Wikidata. -- jalloo_armys is the preferred new parameter. -- jalloo_cleinney and jalloo_cowrey remain supported -- for compatibility with existing articles. local manual = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if manual then -- Explicitly suppress Wikidata. if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P94 = coat of arms image. return getWikidataImage("P94") end ------------------------------------------------------------ -- Country name ------------------------------------------------------------ local function getCountryName(args) return args.ennym_gienneydagh or args.kianglaghey_ennym or args.ennym or mw.title.getCurrentTitle().text end local function getGenitiveName(args) local name = getCountryName(args) return enmynCheerey.genitive(name) end ------------------------------------------------------------ -- Official name (Wikidata P1448) ------------------------------------------------------------ local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" and value.language and value.language ~= "" then table.insert(names, { text = value.text, lang = mw.ustring.lower(value.language) }) end end end return names end ------------------------------------------------------------ -- Language name ------------------------------------------------------------ local function getLanguageName(code) if not code or code == "" then return code end code = mw.ustring.lower(code) -- Manx Wikipedia language-name override. if langOverrideTable and langOverrideTable[code] then local name = langOverrideTable[code] if type(name) == "table" then return name[1] end return name end -- Standard language-name table. if langNameTable and langNameTable[code] then local name = langNameTable[code] if type(name) == "table" then return name[1] end return name end return code end ------------------------------------------------------------ -- Language label ------------------------------------------------------------ local function makeLanguageLabel(code) local languageName = getLanguageName(code) if not languageName or languageName == "" then return "" end -- The language name is deliberately NOT italicised. return mw.text.tag( "small", {}, "([[" .. languageName .. "|" .. languageName .. "]])" ) end ------------------------------------------------------------ -- Country title ------------------------------------------------------------ function p.title(frame) local args = getArgs(frame) local countryName = getCountryName(args) local officialNames = getOfficialNames() local manxName = nil local otherNames = {} -- Find the Manx official name first. for _, item in ipairs(officialNames) do if item.lang == "gv" then manxName = item.text break end end -- If Wikidata has no Manx P1448, use the short Manx country name. if not manxName then manxName = countryName end local output = {} -- Manx country name. -- Explicitly set the font and weight rather than inheriting -- the styling of the Infobox "above" field. table.insert( output, '<span style="font-family:inherit; font-weight:bold;">' .. manxName .. '</span>' ) -- Other official-language names. -- These must explicitly be normal weight. for _, item in ipairs(officialNames) do if item.lang ~= "gv" then local languageLabel = makeLanguageLabel(item.lang) local line = '<span style="font-weight:normal;">' .. item.text if languageLabel ~= "" then line = line .. " " .. languageLabel end line = line .. "</span>" table.insert(output, line) end end return table.concat(output, "<br>") end ------------------------------------------------------------ -- Images ------------------------------------------------------------ function p.images(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</td>' .. '<td style="width:42%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</td>' .. '</tr></table>', flag, arms, args.lheead_cowrey or "85px" ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</div>', flag ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</div>', arms, args.lheead_cowrey or "85px" ) end ------------------------------------------------------------ -- Captions ------------------------------------------------------------ function p.captions(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end local countryName = getCountryName(args) local genitiveName = getGenitiveName(args) local flagCaption = args["fo-heidyl_brattagh"] or "Brattagh" local armsCaption = args["sorçh_cowrey"] or "Armys" local armsArticle = args["art_sorçh_cowrey"] or "Armys" -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</td>' .. '<td style="width:42%%; text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</td>' .. '</tr></table>', genitiveName, flagCaption, armsArticle, genitiveName, armsCaption ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</div>', genitiveName, flagCaption ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</div>', armsArticle, genitiveName, armsCaption ) end return p byb5zbuil2npeep5yz1i5ukzp7qwsbf 392830 392828 2026-09-06T13:38:34Z MacTire02 219 ++ 392830 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override local function getArgs(frame) return frame:getParent().args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local value = mainsnak.datavalue.value if value and value ~= "" then return value end end end return nil end ------------------------------------------------------------ -- Wikidata item statement ------------------------------------------------------------ local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end ------------------------------------------------------------ -- Wikidata reference URL ------------------------------------------------------------ local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end ------------------------------------------------------------ -- Wikidata locator map ------------------------------------------------------------ local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Locator map data ------------------------------------------------------------ local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end ------------------------------------------------------------ -- Locator map ------------------------------------------------------------ function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end ------------------------------------------------------------ -- Capital / administrative centre data ------------------------------------------------------------ local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end -------------------------------------------------------- -- Manual capital -------------------------------------------------------- if capital then return { text = capital, entity = nil, reference = nil } end -------------------------------------------------------- -- Wikidata P36 = capital -------------------------------------------------------- local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Administrative centre data ------------------------------------------------------------ local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre } end return nil end ------------------------------------------------------------ -- Normalise a city name for comparison ------------------------------------------------------------ local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) -------------------------------------------------------- -- Remove simple wikilink markup -------------------------------------------------------- value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") -------------------------------------------------------- -- If the link has a pipe, retain only the target -------------------------------------------------------- local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end ------------------------------------------------------------ -- Largest city / settlement data ------------------------------------------------------------ local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = normaliseCityName(city) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = city, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Capital / administrative centre labels ------------------------------------------------------------ local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end ------------------------------------------------------------ -- City / settlement data ------------------------------------------------------------ local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end ------------------------------------------------------------ -- Determine whether capital is the largest city ------------------------------------------------------------ local function capitalIsLargest(capital, largest) if not capital or not largest then return false end -------------------------------------------------------- -- Best method: compare Wikidata entity IDs -------------------------------------------------------- if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end -------------------------------------------------------- -- Fallback: compare names -------------------------------------------------------- local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end ------------------------------------------------------------ -- Link city name to its article ------------------------------------------------------------ local function makeCityLink(city) if not city or not city.text then return "" end -------------------------------------------------------- -- If we have the Wikidata entity, use its Manx -- Wikipedia sitelink. -------------------------------------------------------- if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. city.text .. "]]" end end -------------------------------------------------------- -- Fallback: link to the displayed name itself. -------------------------------------------------------- return "[[" .. city.text .. "|" .. city.text .. "]]" end ------------------------------------------------------------ -- Coordinates ------------------------------------------------------------ local function makeCoordinates(entity) if not entity then return nil end -------------------------------------------------------- -- Wikidata P625 = coordinate location -------------------------------------------------------- local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end ------------------------------------------------------------ -- Capital / largest city / administrative centre ------------------------------------------------------------ function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = '<div style="text-align:left;">' .. "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end label = label .. '</div>' return label end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then return makeCityLink(administrative) elseif largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end return text end return nil end function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} -------------------------------------------------------- -- Capital / administrative centre -------------------------------------------------------- if capital or administrative then local label local text ---------------------------------------------------- -- Capital ---------------------------------------------------- if capital then ------------------------------------------------ -- Link the label to Preeu-valley ------------------------------------------------ label = "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" ------------------------------------------------ -- Link the capital city ------------------------------------------------ text = makeCityLink(capital) ------------------------------------------------ -- Capital is also largest city ------------------------------------------------ if capitalIsLargest(capital, largest) then text = text .. '<br/><small>(as y balley smoo)</small>' end ------------------------------------------------ -- Coordinates directly underneath the city ------------------------------------------------ if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/>' .. coordinates end end ------------------------------------------------ -- Wikidata reference ------------------------------------------------ if capital.reference then text = text .. capital.reference end ---------------------------------------------------- -- Administrative centre only ---------------------------------------------------- else label = "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" text = makeCityLink(administrative) end table.insert( rows, "'''" .. label .. ":&nbsp;'''" .. text ) ---------------------------------------------------- -- Add largest city when different from capital ---------------------------------------------------- if largest and not capitalIsLargest(capital, largest) then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- No capital or administrative centre, -- but largest city exists -------------------------------------------------------- elseif largest then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- Nothing to display -------------------------------------------------------- if #rows == 0 then return nil end return mw.text.listToText( rows, "<br/>", "<br/>" ) end ------------------------------------------------------------ -- Wikidata audio file ------------------------------------------------------------ local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Anthems ------------------------------------------------------------ local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil -- P3831 = object of statement has role. -- This may identify the anthem as national, -- royal, regional, etc. if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { label = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end ------------------------------------------------------------ -- Classify anthems ------------------------------------------------------------ local function classifyAnthems(anthems) local national = {} local royal = {} local other = {} for _, anthem in ipairs(anthems) do local role = anthem.role if role then role = mw.ustring.lower(role) end if role and mw.ustring.find(role, "royal") then table.insert(royal, anthem) elseif role and ( mw.ustring.find(role, "national") or mw.ustring.find(role, "state anthem") ) then table.insert(national, anthem) else table.insert(other, anthem) end end -- If Wikidata has supplied an anthem but has not given -- it a role, treat the first such anthem as the national -- anthem. P85 is normally used for the country's official -- anthem. if #national == 0 and #other > 0 then table.insert(national, other[1]) table.remove(other, 1) end return national, royal, other end ------------------------------------------------------------ -- Anthem data ------------------------------------------------------------ local function getAnthemData(args) local anthems = getAnthems() local national, royal, other = classifyAnthems(anthems) local result = {} -------------------------------------------------------- -- National anthem -------------------------------------------------------- local manualNational = getManual(args, { "arrane_ashoonagh" }) if manualNational then if mw.ustring.lower(manualNational) ~= "none" then result.national = { text = '"' .. manualNational .. '"', reference = getManual(args, { "imraa_arrane_ashoonagh" }), audio = nil } end elseif #national > 0 then result.national = { text = national[1].label, reference = national[1].reference, audio = national[1].audio } end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- local manualRoyal = getManual(args, { "arrane_reeoil" }) if manualRoyal then if mw.ustring.lower(manualRoyal) ~= "none" then result.royal = { text = '"' .. manualRoyal .. '"', reference = getManual(args, { "imraa_arrane_reeoil" }), audio = nil } end elseif #royal > 0 then result.royal = { text = '"' .. royal[1].label .. '"', reference = royal[1].reference, audio = royal[1].audio } end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- local manualOther = getManual(args, { "arrane" }) if manualOther then if mw.ustring.lower(manualOther) ~= "none" then result.other = { text = '"' .. manualOther .. '"', reference = getManual(args, { "imraa_arrane" }), audio = nil } end elseif #other > 0 then result.other = { text = '"' .. other[1].label .. '"', reference = other[1].reference, audio = other[1].audio } end return result end ------------------------------------------------------------ -- Motto ------------------------------------------------------------ local function getMotto() local entity = mw.wikibase.getEntityObject() if not entity then return nil, nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil, nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return value.text, getWikidataReference(statement) end end end return nil, nil end ------------------------------------------------------------ -- Motto data ------------------------------------------------------------ local function getMottoData(args) local manual = getManual(args, { "jarroo-raa_ashoonagh", "jarroo-raa" }) if manual then if mw.ustring.lower(manual) == "none" then return nil end return { text = manual, reference = getManual(args, { "imraa_jarroo-raa" }) } end local text, reference = getMotto() if not text then return nil end return { text = text, reference = reference } end ------------------------------------------------------------ -- Motto and anthem output ------------------------------------------------------------ function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} -------------------------------------------------------- -- Motto -------------------------------------------------------- if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- National anthem -------------------------------------------------------- if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '""' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '""' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end ------------------------------------------------------------ -- Flag ------------------------------------------------------------ local function getFlag(args) -- Manual value takes precedence over Wikidata. local manual = getManual(args, { "jalloo_brattagh" }) if manual then if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P41 = flag image. return getWikidataImage("P41") end ------------------------------------------------------------ -- Coat of arms ------------------------------------------------------------ local function getArms(args) -- Manual value takes precedence over Wikidata. -- jalloo_armys is the preferred new parameter. -- jalloo_cleinney and jalloo_cowrey remain supported -- for compatibility with existing articles. local manual = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if manual then -- Explicitly suppress Wikidata. if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P94 = coat of arms image. return getWikidataImage("P94") end ------------------------------------------------------------ -- Country name ------------------------------------------------------------ local function getCountryName(args) return args.ennym_gienneydagh or args.kianglaghey_ennym or args.ennym or mw.title.getCurrentTitle().text end local function getGenitiveName(args) local name = getCountryName(args) return enmynCheerey.genitive(name) end ------------------------------------------------------------ -- Official name (Wikidata P1448) ------------------------------------------------------------ local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" and value.language and value.language ~= "" then table.insert(names, { text = value.text, lang = mw.ustring.lower(value.language) }) end end end return names end ------------------------------------------------------------ -- Language name ------------------------------------------------------------ local function getLanguageName(code) if not code or code == "" then return code end code = mw.ustring.lower(code) -- Manx Wikipedia language-name override. if langOverrideTable and langOverrideTable[code] then local name = langOverrideTable[code] if type(name) == "table" then return name[1] end return name end -- Standard language-name table. if langNameTable and langNameTable[code] then local name = langNameTable[code] if type(name) == "table" then return name[1] end return name end return code end ------------------------------------------------------------ -- Language label ------------------------------------------------------------ local function makeLanguageLabel(code) local languageName = getLanguageName(code) if not languageName or languageName == "" then return "" end -- The language name is deliberately NOT italicised. return mw.text.tag( "small", {}, "([[" .. languageName .. "|" .. languageName .. "]])" ) end ------------------------------------------------------------ -- Country title ------------------------------------------------------------ function p.title(frame) local args = getArgs(frame) local countryName = getCountryName(args) local officialNames = getOfficialNames() local manxName = nil local otherNames = {} -- Find the Manx official name first. for _, item in ipairs(officialNames) do if item.lang == "gv" then manxName = item.text break end end -- If Wikidata has no Manx P1448, use the short Manx country name. if not manxName then manxName = countryName end local output = {} -- Manx country name. -- Explicitly set the font and weight rather than inheriting -- the styling of the Infobox "above" field. table.insert( output, '<span style="font-family:inherit; font-weight:bold;">' .. manxName .. '</span>' ) -- Other official-language names. -- These must explicitly be normal weight. for _, item in ipairs(officialNames) do if item.lang ~= "gv" then local languageLabel = makeLanguageLabel(item.lang) local line = '<span style="font-weight:normal;">' .. item.text if languageLabel ~= "" then line = line .. " " .. languageLabel end line = line .. "</span>" table.insert(output, line) end end return table.concat(output, "<br>") end ------------------------------------------------------------ -- Images ------------------------------------------------------------ function p.images(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</td>' .. '<td style="width:42%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</td>' .. '</tr></table>', flag, arms, args.lheead_cowrey or "85px" ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</div>', flag ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</div>', arms, args.lheead_cowrey or "85px" ) end ------------------------------------------------------------ -- Captions ------------------------------------------------------------ function p.captions(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end local countryName = getCountryName(args) local genitiveName = getGenitiveName(args) local flagCaption = args["fo-heidyl_brattagh"] or "Brattagh" local armsCaption = args["sorçh_cowrey"] or "Armys" local armsArticle = args["art_sorçh_cowrey"] or "Armys" -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</td>' .. '<td style="width:42%%; text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</td>' .. '</tr></table>', genitiveName, flagCaption, armsArticle, genitiveName, armsCaption ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</div>', genitiveName, flagCaption ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</div>', armsArticle, genitiveName, armsCaption ) end return p nn4ewd6csd6nk59cshv3ns0aatjp3ya 392831 392830 2026-09-06T13:43:28Z MacTire02 219 ++ 392831 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override local function getArgs(frame) return frame:getParent().args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local value = mainsnak.datavalue.value if value and value ~= "" then return value end end end return nil end ------------------------------------------------------------ -- Wikidata item statement ------------------------------------------------------------ local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end ------------------------------------------------------------ -- Wikidata reference URL ------------------------------------------------------------ local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end ------------------------------------------------------------ -- Wikidata locator map ------------------------------------------------------------ local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Locator map data ------------------------------------------------------------ local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end ------------------------------------------------------------ -- Locator map ------------------------------------------------------------ function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end ------------------------------------------------------------ -- Capital / administrative centre data ------------------------------------------------------------ local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end -------------------------------------------------------- -- Manual capital -------------------------------------------------------- if capital then return { text = capital, entity = nil, reference = nil } end -------------------------------------------------------- -- Wikidata P36 = capital -------------------------------------------------------- local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Administrative centre data ------------------------------------------------------------ local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre } end return nil end ------------------------------------------------------------ -- Normalise a city name for comparison ------------------------------------------------------------ local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) -------------------------------------------------------- -- Remove simple wikilink markup -------------------------------------------------------- value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") -------------------------------------------------------- -- If the link has a pipe, retain only the target -------------------------------------------------------- local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end ------------------------------------------------------------ -- Largest city / settlement data ------------------------------------------------------------ local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = mw.text.trim(city) title = mw.ustring.gsub(title, "^%[%[", "") title = mw.ustring.gsub(title, "%]%]$", "") local pipe = mw.ustring.find(title, "|", 1, true) if pipe then title = mw.ustring.sub(title, 1, pipe - 1) end title = mw.text.trim(title) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = title, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Capital / administrative centre labels ------------------------------------------------------------ local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end ------------------------------------------------------------ -- City / settlement data ------------------------------------------------------------ local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end ------------------------------------------------------------ -- Determine whether capital is the largest city ------------------------------------------------------------ local function capitalIsLargest(capital, largest) if not capital or not largest then return false end -------------------------------------------------------- -- Best method: compare Wikidata entity IDs -------------------------------------------------------- if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end -------------------------------------------------------- -- Fallback: compare names -------------------------------------------------------- local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end ------------------------------------------------------------ -- Link city name to its article ------------------------------------------------------------ local function makeCityLink(city) if not city or not city.text then return "" end -------------------------------------------------------- -- If we have the Wikidata entity, use its Manx -- Wikipedia sitelink. -------------------------------------------------------- if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. city.text .. "]]" end end -------------------------------------------------------- -- Fallback: link to the displayed name itself. -------------------------------------------------------- return "[[" .. city.text .. "|" .. city.text .. "]]" end ------------------------------------------------------------ -- Coordinates ------------------------------------------------------------ local function makeCoordinates(entity) if not entity then return nil end -------------------------------------------------------- -- Wikidata P625 = coordinate location -------------------------------------------------------- local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end ------------------------------------------------------------ -- Capital / largest city / administrative centre ------------------------------------------------------------ function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = '<div style="text-align:left;">' .. "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end label = label .. '</div>' return label end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then return makeCityLink(administrative) elseif largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end return text end return nil end function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} -------------------------------------------------------- -- Capital / administrative centre -------------------------------------------------------- if capital or administrative then local label local text ---------------------------------------------------- -- Capital ---------------------------------------------------- if capital then ------------------------------------------------ -- Link the label to Preeu-valley ------------------------------------------------ label = "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" ------------------------------------------------ -- Link the capital city ------------------------------------------------ text = makeCityLink(capital) ------------------------------------------------ -- Capital is also largest city ------------------------------------------------ if capitalIsLargest(capital, largest) then text = text .. '<br/><small>(as y balley smoo)</small>' end ------------------------------------------------ -- Coordinates directly underneath the city ------------------------------------------------ if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/>' .. coordinates end end ------------------------------------------------ -- Wikidata reference ------------------------------------------------ if capital.reference then text = text .. capital.reference end ---------------------------------------------------- -- Administrative centre only ---------------------------------------------------- else label = "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" text = makeCityLink(administrative) end table.insert( rows, "'''" .. label .. ":&nbsp;'''" .. text ) ---------------------------------------------------- -- Add largest city when different from capital ---------------------------------------------------- if largest and not capitalIsLargest(capital, largest) then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- No capital or administrative centre, -- but largest city exists -------------------------------------------------------- elseif largest then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- Nothing to display -------------------------------------------------------- if #rows == 0 then return nil end return mw.text.listToText( rows, "<br/>", "<br/>" ) end ------------------------------------------------------------ -- Wikidata audio file ------------------------------------------------------------ local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Anthems ------------------------------------------------------------ local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil -- P3831 = object of statement has role. -- This may identify the anthem as national, -- royal, regional, etc. if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { label = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end ------------------------------------------------------------ -- Classify anthems ------------------------------------------------------------ local function classifyAnthems(anthems) local national = {} local royal = {} local other = {} for _, anthem in ipairs(anthems) do local role = anthem.role if role then role = mw.ustring.lower(role) end if role and mw.ustring.find(role, "royal") then table.insert(royal, anthem) elseif role and ( mw.ustring.find(role, "national") or mw.ustring.find(role, "state anthem") ) then table.insert(national, anthem) else table.insert(other, anthem) end end -- If Wikidata has supplied an anthem but has not given -- it a role, treat the first such anthem as the national -- anthem. P85 is normally used for the country's official -- anthem. if #national == 0 and #other > 0 then table.insert(national, other[1]) table.remove(other, 1) end return national, royal, other end ------------------------------------------------------------ -- Anthem data ------------------------------------------------------------ local function getAnthemData(args) local anthems = getAnthems() local national, royal, other = classifyAnthems(anthems) local result = {} -------------------------------------------------------- -- National anthem -------------------------------------------------------- local manualNational = getManual(args, { "arrane_ashoonagh" }) if manualNational then if mw.ustring.lower(manualNational) ~= "none" then result.national = { text = '"' .. manualNational .. '"', reference = getManual(args, { "imraa_arrane_ashoonagh" }), audio = nil } end elseif #national > 0 then result.national = { text = national[1].label, reference = national[1].reference, audio = national[1].audio } end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- local manualRoyal = getManual(args, { "arrane_reeoil" }) if manualRoyal then if mw.ustring.lower(manualRoyal) ~= "none" then result.royal = { text = '"' .. manualRoyal .. '"', reference = getManual(args, { "imraa_arrane_reeoil" }), audio = nil } end elseif #royal > 0 then result.royal = { text = '"' .. royal[1].label .. '"', reference = royal[1].reference, audio = royal[1].audio } end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- local manualOther = getManual(args, { "arrane" }) if manualOther then if mw.ustring.lower(manualOther) ~= "none" then result.other = { text = '"' .. manualOther .. '"', reference = getManual(args, { "imraa_arrane" }), audio = nil } end elseif #other > 0 then result.other = { text = '"' .. other[1].label .. '"', reference = other[1].reference, audio = other[1].audio } end return result end ------------------------------------------------------------ -- Motto ------------------------------------------------------------ local function getMotto() local entity = mw.wikibase.getEntityObject() if not entity then return nil, nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil, nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return value.text, getWikidataReference(statement) end end end return nil, nil end ------------------------------------------------------------ -- Motto data ------------------------------------------------------------ local function getMottoData(args) local manual = getManual(args, { "jarroo-raa_ashoonagh", "jarroo-raa" }) if manual then if mw.ustring.lower(manual) == "none" then return nil end return { text = manual, reference = getManual(args, { "imraa_jarroo-raa" }) } end local text, reference = getMotto() if not text then return nil end return { text = text, reference = reference } end ------------------------------------------------------------ -- Motto and anthem output ------------------------------------------------------------ function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} -------------------------------------------------------- -- Motto -------------------------------------------------------- if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- National anthem -------------------------------------------------------- if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '""' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '""' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end ------------------------------------------------------------ -- Flag ------------------------------------------------------------ local function getFlag(args) -- Manual value takes precedence over Wikidata. local manual = getManual(args, { "jalloo_brattagh" }) if manual then if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P41 = flag image. return getWikidataImage("P41") end ------------------------------------------------------------ -- Coat of arms ------------------------------------------------------------ local function getArms(args) -- Manual value takes precedence over Wikidata. -- jalloo_armys is the preferred new parameter. -- jalloo_cleinney and jalloo_cowrey remain supported -- for compatibility with existing articles. local manual = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if manual then -- Explicitly suppress Wikidata. if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P94 = coat of arms image. return getWikidataImage("P94") end ------------------------------------------------------------ -- Country name ------------------------------------------------------------ local function getCountryName(args) return args.ennym_gienneydagh or args.kianglaghey_ennym or args.ennym or mw.title.getCurrentTitle().text end local function getGenitiveName(args) local name = getCountryName(args) return enmynCheerey.genitive(name) end ------------------------------------------------------------ -- Official name (Wikidata P1448) ------------------------------------------------------------ local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" and value.language and value.language ~= "" then table.insert(names, { text = value.text, lang = mw.ustring.lower(value.language) }) end end end return names end ------------------------------------------------------------ -- Language name ------------------------------------------------------------ local function getLanguageName(code) if not code or code == "" then return code end code = mw.ustring.lower(code) -- Manx Wikipedia language-name override. if langOverrideTable and langOverrideTable[code] then local name = langOverrideTable[code] if type(name) == "table" then return name[1] end return name end -- Standard language-name table. if langNameTable and langNameTable[code] then local name = langNameTable[code] if type(name) == "table" then return name[1] end return name end return code end ------------------------------------------------------------ -- Language label ------------------------------------------------------------ local function makeLanguageLabel(code) local languageName = getLanguageName(code) if not languageName or languageName == "" then return "" end -- The language name is deliberately NOT italicised. return mw.text.tag( "small", {}, "([[" .. languageName .. "|" .. languageName .. "]])" ) end ------------------------------------------------------------ -- Country title ------------------------------------------------------------ function p.title(frame) local args = getArgs(frame) local countryName = getCountryName(args) local officialNames = getOfficialNames() local manxName = nil local otherNames = {} -- Find the Manx official name first. for _, item in ipairs(officialNames) do if item.lang == "gv" then manxName = item.text break end end -- If Wikidata has no Manx P1448, use the short Manx country name. if not manxName then manxName = countryName end local output = {} -- Manx country name. -- Explicitly set the font and weight rather than inheriting -- the styling of the Infobox "above" field. table.insert( output, '<span style="font-family:inherit; font-weight:bold;">' .. manxName .. '</span>' ) -- Other official-language names. -- These must explicitly be normal weight. for _, item in ipairs(officialNames) do if item.lang ~= "gv" then local languageLabel = makeLanguageLabel(item.lang) local line = '<span style="font-weight:normal;">' .. item.text if languageLabel ~= "" then line = line .. " " .. languageLabel end line = line .. "</span>" table.insert(output, line) end end return table.concat(output, "<br>") end ------------------------------------------------------------ -- Images ------------------------------------------------------------ function p.images(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</td>' .. '<td style="width:42%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</td>' .. '</tr></table>', flag, arms, args.lheead_cowrey or "85px" ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</div>', flag ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</div>', arms, args.lheead_cowrey or "85px" ) end ------------------------------------------------------------ -- Captions ------------------------------------------------------------ function p.captions(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end local countryName = getCountryName(args) local genitiveName = getGenitiveName(args) local flagCaption = args["fo-heidyl_brattagh"] or "Brattagh" local armsCaption = args["sorçh_cowrey"] or "Armys" local armsArticle = args["art_sorçh_cowrey"] or "Armys" -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</td>' .. '<td style="width:42%%; text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</td>' .. '</tr></table>', genitiveName, flagCaption, armsArticle, genitiveName, armsCaption ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</div>', genitiveName, flagCaption ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</div>', armsArticle, genitiveName, armsCaption ) end return p sdc2i0m3otfaz8z083gei3djhzacy64 392832 392831 2026-09-06T13:46:11Z MacTire02 219 prowal 392832 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override local function getArgs(frame) return frame:getParent().args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local value = mainsnak.datavalue.value if value and value ~= "" then return value end end end return nil end ------------------------------------------------------------ -- Wikidata item statement ------------------------------------------------------------ local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end ------------------------------------------------------------ -- Wikidata reference URL ------------------------------------------------------------ local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end ------------------------------------------------------------ -- Wikidata locator map ------------------------------------------------------------ local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Locator map data ------------------------------------------------------------ local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end ------------------------------------------------------------ -- Locator map ------------------------------------------------------------ function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end ------------------------------------------------------------ -- Capital / administrative centre data ------------------------------------------------------------ local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end -------------------------------------------------------- -- Manual capital -------------------------------------------------------- if capital then return { text = capital, entity = nil, reference = nil } end -------------------------------------------------------- -- Wikidata P36 = capital -------------------------------------------------------- local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Administrative centre data ------------------------------------------------------------ local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre } end return nil end ------------------------------------------------------------ -- Normalise a city name for comparison ------------------------------------------------------------ local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) -------------------------------------------------------- -- Remove simple wikilink markup -------------------------------------------------------- value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") -------------------------------------------------------- -- If the link has a pipe, retain only the target -------------------------------------------------------- local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end ------------------------------------------------------------ -- Largest city / settlement data ------------------------------------------------------------ local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = mw.text.trim(city) title = mw.ustring.gsub(title, "^%[%[", "") title = mw.ustring.gsub(title, "%]%]$", "") local pipe = mw.ustring.find(title, "|", 1, true) if pipe then title = mw.ustring.sub(title, 1, pipe - 1) end title = mw.text.trim(title) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = title, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end ------------------------------------------------------------ -- Capital / administrative centre labels ------------------------------------------------------------ local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end ------------------------------------------------------------ -- City / settlement data ------------------------------------------------------------ local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end ------------------------------------------------------------ -- Determine whether capital is the largest city ------------------------------------------------------------ local function capitalIsLargest(capital, largest) if not capital or not largest then return false end -------------------------------------------------------- -- Best method: compare Wikidata entity IDs -------------------------------------------------------- if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end -------------------------------------------------------- -- Fallback: compare names -------------------------------------------------------- local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end ------------------------------------------------------------ -- Link city name to its article ------------------------------------------------------------ local function makeCityLink(city) if not city or not city.text then return "" end -------------------------------------------------------- -- If we have the Wikidata entity, use its Manx -- Wikipedia sitelink. -------------------------------------------------------- if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. city.text .. "]]" end end -------------------------------------------------------- -- Fallback: link to the displayed name itself. -------------------------------------------------------- return "[[" .. city.text .. "|" .. city.text .. "]]" end ------------------------------------------------------------ -- Coordinates ------------------------------------------------------------ local function makeCoordinates(entity) if not entity then return nil end -------------------------------------------------------- -- Wikidata P625 = coordinate location -------------------------------------------------------- local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end ------------------------------------------------------------ -- Capital / largest city / administrative centre ------------------------------------------------------------ function p.test_city(frame) local args = getArgs(frame) return getManual(args, { "balley_smoo" }) or "NO BALLEY_SMOO" end function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = '<div style="text-align:left;">' .. "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end label = label .. '</div>' return label end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then return makeCityLink(administrative) elseif largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end return text end return nil end function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} -------------------------------------------------------- -- Capital / administrative centre -------------------------------------------------------- if capital or administrative then local label local text ---------------------------------------------------- -- Capital ---------------------------------------------------- if capital then ------------------------------------------------ -- Link the label to Preeu-valley ------------------------------------------------ label = "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" ------------------------------------------------ -- Link the capital city ------------------------------------------------ text = makeCityLink(capital) ------------------------------------------------ -- Capital is also largest city ------------------------------------------------ if capitalIsLargest(capital, largest) then text = text .. '<br/><small>(as y balley smoo)</small>' end ------------------------------------------------ -- Coordinates directly underneath the city ------------------------------------------------ if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/>' .. coordinates end end ------------------------------------------------ -- Wikidata reference ------------------------------------------------ if capital.reference then text = text .. capital.reference end ---------------------------------------------------- -- Administrative centre only ---------------------------------------------------- else label = "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" text = makeCityLink(administrative) end table.insert( rows, "'''" .. label .. ":&nbsp;'''" .. text ) ---------------------------------------------------- -- Add largest city when different from capital ---------------------------------------------------- if largest and not capitalIsLargest(capital, largest) then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- No capital or administrative centre, -- but largest city exists -------------------------------------------------------- elseif largest then local largestText = makeCityLink(largest) if largest.reference then largestText = largestText .. largest.reference end table.insert( rows, "'''Balley smoo:&nbsp;'''" .. largestText ) end -------------------------------------------------------- -- Nothing to display -------------------------------------------------------- if #rows == 0 then return nil end return mw.text.listToText( rows, "<br/>", "<br/>" ) end ------------------------------------------------------------ -- Wikidata audio file ------------------------------------------------------------ local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end ------------------------------------------------------------ -- Anthems ------------------------------------------------------------ local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil -- P3831 = object of statement has role. -- This may identify the anthem as national, -- royal, regional, etc. if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { label = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end ------------------------------------------------------------ -- Classify anthems ------------------------------------------------------------ local function classifyAnthems(anthems) local national = {} local royal = {} local other = {} for _, anthem in ipairs(anthems) do local role = anthem.role if role then role = mw.ustring.lower(role) end if role and mw.ustring.find(role, "royal") then table.insert(royal, anthem) elseif role and ( mw.ustring.find(role, "national") or mw.ustring.find(role, "state anthem") ) then table.insert(national, anthem) else table.insert(other, anthem) end end -- If Wikidata has supplied an anthem but has not given -- it a role, treat the first such anthem as the national -- anthem. P85 is normally used for the country's official -- anthem. if #national == 0 and #other > 0 then table.insert(national, other[1]) table.remove(other, 1) end return national, royal, other end ------------------------------------------------------------ -- Anthem data ------------------------------------------------------------ local function getAnthemData(args) local anthems = getAnthems() local national, royal, other = classifyAnthems(anthems) local result = {} -------------------------------------------------------- -- National anthem -------------------------------------------------------- local manualNational = getManual(args, { "arrane_ashoonagh" }) if manualNational then if mw.ustring.lower(manualNational) ~= "none" then result.national = { text = '"' .. manualNational .. '"', reference = getManual(args, { "imraa_arrane_ashoonagh" }), audio = nil } end elseif #national > 0 then result.national = { text = national[1].label, reference = national[1].reference, audio = national[1].audio } end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- local manualRoyal = getManual(args, { "arrane_reeoil" }) if manualRoyal then if mw.ustring.lower(manualRoyal) ~= "none" then result.royal = { text = '"' .. manualRoyal .. '"', reference = getManual(args, { "imraa_arrane_reeoil" }), audio = nil } end elseif #royal > 0 then result.royal = { text = '"' .. royal[1].label .. '"', reference = royal[1].reference, audio = royal[1].audio } end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- local manualOther = getManual(args, { "arrane" }) if manualOther then if mw.ustring.lower(manualOther) ~= "none" then result.other = { text = '"' .. manualOther .. '"', reference = getManual(args, { "imraa_arrane" }), audio = nil } end elseif #other > 0 then result.other = { text = '"' .. other[1].label .. '"', reference = other[1].reference, audio = other[1].audio } end return result end ------------------------------------------------------------ -- Motto ------------------------------------------------------------ local function getMotto() local entity = mw.wikibase.getEntityObject() if not entity then return nil, nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil, nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return value.text, getWikidataReference(statement) end end end return nil, nil end ------------------------------------------------------------ -- Motto data ------------------------------------------------------------ local function getMottoData(args) local manual = getManual(args, { "jarroo-raa_ashoonagh", "jarroo-raa" }) if manual then if mw.ustring.lower(manual) == "none" then return nil end return { text = manual, reference = getManual(args, { "imraa_jarroo-raa" }) } end local text, reference = getMotto() if not text then return nil end return { text = text, reference = reference } end ------------------------------------------------------------ -- Motto and anthem output ------------------------------------------------------------ function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} -------------------------------------------------------- -- Motto -------------------------------------------------------- if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- National anthem -------------------------------------------------------- if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Other anthem -------------------------------------------------------- if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '""' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end -------------------------------------------------------- -- Royal anthem -------------------------------------------------------- if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '""' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end ------------------------------------------------------------ -- Flag ------------------------------------------------------------ local function getFlag(args) -- Manual value takes precedence over Wikidata. local manual = getManual(args, { "jalloo_brattagh" }) if manual then if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P41 = flag image. return getWikidataImage("P41") end ------------------------------------------------------------ -- Coat of arms ------------------------------------------------------------ local function getArms(args) -- Manual value takes precedence over Wikidata. -- jalloo_armys is the preferred new parameter. -- jalloo_cleinney and jalloo_cowrey remain supported -- for compatibility with existing articles. local manual = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if manual then -- Explicitly suppress Wikidata. if mw.ustring.lower(manual) == "none" then return false end return manual end -- Wikidata P94 = coat of arms image. return getWikidataImage("P94") end ------------------------------------------------------------ -- Country name ------------------------------------------------------------ local function getCountryName(args) return args.ennym_gienneydagh or args.kianglaghey_ennym or args.ennym or mw.title.getCurrentTitle().text end local function getGenitiveName(args) local name = getCountryName(args) return enmynCheerey.genitive(name) end ------------------------------------------------------------ -- Official name (Wikidata P1448) ------------------------------------------------------------ local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" and value.language and value.language ~= "" then table.insert(names, { text = value.text, lang = mw.ustring.lower(value.language) }) end end end return names end ------------------------------------------------------------ -- Language name ------------------------------------------------------------ local function getLanguageName(code) if not code or code == "" then return code end code = mw.ustring.lower(code) -- Manx Wikipedia language-name override. if langOverrideTable and langOverrideTable[code] then local name = langOverrideTable[code] if type(name) == "table" then return name[1] end return name end -- Standard language-name table. if langNameTable and langNameTable[code] then local name = langNameTable[code] if type(name) == "table" then return name[1] end return name end return code end ------------------------------------------------------------ -- Language label ------------------------------------------------------------ local function makeLanguageLabel(code) local languageName = getLanguageName(code) if not languageName or languageName == "" then return "" end -- The language name is deliberately NOT italicised. return mw.text.tag( "small", {}, "([[" .. languageName .. "|" .. languageName .. "]])" ) end ------------------------------------------------------------ -- Country title ------------------------------------------------------------ function p.title(frame) local args = getArgs(frame) local countryName = getCountryName(args) local officialNames = getOfficialNames() local manxName = nil local otherNames = {} -- Find the Manx official name first. for _, item in ipairs(officialNames) do if item.lang == "gv" then manxName = item.text break end end -- If Wikidata has no Manx P1448, use the short Manx country name. if not manxName then manxName = countryName end local output = {} -- Manx country name. -- Explicitly set the font and weight rather than inheriting -- the styling of the Infobox "above" field. table.insert( output, '<span style="font-family:inherit; font-weight:bold;">' .. manxName .. '</span>' ) -- Other official-language names. -- These must explicitly be normal weight. for _, item in ipairs(officialNames) do if item.lang ~= "gv" then local languageLabel = makeLanguageLabel(item.lang) local line = '<span style="font-weight:normal;">' .. item.text if languageLabel ~= "" then line = line .. " " .. languageLabel end line = line .. "</span>" table.insert(output, line) end end return table.concat(output, "<br>") end ------------------------------------------------------------ -- Images ------------------------------------------------------------ function p.images(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</td>' .. '<td style="width:42%%; text-align:center; vertical-align:middle;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</td>' .. '</tr></table>', flag, arms, args.lheead_cowrey or "85px" ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|125px|border|alt=Brattagh]]' .. '</div>', flag ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '[[Coadan:%s|%s|alt=Armys]]' .. '</div>', arms, args.lheead_cowrey or "85px" ) end ------------------------------------------------------------ -- Captions ------------------------------------------------------------ function p.captions(frame) local args = getArgs(frame) local flag = getFlag(args) local arms = getArms(args) -- No flag and no coat of arms. if not flag and not arms then return "" end local countryName = getCountryName(args) local genitiveName = getGenitiveName(args) local flagCaption = args["fo-heidyl_brattagh"] or "Brattagh" local armsCaption = args["sorçh_cowrey"] or "Armys" local armsArticle = args["art_sorçh_cowrey"] or "Armys" -- Both flag and coat of arms. if flag and arms then return string.format( '<table style="width:100%%; background:none; border:0;"><tr>' .. '<td style="width:58%%; text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</td>' .. '<td style="width:42%%; text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</td>' .. '</tr></table>', genitiveName, flagCaption, armsArticle, genitiveName, armsCaption ) end -- Flag only. if flag then return string.format( '<div style="text-align:center;">' .. '<small>[[Brattagh %s|%s]]</small>' .. '</div>', genitiveName, flagCaption ) end -- Coat of arms only. return string.format( '<div style="text-align:center;">' .. '<small>[[%s %s|%s]]</small>' .. '</div>', armsArticle, genitiveName, armsCaption ) end return p hyrs283herx3a8leod66p65y5ewprbu 392834 392832 2026-09-06T13:49:34Z MacTire02 219 ++ 392834 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override local function getArgs(frame) return frame:getParent().args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- TITLE -------------------------------------------------- local function getTitleData(args) local name = getManual(args, { "ennym", "ennym_çheerey" }) if not name then return nil end return name end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getCountryName(args) local name = getManual(args, { "ennym", "ennym_çheerey" }) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getManual(args, { "ennym", "ennym_çheerey" }) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getImages(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil else if not flag then flag = getWikidataImage("P41") end end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil else if not arms then arms = getWikidataImage("P94") end end local images = {} if flag then table.insert(images, flag) end if arms then table.insert(images, arms) end if #images == 0 then return nil end return images end -------------------------------------------------- -- IMAGE CAPTIONS -------------------------------------------------- local function getCaptions(args) local flagCaption = getManual(args, { "fo-heidyl_brattagh" }) local armsCaption = getManual(args, { "fo-heidyl_armys", "fo-heidyl_cleinney", "fo-heidyl_cowrey" }) local captions = {} local images = getImages(args) if not images then return nil end local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if flag then table.insert(captions, flagCaption or "") end if arms then table.insert(captions, armsCaption or "") end return captions end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo-raa" }) if motto and mw.ustring.lower(motto) == "none" then return nil end if motto then return { text = "“" .. motto .. "”", reference = reference and "<ref>" .. reference .. "</ref>" or nil } end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { label = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = '"' .. national .. '"', reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = '"' .. royal .. '"', reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = '"' .. other .. '"', reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '""' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '""' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then return { text = capital, entity = nil, reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre } end return nil end local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = mw.text.trim(city) title = mw.ustring.gsub(title, "^%[%[", "") title = mw.ustring.gsub(title, "%]%]$", "") local pipe = mw.ustring.find(title, "|", 1, true) if pipe then title = mw.ustring.sub(title, 1, pipe - 1) end title = mw.text.trim(title) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = title, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. city.text .. "]]" end end return "[[" .. city.text .. "|" .. city.text .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = '<div style="text-align:left;">' .. "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end label = label .. '</div>' return label end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then return makeCityLink(administrative) elseif largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TEMPORARY TEST -------------------------------------------------- function p.test_city(frame) local args = getArgs(frame) if args["balley_smoo"] then return "BALLEY_SMOO = " .. args["balley_smoo"] end return "NO BALLEY_SMOO" end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local name = getCountryName(args) if not name then return nil end local genitive = getCountryGenitive(args) local officialNames = getOfficialNames() local gvName = nil local otherNames = {} for _, official in ipairs(officialNames) do if official.language == "gv" then gvName = official else table.insert(otherNames, official) end end local title = "" if gvName then title = '<span style="font-weight:bold;">' .. gvName.text .. '</span>' else title = '<span style="font-weight:bold;">' .. name .. '</span>' end for _, official in ipairs(otherNames) do local languageName = getLanguageName(official.language) title = title .. "<br/><span style=\"font-weight:normal;\">" .. (official.text or "") .. " (" .. (languageName or official.language) .. ")</span>" end return title end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) local images = getImages(args) if not images then return nil end return table.concat(images, "<br/>") end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) local args = getArgs(frame) local captions = getCaptions(args) if not captions then return nil end return table.concat(captions, "<br/>") end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest and not capitalIsLargest(capital, largest) then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end return p ap7d4n4ee1pavjb0byowzxtxfv8hrsp 392837 392834 2026-09-06T13:53:21Z MacTire02 219 prowal 392837 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override local function getArgs(frame) return frame:getParent().args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- TITLE -------------------------------------------------- local function getTitleData(args) local name = getManual(args, { "ennym", "ennym_çheerey" }) if not name then return nil end return name end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getCountryName(args) local name = getManual(args, { "ennym", "ennym_çheerey" }) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getManual(args, { "ennym", "ennym_çheerey" }) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getImages(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil else if not flag then flag = getWikidataImage("P41") end end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil else if not arms then arms = getWikidataImage("P94") end end local images = {} if flag then table.insert(images, flag) end if arms then table.insert(images, arms) end if #images == 0 then return nil end return images end -------------------------------------------------- -- IMAGE CAPTIONS -------------------------------------------------- local function getCaptions(args) local flagCaption = getManual(args, { "fo-heidyl_brattagh" }) local armsCaption = getManual(args, { "fo-heidyl_armys", "fo-heidyl_cleinney", "fo-heidyl_cowrey" }) local captions = {} local images = getImages(args) if not images then return nil end local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if flag then table.insert(captions, flagCaption or "") end if arms then table.insert(captions, armsCaption or "") end return captions end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo-raa" }) if motto and mw.ustring.lower(motto) == "none" then return nil end if motto then return { text = "“" .. motto .. "”", reference = reference and "<ref>" .. reference .. "</ref>" or nil } end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { label = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = '"' .. national .. '"', reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = '"' .. royal .. '"', reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = '"' .. other .. '"', reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '""' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '""' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then return { text = capital, entity = nil, reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre } end return nil end local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = mw.text.trim(city) title = mw.ustring.gsub(title, "^%[%[", "") title = mw.ustring.gsub(title, "%]%]$", "") local pipe = mw.ustring.find(title, "|", 1, true) if pipe then title = mw.ustring.sub(title, 1, pipe - 1) end title = mw.text.trim(title) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = title, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. city.text .. "]]" end end return "[[" .. city.text .. "|" .. city.text .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = '<div style="text-align:left;">' .. "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end label = label .. '</div>' return label end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then return makeCityLink(administrative) elseif largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TEMPORARY TEST -------------------------------------------------- function p.test_city(frame) local args = getArgs(frame) if args["balley_smoo"] then return "BALLEY_SMOO = " .. args["balley_smoo"] end return "NO BALLEY_SMOO" end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local name = getCountryName(args) if not name then return nil end local genitive = getCountryGenitive(args) local officialNames = getOfficialNames() local gvName = nil local otherNames = {} for _, official in ipairs(officialNames) do if official.language == "gv" then gvName = official else table.insert(otherNames, official) end end local title = "" if gvName then title = '<span style="font-weight:bold;">' .. gvName.text .. '</span>' else title = '<span style="font-weight:bold;">' .. name .. '</span>' end for _, official in ipairs(otherNames) do local languageName = getLanguageName(official.language) title = title .. "<br/><span style=\"font-weight:normal;\">" .. (official.text or "") .. " (" .. (languageName or official.language) .. ")</span>" end return title end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) local images = getImages(args) if not images then return nil end return table.concat(images, "<br/>") end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) local args = getArgs(frame) local captions = getCaptions(args) if not captions then return nil end return table.concat(captions, "<br/>") end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest and not capitalIsLargest(capital, largest) then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end function p.test_city(frame) local args = getArgs(frame) if args["balley_smoo"] then return "BALLEY_SMOO = " .. args["balley_smoo"] end return "NO BALLEY_SMOO" end return p eipxwcluiebhgz5tukdppsu2rifvtdu 392838 392837 2026-09-06T13:56:11Z MacTire02 219 ++ 392838 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override local function getArgs(frame) return frame:getParent().args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- TITLE -------------------------------------------------- local function getTitleData(args) local name = getManual(args, { "ennym", "ennym_çheerey" }) if not name then return nil end return name end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getCountryName(args) local name = getManual(args, { "ennym", "ennym_çheerey" }) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getManual(args, { "ennym", "ennym_çheerey" }) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getImages(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil else if not flag then flag = getWikidataImage("P41") end end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil else if not arms then arms = getWikidataImage("P94") end end local images = {} if flag then table.insert(images, flag) end if arms then table.insert(images, arms) end if #images == 0 then return nil end return images end -------------------------------------------------- -- IMAGE CAPTIONS -------------------------------------------------- local function getCaptions(args) local flagCaption = getManual(args, { "fo-heidyl_brattagh" }) local armsCaption = getManual(args, { "fo-heidyl_armys", "fo-heidyl_cleinney", "fo-heidyl_cowrey" }) local captions = {} local images = getImages(args) if not images then return nil end local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if flag then table.insert(captions, flagCaption or "") end if arms then table.insert(captions, armsCaption or "") end return captions end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo-raa" }) if motto and mw.ustring.lower(motto) == "none" then return nil end if motto then return { text = "“" .. motto .. "”", reference = reference and "<ref>" .. reference .. "</ref>" or nil } end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = '"' .. national .. '"', reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = '"' .. royal .. '"', reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = '"' .. other .. '"', reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '""' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '""' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then return { text = capital, entity = nil, reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre } end return nil end local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = mw.text.trim(city) title = mw.ustring.gsub(title, "^%[%[", "") title = mw.ustring.gsub(title, "%]%]$", "") local pipe = mw.ustring.find(title, "|", 1, true) if pipe then title = mw.ustring.sub(title, 1, pipe - 1) end title = mw.text.trim(title) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = title, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. city.text .. "]]" end end return "[[" .. city.text .. "|" .. city.text .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = '<div style="text-align:left;">' .. "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end label = label .. '</div>' return label end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then return makeCityLink(administrative) elseif largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TEMPORARY TEST -------------------------------------------------- function p.test_city(frame) local args = getArgs(frame) if args["balley_smoo"] then return "BALLEY_SMOO = " .. args["balley_smoo"] end return "NO BALLEY_SMOO" end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local name = getCountryName(args) if not name then return nil end local genitive = getCountryGenitive(args) local officialNames = getOfficialNames() local gvName = nil local otherNames = {} for _, official in ipairs(officialNames) do if official.language == "gv" then gvName = official else table.insert(otherNames, official) end end local title = "" if gvName then title = '<span style="font-weight:bold;">' .. gvName.text .. '</span>' else title = '<span style="font-weight:bold;">' .. name .. '</span>' end for _, official in ipairs(otherNames) do local languageName = getLanguageName(official.language) title = title .. "<br/><span style=\"font-weight:normal;\">" .. (official.text or "") .. " (" .. (languageName or official.language) .. ")</span>" end return title end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) local images = getImages(args) if not images then return nil end return table.concat(images, "<br/>") end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) local args = getArgs(frame) local captions = getCaptions(args) if not captions then return nil end return table.concat(captions, "<br/>") end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest and not capitalIsLargest(capital, largest) then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end return p kkwdh7qot83d8cgi0s9vr1aly3g7cuo 392839 392838 2026-09-06T13:59:31Z MacTire02 219 ++ 392839 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override local function getArgs(frame) return frame:getParent().args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- TITLE -------------------------------------------------- local function getTitleData(args) local name = getManual(args, { "ennym", "ennym_çheerey" }) if not name then return nil end return name end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getCountryName(args) local name = getManual(args, { "ennym", "ennym_çheerey" }) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getManual(args, { "ennym", "ennym_çheerey" }) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getImages(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil else if not flag then flag = getWikidataImage("P41") end end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil else if not arms then arms = getWikidataImage("P94") end end local images = {} if flag then table.insert(images, flag) end if arms then table.insert(images, arms) end if #images == 0 then return nil end return images end -------------------------------------------------- -- IMAGE CAPTIONS -------------------------------------------------- local function getCaptions(args) local flagCaption = getManual(args, { "fo-heidyl_brattagh" }) local armsCaption = getManual(args, { "fo-heidyl_armys", "fo-heidyl_cleinney", "fo-heidyl_cowrey" }) local captions = {} local images = getImages(args) if not images then return nil end local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if flag then table.insert(captions, flagCaption or "") end if arms then table.insert(captions, armsCaption or "") end return captions end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo-raa" }) if motto and mw.ustring.lower(motto) == "none" then return nil end if motto then return { text = "“" .. motto .. "”", reference = reference and "<ref>" .. reference .. "</ref>" or nil } end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = '"' .. national .. '"', reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = '"' .. royal .. '"', reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = '"' .. other .. '"', reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '""' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '""' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then return { text = capital, entity = nil, reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre } end return nil end local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = mw.text.trim(city) title = mw.ustring.gsub(title, "^%[%[", "") title = mw.ustring.gsub(title, "%]%]$", "") local pipe = mw.ustring.find(title, "|", 1, true) if pipe then title = mw.ustring.sub(title, 1, pipe - 1) end title = mw.text.trim(title) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = title, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. city.text .. "]]" end end return "[[" .. city.text .. "|" .. city.text .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = '<div style="text-align:left;">' .. "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end label = label .. '</div>' return label end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then return makeCityLink(administrative) elseif largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TEMPORARY TEST -------------------------------------------------- function p.test_city(frame) local args = getArgs(frame) if args["balley_smoo"] then return "BALLEY_SMOO = " .. args["balley_smoo"] end return "NO BALLEY_SMOO" end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local titleData = getTitleData(args) if not titleData then return nil end local text = titleData.name if titleData.genitive then text = text .. "<br/><small>(" .. titleData.genitive .. ")</small>" end return text end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) local flag = getFlagData(args) local arms = getArmsData(args) local images = {} if flag then table.insert(images, "[[Coadan:" .. flag.image .. "|" .. flag.width .. "]]" ) end if arms then table.insert(images, "[[Coadan:" .. arms.image .. "|" .. arms.width .. "]]" ) end if #images == 0 then return nil end return table.concat(images, "<br/>") end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) local args = getArgs(frame) local captions = getCaptions(args) if not captions then return nil end return table.concat(captions, "<br/>") end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest and not capitalIsLargest(capital, largest) then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end return p q9rcimljmpcg06yxgq0ok385cjt5i1w 392840 392839 2026-09-06T14:13:01Z MacTire02 219 ++ 392840 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getCountryName(args) local name = getManual(args, { "ennym", "ennym_çheerey" }) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getManual(args, { "ennym", "ennym_çheerey" }) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- TITLE -------------------------------------------------- local function getTitleData(args) local name = getCountryName(args) if not name then return nil end local genitive = getCountryGenitive(args) return { name = name, genitive = genitive } end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getImages(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end local images = {} if flag then table.insert(images, { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px" }) end if arms then table.insert(images, { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "125px" }) end if #images == 0 then return nil end return images end -------------------------------------------------- -- IMAGE CAPTIONS -------------------------------------------------- local function getCaptions(args) local flagCaption = getManual(args, { "fo-heidyl_brattagh" }) local armsCaption = getManual(args, { "fo-heidyl_armys", "fo-heidyl_cleinney", "fo-heidyl_cowrey" }) local captions = {} local images = getImages(args) if not images then return nil end local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if flag then table.insert(captions, flagCaption or "") end if arms then table.insert(captions, armsCaption or "") end return captions end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo-raa" }) if motto and mw.ustring.lower(motto) == "none" then return nil end if motto then return { text = "“" .. motto .. "”", reference = reference and "<ref>" .. reference .. "</ref>" or nil } end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = '"' .. national .. '"', reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = '"' .. royal .. '"', reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = '"' .. other .. '"', reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then local title = normaliseCityName(capital) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = capital, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = normaliseCityName(city) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = city, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. normaliseCityName(city.text) .. "]]" end end local title = normaliseCityName(city.text) return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = '<div style="text-align:left;">' .. "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end label = label .. '</div>' return label end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then return makeCityLink(administrative) elseif largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TEMPORARY TEST -------------------------------------------------- function p.test_city(frame) local args = getArgs(frame) local value = getManual(args, { "balley_smoo" }) if value then return "BALLEY_SMOO = " .. value end return "NO BALLEY_SMOO" end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local titleData = getTitleData(args) if not titleData then return nil end local text = titleData.name if titleData.genitive then text = text .. "<br/><small>(" .. titleData.genitive .. ")</small>" end return text end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) local images = getImages(args) if not images then return nil end local output = {} for _, image in ipairs(images) do table.insert(output, '[[Coadan:' .. image.image .. '|' .. image.width .. '|center]]' ) end return table.concat(output, "<br/>") end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) local args = getArgs(frame) local captions = getCaptions(args) if not captions then return nil end return table.concat(captions, "<br/>") end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest and not capitalIsLargest(capital, largest) then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end return p mgc7b3r49yedtxxmkqdl8mppfbgr5iv 392841 392840 2026-09-06T14:33:54Z MacTire02 219 ++ 392841 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getCountryName(args) local name = getManual(args, { "ennym", "ennym_çheerey", "ennym_çheer" }) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getManual(args, { "ennym", "ennym_çheerey" }) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- TITLE -------------------------------------------------- local function getTitleData(args) local name = getCountryName(args) if not name then return nil end local genitive = getCountryGenitive(args) return { name = name, genitive = genitive } end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getImages(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end local images = {} if flag then table.insert(images, { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px" }) end if arms then table.insert(images, { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "125px" }) end if #images == 0 then return nil end return images end -------------------------------------------------- -- IMAGE CAPTIONS -------------------------------------------------- local function getCaptions(args) local flagCaption = getManual(args, { "fo-heidyl_brattagh" }) local armsCaption = getManual(args, { "fo-heidyl_armys", "fo-heidyl_cleinney", "fo-heidyl_cowrey" }) local captions = {} local images = getImages(args) if not images then return nil end local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if flag then table.insert(captions, flagCaption or "") end if arms then table.insert(captions, armsCaption or "") end return captions end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa", "jarroo_raa" }) local reference = getManual(args, { "imraa_jarroo-raa", "imraa_jarroo_raa" }) if motto and mw.ustring.lower(motto) == "none" then return nil end if motto then return { text = "“" .. motto .. "”", reference = reference and "<ref>" .. reference .. "</ref>" or nil } end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = '"' .. national .. '"', reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = '"' .. royal .. '"', reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = '"' .. other .. '"', reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then local title = normaliseCityName(capital) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = capital, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = normaliseCityName(city) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = city, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. normaliseCityName(city.text) .. "]]" end end local title = normaliseCityName(city.text) return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = '<div style="text-align:left;">' .. "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end label = label .. '</div>' return label end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then return makeCityLink(administrative) elseif largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TEMPORARY TEST -------------------------------------------------- function p.test_city(frame) local args = getArgs(frame) local value = getManual(args, { "balley_smoo" }) if value then return "BALLEY_SMOO = " .. value end return "NO BALLEY_SMOO" end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local titleData = getTitleData(args) if not titleData then return nil end local text = titleData.name if titleData.genitive then text = text .. "<br/><small>(" .. titleData.genitive .. ")</small>" end return text end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) local images = getImages(args) if not images then return nil end local output = {} for _, image in ipairs(images) do table.insert(output, '[[Coadan:' .. image.image .. '|' .. image.width .. '|center]]' ) end return table.concat(output, " ") end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) local args = getArgs(frame) local captions = getCaptions(args) if not captions then return nil end return table.concat(captions, "<br/>") end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest and not capitalIsLargest(capital, largest) then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end return p rwzuymtj1vgi112et1eubzjhm9gygg8 392842 392841 2026-09-06T14:37:08Z MacTire02 219 ++ 392842 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getCountryName(args) local name = getManual(args, { "ennym", "ennym_çheerey", "ennym_çheer", "ennym çheerey", "ennym çheer" }) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getManual(args, { "ennym", "ennym_çheerey", "ennym_çheer", "ennym çheerey", "ennym çheer" }) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- TITLE -------------------------------------------------- local function getTitleData(args) local name = getCountryName(args) if not name then return nil end local genitive = getCountryGenitive(args) return { name = name, genitive = genitive } end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getImages(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end local images = {} if flag then table.insert(images, { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px" }) end if arms then table.insert(images, { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "125px" }) end if #images == 0 then return nil end return images end -------------------------------------------------- -- IMAGE CAPTIONS -------------------------------------------------- local function getCaptions(args) local flagCaption = getManual(args, { "fo-heidyl_brattagh" }) local armsCaption = getManual(args, { "fo-heidyl_armys", "fo-heidyl_cleinney", "fo-heidyl_cowrey" }) local captions = {} local images = getImages(args) if not images then return nil end local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if flag then table.insert(captions, flagCaption or "") end if arms then table.insert(captions, armsCaption or "") end return captions end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa", "jarroo_raa", "jarroo raa", "jarroo-raa_çheerey", "jarroo_raa_çheerey" }) local reference = getManual(args, { "imraa_jarroo-raa", "imraa_jarroo_raa", "imraa_jarroo raa", "imraa_jarroo-raa_çheerey", "imraa_jarroo_raa_çheerey" }) if motto and mw.ustring.lower(motto) == "none" then return nil end if motto then return { text = "“" .. motto .. "”", reference = reference and "<ref>" .. reference .. "</ref>" or nil } end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = '"' .. national .. '"', reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = '"' .. royal .. '"', reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = '"' .. other .. '"', reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then local title = normaliseCityName(capital) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = capital, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = normaliseCityName(city) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = city, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. normaliseCityName(city.text) .. "]]" end end local title = normaliseCityName(city.text) return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = '<div style="text-align:left;">' .. "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end label = label .. '</div>' return label end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then return makeCityLink(administrative) elseif largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TEMPORARY TEST -------------------------------------------------- function p.test_city(frame) local args = getArgs(frame) local value = getManual(args, { "balley_smoo" }) if value then return "BALLEY_SMOO = " .. value end return "NO BALLEY_SMOO" end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local titleData = getTitleData(args) if not titleData then return nil end local text = titleData.name if titleData.genitive then text = text .. "<br/><small>(" .. titleData.genitive .. ")</small>" end return text end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) local images = getImages(args) if not images then return nil end local output = {} for _, image in ipairs(images) do table.insert(output, '[[Coadan:' .. image.image .. '|' .. image.width .. '|center]]' ) end return table.concat(output, " ") end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) local args = getArgs(frame) local captions = getCaptions(args) if not captions then return nil end return table.concat(captions, "<br/>") end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest and not capitalIsLargest(capital, largest) then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end return p cjh2wcm0t6lsk0k7sxcoamkjkio8r97 392843 392842 2026-09-06T14:39:23Z MacTire02 219 prowal 392843 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getCountryName(args) local name = getManual(args, { "ennym", "ennym_çheerey", "ennym_çheer", "ennym çheerey", "ennym çheer" }) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getManual(args, { "ennym", "ennym_çheerey", "ennym_çheer", "ennym çheerey", "ennym çheer" }) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- TITLE -------------------------------------------------- local function getTitleData(args) local name = getCountryName(args) if not name then return nil end local genitive = getCountryGenitive(args) return { name = name, genitive = genitive } end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getImages(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end local images = {} if flag then table.insert(images, { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px" }) end if arms then table.insert(images, { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "125px" }) end if #images == 0 then return nil end return images end -------------------------------------------------- -- IMAGE CAPTIONS -------------------------------------------------- local function getCaptions(args) local flagCaption = getManual(args, { "fo-heidyl_brattagh" }) local armsCaption = getManual(args, { "fo-heidyl_armys", "fo-heidyl_cleinney", "fo-heidyl_cowrey" }) local captions = {} local images = getImages(args) if not images then return nil end local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if flag then table.insert(captions, flagCaption or "") end if arms then table.insert(captions, armsCaption or "") end return captions end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa", "jarroo_raa", "jarroo raa", "jarroo-raa_çheerey", "jarroo_raa_çheerey" }) local reference = getManual(args, { "imraa_jarroo-raa", "imraa_jarroo_raa", "imraa_jarroo raa", "imraa_jarroo-raa_çheerey", "imraa_jarroo_raa_çheerey" }) if motto and mw.ustring.lower(motto) == "none" then return nil end if motto then return { text = "“" .. motto .. "”", reference = reference and "<ref>" .. reference .. "</ref>" or nil } end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = '"' .. national .. '"', reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = '"' .. royal .. '"', reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = '"' .. other .. '"', reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local output = {} for key, value in pairs(args) do if value and mw.text.trim(value) ~= "" then table.insert(output, "[" .. tostring(key) .. "] = " .. mw.text.trim(value) ) end end if #output == 0 then return "NO SYMBOL ARGUMENTS" end return table.concat(output, "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then local title = normaliseCityName(capital) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = capital, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = normaliseCityName(city) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = city, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. normaliseCityName(city.text) .. "]]" end end local title = normaliseCityName(city.text) return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = '<div style="text-align:left;">' .. "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end label = label .. '</div>' return label end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then return makeCityLink(administrative) elseif largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TEMPORARY TEST -------------------------------------------------- function p.test_city(frame) local args = getArgs(frame) local value = getManual(args, { "balley_smoo" }) if value then return "BALLEY_SMOO = " .. value end return "NO BALLEY_SMOO" end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local output = {} for key, value in pairs(args) do if value and mw.text.trim(value) ~= "" then table.insert(output, "[" .. tostring(key) .. "] = " .. mw.text.trim(value) ) end end if #output == 0 then return "NO TITLE ARGUMENTS" end return table.concat(output, "<br/>") end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) local images = getImages(args) if not images then return nil end local output = {} for _, image in ipairs(images) do table.insert(output, '[[Coadan:' .. image.image .. '|' .. image.width .. '|center]]' ) end return table.concat(output, " ") end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) local args = getArgs(frame) local captions = getCaptions(args) if not captions then return nil end return table.concat(captions, "<br/>") end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest and not capitalIsLargest(capital, largest) then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end return p s0xgvzaj79uvha9o9cqxrzfy61934u3 392844 392843 2026-09-06T14:42:51Z MacTire02 219 er ash 392844 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getCountryName(args) local name = getManual(args, { "ennym", "ennym_çheerey", "ennym_çheer", "ennym çheerey", "ennym çheer" }) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getManual(args, { "ennym", "ennym_çheerey", "ennym_çheer", "ennym çheerey", "ennym çheer" }) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- TITLE -------------------------------------------------- local function getTitleData(args) local name = getCountryName(args) if not name then return nil end local genitive = getCountryGenitive(args) return { name = name, genitive = genitive } end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getImages(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end local images = {} if flag then table.insert(images, { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px" }) end if arms then table.insert(images, { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "125px" }) end if #images == 0 then return nil end return images end -------------------------------------------------- -- IMAGE CAPTIONS -------------------------------------------------- local function getCaptions(args) local flagCaption = getManual(args, { "fo-heidyl_brattagh" }) local armsCaption = getManual(args, { "fo-heidyl_armys", "fo-heidyl_cleinney", "fo-heidyl_cowrey" }) local captions = {} local images = getImages(args) if not images then return nil end local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if flag then table.insert(captions, flagCaption or "") end if arms then table.insert(captions, armsCaption or "") end return captions end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa", "jarroo_raa", "jarroo raa", "jarroo-raa_çheerey", "jarroo_raa_çheerey" }) local reference = getManual(args, { "imraa_jarroo-raa", "imraa_jarroo_raa", "imraa_jarroo raa", "imraa_jarroo-raa_çheerey", "imraa_jarroo_raa_çheerey" }) if motto and mw.ustring.lower(motto) == "none" then return nil end if motto then return { text = "“" .. motto .. "”", reference = reference and "<ref>" .. reference .. "</ref>" or nil } end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = '"' .. national .. '"', reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = '"' .. royal .. '"', reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = '"' .. other .. '"', reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then local title = normaliseCityName(capital) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = capital, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = normaliseCityName(city) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = city, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. normaliseCityName(city.text) .. "]]" end end local title = normaliseCityName(city.text) return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = '<div style="text-align:left;">' .. "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end label = label .. '</div>' return label end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then return makeCityLink(administrative) elseif largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TEMPORARY TEST -------------------------------------------------- function p.test_city(frame) local args = getArgs(frame) local value = getManual(args, { "balley_smoo" }) if value then return "BALLEY_SMOO = " .. value end return "NO BALLEY_SMOO" end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local titleData = getTitleData(args) if not titleData then return nil end local text = titleData.name if titleData.genitive then text = text .. "<br/><small>(" .. titleData.genitive .. ")</small>" end return text end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) local images = getImages(args) if not images then return nil end local output = {} for _, image in ipairs(images) do table.insert(output, '[[Coadan:' .. image.image .. '|' .. image.width .. '|center]]' ) end return table.concat(output, " ") end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) local args = getArgs(frame) local captions = getCaptions(args) if not captions then return nil end return table.concat(captions, "<br/>") end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest and not capitalIsLargest(capital, largest) then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end return p kck7ch9i4n0g5492lgup3jrjr7lddvm 392845 392844 2026-09-06T14:46:11Z MacTire02 219 ++ 392845 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- TITLE -------------------------------------------------- local function getTitleData(args) local name = getCountryName(args) if not name then return nil end local genitive = getCountryGenitive(args) return { name = name, genitive = genitive } end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getImages(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end local images = {} if flag then table.insert(images, { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px" }) end if arms then table.insert(images, { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "125px" }) end if #images == 0 then return nil end return images end -------------------------------------------------- -- IMAGE CAPTIONS -------------------------------------------------- local function getCaptions(args) local flagCaption = getManual(args, { "fo-heidyl_brattagh" }) local armsCaption = getManual(args, { "fo-heidyl_armys", "fo-heidyl_cleinney", "fo-heidyl_cowrey" }) local captions = {} local images = getImages(args) if not images then return nil end local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if flag then table.insert(captions, flagCaption or "") end if arms then table.insert(captions, armsCaption or "") end return captions end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto and mw.ustring.lower(motto) == "none" then return nil end if motto then return { text = "“" .. motto .. "”", reference = reference and "<ref>" .. reference .. "</ref>" or nil } end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = '"' .. national .. '"', reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = '"' .. royal .. '"', reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = '"' .. other .. '"', reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then local title = normaliseCityName(capital) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = capital, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = normaliseCityName(city) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = city, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. normaliseCityName(city.text) .. "]]" end end local title = normaliseCityName(city.text) return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = '<div style="text-align:left;">' .. "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end label = label .. '</div>' return label end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then return makeCityLink(administrative) elseif largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TEMPORARY TEST -------------------------------------------------- function p.test_city(frame) local args = getArgs(frame) local value = getManual(args, { "balley_smoo" }) if value then return "BALLEY_SMOO = " .. value end return "NO BALLEY_SMOO" end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local titleData = getTitleData(args) if not titleData then return nil end local text = titleData.name if titleData.genitive then text = text .. "<br/><small>(" .. titleData.genitive .. ")</small>" end return text end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) local images = getImages(args) if not images then return nil end local output = {} for _, image in ipairs(images) do table.insert(output, '[[Coadan:' .. image.image .. '|' .. image.width .. '|center]]' ) end return table.concat(output, " ") end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) local args = getArgs(frame) local captions = getCaptions(args) if not captions then return nil end return table.concat(captions, "<br/>") end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest and not capitalIsLargest(capital, largest) then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end return p kvnhz4qbv30mbli1gi0yjdzrm5iyjef 392846 392845 2026-09-06T14:49:12Z MacTire02 219 ++ 392846 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getCountryName(args) local name = getManual(args, { "ennym_gienneydagh" }) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- TITLE -------------------------------------------------- local function getTitleData(args) local name = getCountryName(args) if not name then return nil end local genitive = getCountryGenitive(args) return { name = name, genitive = genitive } end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getImages(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end local images = {} if flag then table.insert(images, { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px" }) end if arms then table.insert(images, { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "125px" }) end if #images == 0 then return nil end return images end -------------------------------------------------- -- IMAGE CAPTIONS -------------------------------------------------- local function getCaptions(args) local flagCaption = getManual(args, { "fo-heidyl_brattagh" }) local armsCaption = getManual(args, { "fo-heidyl_armys", "fo-heidyl_cleinney", "fo-heidyl_cowrey" }) local captions = {} local images = getImages(args) if not images then return nil end local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if flag then table.insert(captions, flagCaption or "") end if arms then table.insert(captions, armsCaption or "") end return captions end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto and mw.ustring.lower(motto) == "none" then return nil end if motto then return { text = "“" .. motto .. "”", reference = reference and "<ref>" .. reference .. "</ref>" or nil } end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = '"' .. national .. '"', reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = '"' .. royal .. '"', reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = '"' .. other .. '"', reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then local title = normaliseCityName(capital) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = capital, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = normaliseCityName(city) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = city, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. normaliseCityName(city.text) .. "]]" end end local title = normaliseCityName(city.text) return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = '<div style="text-align:left;">' .. "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end label = label .. '</div>' return label end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then return makeCityLink(administrative) elseif largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TEMPORARY TEST -------------------------------------------------- function p.test_city(frame) local args = getArgs(frame) local value = getManual(args, { "balley_smoo" }) if value then return "BALLEY_SMOO = " .. value end return "NO BALLEY_SMOO" end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local titleData = getTitleData(args) if not titleData then return nil end return titleData.name end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) local images = getImages(args) if not images then return nil end local output = {} for _, image in ipairs(images) do table.insert(output, '[[Coadan:' .. image.image .. '|' .. image.width .. '|center]]' ) end return table.concat(output, " ") end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) local args = getArgs(frame) local captions = getCaptions(args) if not captions then return nil end return table.concat(captions, "<br/>") end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest and not capitalIsLargest(capital, largest) then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end return p an52hulbuah6qgi7g7t0b69zfu5uehm 392847 392846 2026-09-06T15:21:55Z MacTire02 219 prowal reddyn elley 392847 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- TITLE -------------------------------------------------- -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getImages(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end local images = {} if flag then table.insert(images, { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px" }) end if arms then table.insert(images, { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "125px" }) end if #images == 0 then return nil end return images end -------------------------------------------------- -- IMAGE CAPTIONS -------------------------------------------------- local function getCaptions(args) local images = getImages(args) if not images then return nil end local name = getCountryGenitive(args) if not name then name = "" end local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end local captions = {} if flag then local label = getManual(args, { "fo-heidyl_brattagh" }) or "Brattagh" table.insert(captions, "[[Brattagh " .. name .. "|" .. label .. "]]" ) end if arms then local kind = getManual(args, { "art_sorçh_cowrey" }) or getManual(args, { "sorçh_cowrey" }) or "Armys" local label = getManual(args, { "sorçh_cowrey" }) or "Armys" table.insert(captions, "[[" .. kind .. " " .. name .. "|" .. label .. "]]" ) end return captions end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto and mw.ustring.lower(motto) == "none" then return nil end if motto then return { text = "“" .. motto .. "”", reference = reference and "<ref>" .. reference .. "</ref>" or nil } end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = '"' .. national .. '"', reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = '"' .. royal .. '"', reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = '"' .. other .. '"', reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then local title = normaliseCityName(capital) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = capital, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then local title = normaliseCityName(centre) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = centre, entity = entity, reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = normaliseCityName(city) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = city, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. normaliseCityName(city.text) .. "]]" end end local title = normaliseCityName(city.text) return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = '<div style="text-align:left;">' .. "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end label = label .. '</div>' return label end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local native = getManual(args, { "ennym_dooghyssagh" }) local longform = getManual(args, { "ennym_foddey_cadjincliaghtagh" }) local common = getCountryName(args) if not native then local officialNames = getOfficialNames() local match = nil for _, entry in ipairs(officialNames) do if entry.language == "gv" then match = entry.text break end end if not match and officialNames[1] then match = officialNames[1].text end native = match end local parts = {} if native then table.insert(parts, native) end if longform or common then table.insert(parts, '<div style="padding-top:0.25em;">' .. (longform or common) .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) local images = getImages(args) if not images then return nil end if #images == 1 then local image = images[1] return '[[Coadan:' .. image.image .. '|' .. image.width .. '|center]]' end local cells = {} for _, image in ipairs(images) do table.insert(cells, '<td align="center" style="width:auto; vertical-align:middle;">[[Coadan:' .. image.image .. '|' .. image.width .. ']]</td>' ) end return '<table align="center" style="width:100%; background:none;"><tr>' .. table.concat(cells) .. '</tr></table>' end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) local args = getArgs(frame) local captions = getCaptions(args) if not captions then return nil end return table.concat(captions, "<br/>") end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest and not capitalIsLargest(capital, largest) then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end return p 8l9u4b67fw06no9inh801x6kpmhq1xq 392851 392847 2026-09-06T15:43:25Z MacTire02 219 ++ 392851 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- TITLE -------------------------------------------------- -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getFlagArmsData(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if not flag and not arms then return nil end local name = getCountryGenitive(args) or "" local data = {} if flag then data.flag = { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px", link = "Brattagh " .. name, label = getManual(args, { "fo-heidyl_brattagh" }) or "Brattagh" } end if arms then local kind = getManual(args, { "art_sorçh_cowrey" }) or getManual(args, { "sorçh_cowrey" }) or "Armys" data.arms = { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "85px", link = kind .. " " .. name, label = getManual(args, { "sorçh_cowrey" }) or "Armys" } end return data end -------------------------------------------------- -- FLAG / ARMS BLOCK (images + per-column captions) -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} if data.flag then table.insert(imageCells, '<td align="center" style="' .. (data.arms and "width:58%; " or "") .. 'vertical-align:middle;">[[Coadan:' .. data.flag.image .. '|' .. data.flag.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.flag.link .. '|' .. data.flag.label .. ']]</small></td>' ) end if data.arms then table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">[[Coadan:' .. data.arms.image .. '|' .. data.arms.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.arms.link .. '|' .. data.arms.label .. ']]</small></td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto and mw.ustring.lower(motto) == "none" then return nil end if motto then return { text = "“" .. motto .. "”", reference = reference and "<ref>" .. reference .. "</ref>" or nil } end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = '"' .. national .. '"', reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = '"' .. royal .. '"', reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = '"' .. other .. '"', reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then local title = normaliseCityName(capital) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = capital, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then local title = normaliseCityName(centre) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = centre, entity = entity, reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = normaliseCityName(city) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = city, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. normaliseCityName(city.text) .. "]]" end end local title = normaliseCityName(city.text) return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = '<div style="text-align:left;">' .. "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end label = label .. '</div>' return label end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local native = getManual(args, { "ennym_dooghyssagh" }) local longform = getManual(args, { "ennym_foddey_cadjincliaghtagh" }) local common = getCountryName(args) if not native then local officialNames = getOfficialNames() for _, entry in ipairs(officialNames) do if entry.language == "gv" then native = entry.text break end end end local parts = {} if native then table.insert(parts, native) end if longform or common then table.insert(parts, '<div style="padding-top:0.25em;">' .. (longform or common) .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT (deprecated - captions are now -- embedded per-column inside p.images/buildFlagArmsBlock) -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest and not capitalIsLargest(capital, largest) then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN (assembles the whole infobox table directly, -- reusing the legacy table's classes/structure so -- borders and dividers render the same way) -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} -- Header / country name do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="mergedtoprow fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center;">' .. titleContent .. '</th></tr>' ) end end -- Flag / arms do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr class="mergedtoprow"><td colspan="2" ' .. 'align="center" style="padding:0.5em 0;">' .. flagArms .. '</td></tr>' ) end end -- Motto / anthem do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -- Locator map do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr class="mergedtoprow"><td colspan="2">' .. map .. '</td></tr>' ) end end -- Capital / largest city / administrative centre do local cityLabel = p.city_label(frame) local cityData = p.city_data(frame) if cityLabel and cityData then table.insert(rows, '<tr class="mergedtoprow"><th>' .. cityLabel .. '</th><td>' .. cityData .. '</td></tr>' ) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="width:23em; margin-top:0.75em;">' .. table.concat(rows) .. '</table>' end return p 9lnjbjkmzn875luq5cy352dc6vjt0j5 392853 392851 2026-09-06T15:54:47Z MacTire02 219 ++ 392853 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- TITLE -------------------------------------------------- -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getFlagArmsData(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if not flag and not arms then return nil end local name = getCountryGenitive(args) or "" local data = {} if flag then data.flag = { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px", link = "Brattagh " .. name, label = getManual(args, { "fo-heidyl_brattagh" }) or "Brattagh" } end if arms then local kind = getManual(args, { "art_sorçh_cowrey" }) or getManual(args, { "sorçh_cowrey" }) or "Armys" data.arms = { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "85px", link = kind .. " " .. name, label = getManual(args, { "sorçh_cowrey" }) or "Armys" } end return data end -------------------------------------------------- -- FLAG / ARMS BLOCK (images + per-column captions) -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} if data.flag then table.insert(imageCells, '<td align="center" style="' .. (data.arms and "width:58%; " or "") .. 'vertical-align:middle;">[[Coadan:' .. data.flag.image .. '|' .. data.flag.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.flag.link .. '|' .. data.flag.label .. ']]</small></td>' ) end if data.arms then table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">[[Coadan:' .. data.arms.image .. '|' .. data.arms.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.arms.link .. '|' .. data.arms.label .. ']]</small></td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto and mw.ustring.lower(motto) == "none" then return nil end if motto then return { text = "“" .. motto .. "”", reference = reference and "<ref>" .. reference .. "</ref>" or nil } end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = '"' .. national .. '"', reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = '"' .. royal .. '"', reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = '"' .. other .. '"', reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then local title = normaliseCityName(capital) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = capital, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then local title = normaliseCityName(centre) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = centre, entity = entity, reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = normaliseCityName(city) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = city, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. normaliseCityName(city.text) .. "]]" end end local title = normaliseCityName(city.text) return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = '<div style="text-align:left;">' .. "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end label = label .. '</div>' return label end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) -- TOP: the Manx working name used as this wiki's article -- title. Falls back to the page title itself. (Not the -- genitive-lookup parameters like ennym_gienneydagh, which -- serve a different purpose - see Enmyn çheerey.) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end -- BOTTOM: the native name (endonym) - ennym_dooghyssagh -- literally means "native name" - or an explicit long-form -- override, or failing both, a Wikidata (P1448) fallback -- with an automatic language gloss, e.g. -- "United States of America (Baarle)". local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text local langName = getLanguageName(entry.language) if langName then bottom = bottom .. " ([[" .. langName .. "]])" end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, top) end if bottom then table.insert(parts, '<div style="padding-top:0.25em;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT (deprecated - captions are now -- embedded per-column inside p.images/buildFlagArmsBlock) -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest and not capitalIsLargest(capital, largest) then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN (assembles the whole infobox table directly, -- reusing the legacy table's classes/structure so -- borders and dividers render the same way) -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -- Header / country name do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center;">' .. titleContent .. '</th></tr>' ) end end -- Flag / arms do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -- Motto / anthem do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -- Locator map do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -- Capital / largest city / administrative centre do local cityLabel = p.city_label(frame) local cityData = p.city_data(frame) if cityLabel and cityData then table.insert(rows, '<tr><th style="' .. dividerStyle .. '">' .. cityLabel .. '</th><td style="' .. dividerStyle .. '">' .. cityData .. '</td></tr>' ) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em;">' .. table.concat(rows) .. '</table>' end return p fep0kt83gtszgkq50jd0cfovt7vj3cb 392854 392853 2026-09-06T16:11:49Z MacTire02 219 prowal 392854 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- TITLE -------------------------------------------------- -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getFlagArmsData(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if not flag and not arms then return nil end local name = getCountryGenitive(args) or "" local data = {} if flag then data.flag = { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px", link = "Brattagh " .. name, label = getManual(args, { "fo-heidyl_brattagh" }) or "Brattagh" } end if arms then local kind = getManual(args, { "art_sorçh_cowrey" }) or getManual(args, { "sorçh_cowrey" }) or "Armys" data.arms = { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "85px", link = kind .. " " .. name, label = getManual(args, { "sorçh_cowrey" }) or "Armys" } end return data end -------------------------------------------------- -- FLAG / ARMS BLOCK (images + per-column captions) -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} if data.flag then table.insert(imageCells, '<td align="center" style="' .. (data.arms and "width:58%; " or "") .. 'vertical-align:middle;">[[Coadan:' .. data.flag.image .. '|' .. data.flag.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.flag.link .. '|' .. data.flag.label .. ']]</small></td>' ) end if data.arms then table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">[[Coadan:' .. data.arms.image .. '|' .. data.arms.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.arms.link .. '|' .. data.arms.label .. ']]</small></td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto and mw.ustring.lower(motto) == "none" then return nil end if motto then return { text = "“" .. motto .. "”", reference = reference and "<ref>" .. reference .. "</ref>" or nil } end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = '"' .. national .. '"', reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = '"' .. royal .. '"', reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = '"' .. other .. '"', reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then local title = normaliseCityName(capital) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = capital, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then local title = normaliseCityName(centre) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = centre, entity = entity, reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = normaliseCityName(city) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = city, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. normaliseCityName(city.text) .. "]]" end end local title = normaliseCityName(city.text) return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = '<div style="text-align:left;">' .. "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end label = label .. '</div>' return label end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT (deprecated - captions are now -- embedded per-column inside p.images/buildFlagArmsBlock) -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest and not capitalIsLargest(capital, largest) then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN (assembles the whole infobox table directly, -- reusing the legacy table's classes/structure so -- borders and dividers render the same way) -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -- Header / country name do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center;">' .. titleContent .. '</th></tr>' ) end end -- Flag / arms do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -- Motto / anthem do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -- Locator map do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -- Capital / largest city / administrative centre do local cityLabel = p.city_label(frame) local cityData = p.city_data(frame) if cityLabel and cityData then table.insert(rows, '<tr><th style="' .. dividerStyle .. '">' .. cityLabel .. '</th><td style="' .. dividerStyle .. '">' .. cityData .. '</td></tr>' ) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em;">' .. table.concat(rows) .. '</table>' end return p 9ten1lnjyfjkql8oetmd5f3wtvjnd6g 392855 392854 2026-09-06T16:13:06Z MacTire02 219 ++ 392855 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- TITLE -------------------------------------------------- -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getFlagArmsData(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if not flag and not arms then return nil end local name = getCountryGenitive(args) or "" local data = {} if flag then data.flag = { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px", link = "Brattagh " .. name, label = getManual(args, { "fo-heidyl_brattagh" }) or "Brattagh" } end if arms then local kind = getManual(args, { "art_sorçh_cowrey" }) or getManual(args, { "sorçh_cowrey" }) or "Armys" data.arms = { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "85px", link = kind .. " " .. name, label = getManual(args, { "sorçh_cowrey" }) or "Armys" } end return data end -------------------------------------------------- -- FLAG / ARMS BLOCK (images + per-column captions) -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} if data.flag then table.insert(imageCells, '<td align="center" style="' .. (data.arms and "width:58%; " or "") .. 'vertical-align:middle;">[[Coadan:' .. data.flag.image .. '|' .. data.flag.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.flag.link .. '|' .. data.flag.label .. ']]</small></td>' ) end if data.arms then table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">[[Coadan:' .. data.arms.image .. '|' .. data.arms.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.arms.link .. '|' .. data.arms.label .. ']]</small></td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto and mw.ustring.lower(motto) == "none" then return nil end if motto then return { text = "“" .. motto .. "”", reference = reference and "<ref>" .. reference .. "</ref>" or nil } end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = '"' .. national .. '"', reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = '"' .. royal .. '"', reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = '"' .. other .. '"', reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then local title = normaliseCityName(capital) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = capital, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then local title = normaliseCityName(centre) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = centre, entity = entity, reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = normaliseCityName(city) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = city, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. normaliseCityName(city.text) .. "]]" end end local title = normaliseCityName(city.text) return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = '<div style="text-align:left;">' .. "[[Preeu-valley|" .. (labels.capital or "Preeu-valley") .. "]]" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end label = label .. '</div>' return label end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT (deprecated - captions are now -- embedded per-column inside p.images/buildFlagArmsBlock) -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest and not capitalIsLargest(capital, largest) then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN (assembles the whole infobox table directly, -- reusing the legacy table's classes/structure so -- borders and dividers render the same way) -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -- Header / country name do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -- Flag / arms do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -- Motto / anthem do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -- Locator map do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -- Capital / largest city / administrative centre do local cityLabel = p.city_label(frame) local cityData = p.city_data(frame) if cityLabel and cityData then table.insert(rows, '<tr><th style="' .. dividerStyle .. '">' .. cityLabel .. '</th><td style="' .. dividerStyle .. '">' .. cityData .. '</td></tr>' ) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em;">' .. table.concat(rows) .. '</table>' end return p q4d8lsbe5b3ke1vlx23n9d08ntn7ayw 392856 392855 2026-09-06T16:13:55Z MacTire02 219 ++ 392856 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- TITLE -------------------------------------------------- -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getFlagArmsData(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if not flag and not arms then return nil end local name = getCountryGenitive(args) or "" local data = {} if flag then data.flag = { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px", link = "Brattagh " .. name, label = getManual(args, { "fo-heidyl_brattagh" }) or "Brattagh" } end if arms then local kind = getManual(args, { "art_sorçh_cowrey" }) or getManual(args, { "sorçh_cowrey" }) or "Armys" data.arms = { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "85px", link = kind .. " " .. name, label = getManual(args, { "sorçh_cowrey" }) or "Armys" } end return data end -------------------------------------------------- -- FLAG / ARMS BLOCK (images + per-column captions) -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} if data.flag then table.insert(imageCells, '<td align="center" style="' .. (data.arms and "width:58%; " or "") .. 'vertical-align:middle;">[[Coadan:' .. data.flag.image .. '|' .. data.flag.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.flag.link .. '|' .. data.flag.label .. ']]</small></td>' ) end if data.arms then table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">[[Coadan:' .. data.arms.image .. '|' .. data.arms.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.arms.link .. '|' .. data.arms.label .. ']]</small></td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto and mw.ustring.lower(motto) == "none" then return nil end if motto then return { text = "“" .. motto .. "”", reference = reference and "<ref>" .. reference .. "</ref>" or nil } end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = '"' .. national .. '"', reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = '"' .. royal .. '"', reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = '"' .. other .. '"', reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then local title = normaliseCityName(capital) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = capital, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then local title = normaliseCityName(centre) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = centre, entity = entity, reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = normaliseCityName(city) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = city, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. normaliseCityName(city.text) .. "]]" end end local title = normaliseCityName(city.text) return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT (deprecated - captions are now -- embedded per-column inside p.images/buildFlagArmsBlock) -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest and not capitalIsLargest(capital, largest) then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN (assembles the whole infobox table directly, -- reusing the legacy table's classes/structure so -- borders and dividers render the same way) -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -- Header / country name do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -- Flag / arms do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -- Motto / anthem do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -- Locator map do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -- Capital / largest city / administrative centre do local cityLabel = p.city_label(frame) local cityData = p.city_data(frame) if cityLabel and cityData then table.insert(rows, '<tr><th style="' .. dividerStyle .. '">' .. cityLabel .. '</th><td style="' .. dividerStyle .. '">' .. cityData .. '</td></tr>' ) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em;">' .. table.concat(rows) .. '</table>' end return p 4ua6xfe2ovbgz3494nj9gvoddwxvv8k 392857 392856 2026-09-06T16:16:49Z MacTire02 219 ++ 392857 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- TITLE -------------------------------------------------- -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getFlagArmsData(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if not flag and not arms then return nil end local name = getCountryGenitive(args) or "" local data = {} if flag then data.flag = { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px", link = "Brattagh " .. name, label = getManual(args, { "fo-heidyl_brattagh" }) or "Brattagh" } end if arms then local kind = getManual(args, { "art_sorçh_cowrey" }) or getManual(args, { "sorçh_cowrey" }) or "Armys" data.arms = { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "85px", link = kind .. " " .. name, label = getManual(args, { "sorçh_cowrey" }) or "Armys" } end return data end -------------------------------------------------- -- FLAG / ARMS BLOCK (images + per-column captions) -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} if data.flag then table.insert(imageCells, '<td align="center" style="' .. (data.arms and "width:58%; " or "") .. 'vertical-align:middle;">[[Coadan:' .. data.flag.image .. '|' .. data.flag.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.flag.link .. '|' .. data.flag.label .. ']]</small></td>' ) end if data.arms then table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">[[Coadan:' .. data.arms.image .. '|' .. data.arms.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.arms.link .. '|' .. data.arms.label .. ']]</small></td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = "“" .. motto .. "”", reference = reference and "<ref>" .. reference .. "</ref>" or nil } end -- Wikidata P1451 = motto local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = "“" .. value.text .. "”", reference = getWikidataReference(statement) } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = '"' .. national .. '"', reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = '"' .. royal .. '"', reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = '"' .. other .. '"', reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then local title = normaliseCityName(capital) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = capital, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then local title = normaliseCityName(centre) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = centre, entity = entity, reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = normaliseCityName(city) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = city, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. normaliseCityName(city.text) .. "]]" end end local title = normaliseCityName(city.text) return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT (deprecated - captions are now -- embedded per-column inside p.images/buildFlagArmsBlock) -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest and not capitalIsLargest(capital, largest) then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN (assembles the whole infobox table directly, -- reusing the legacy table's classes/structure so -- borders and dividers render the same way) -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -- Header / country name do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -- Flag / arms do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -- Motto / anthem do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -- Locator map do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -- Capital / largest city / administrative centre do local cityLabel = p.city_label(frame) local cityData = p.city_data(frame) if cityLabel and cityData then table.insert(rows, '<tr><th style="' .. dividerStyle .. ' vertical-align:top; white-space:nowrap; text-align:left;">' .. cityLabel .. '</th><td style="' .. dividerStyle .. ' vertical-align:top;">' .. cityData .. '</td></tr>' ) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em;">' .. table.concat(rows) .. '</table>' end return p gjmdqona6ezi2cdj1orz88hdreqx09i 392859 392857 2026-09-06T16:56:59Z MacTire02 219 ++ 392859 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- TITLE -------------------------------------------------- -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getFlagArmsData(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if not flag and not arms then return nil end local name = getCountryGenitive(args) or "" local data = {} if flag then data.flag = { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px", link = "Brattagh " .. name, label = getManual(args, { "fo-heidyl_brattagh" }) or "Brattagh" } end if arms then local kind = getManual(args, { "art_sorçh_cowrey" }) or getManual(args, { "sorçh_cowrey" }) or "Armys" data.arms = { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "85px", link = kind .. " " .. name, label = getManual(args, { "sorçh_cowrey" }) or "Armys" } end return data end -------------------------------------------------- -- FLAG / ARMS BLOCK (images + per-column captions) -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} if data.flag then table.insert(imageCells, '<td align="center" style="' .. (data.arms and "width:58%; " or "") .. 'vertical-align:middle;">[[Coadan:' .. data.flag.image .. '|' .. data.flag.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.flag.link .. '|' .. data.flag.label .. ']]</small></td>' ) end if data.arms then table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">[[Coadan:' .. data.arms.image .. '|' .. data.arms.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.arms.link .. '|' .. data.arms.label .. ']]</small></td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = "“" .. motto .. "”", reference = reference and "<ref>" .. reference .. "</ref>" or nil } end -- Wikidata P1451 = motto local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = "“" .. value.text .. "”", reference = getWikidataReference(statement) } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = '"' .. national .. '"', reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = '"' .. royal .. '"', reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = '"' .. other .. '"', reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then local title = normaliseCityName(capital) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = capital, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then local title = normaliseCityName(centre) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = centre, entity = entity, reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = normaliseCityName(city) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = city, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. normaliseCityName(city.text) .. "]]" end end local title = normaliseCityName(city.text) return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT (deprecated - captions are now -- embedded per-column inside p.images/buildFlagArmsBlock) -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest and not capitalIsLargest(capital, largest) then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN (assembles the whole infobox table directly, -- reusing the legacy table's classes/structure so -- borders and dividers render the same way) -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -- Header / country name do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -- Flag / arms do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -- Motto / anthem do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -- Locator map do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -- Capital / largest city / administrative centre do local cityLabel = p.city_label(frame) local cityData = p.city_data(frame) if cityLabel and cityData then table.insert(rows, '<tr><th style="' .. dividerStyle .. ' vertical-align:top; white-space:nowrap; text-align:left;">' .. cityLabel .. '</th><td style="' .. dividerStyle .. ' vertical-align:top;">' .. cityData .. '</td></tr>' ) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p jvruzw6ax58jhx6p9vfl6vf8op3h2k2 392861 392859 2026-09-06T17:01:45Z MacTire02 219 prowal 392861 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- TITLE -------------------------------------------------- -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getFlagArmsData(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if not flag and not arms then return nil end local name = getCountryGenitive(args) or "" local data = {} if flag then data.flag = { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px", link = "Brattagh " .. name, label = getManual(args, { "fo-heidyl_brattagh" }) or "Brattagh" } end if arms then local kind = getManual(args, { "art_sorçh_cowrey" }) or getManual(args, { "sorçh_cowrey" }) or "Armys" data.arms = { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "85px", link = kind .. " " .. name, label = getManual(args, { "sorçh_cowrey" }) or "Armys" } end return data end -------------------------------------------------- -- FLAG / ARMS BLOCK (images + per-column captions) -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} if data.flag then table.insert(imageCells, '<td align="center" style="' .. (data.arms and "width:58%; " or "") .. 'vertical-align:middle;">[[Coadan:' .. data.flag.image .. '|' .. data.flag.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.flag.link .. '|' .. data.flag.label .. ']]</small></td>' ) end if data.arms then table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">[[Coadan:' .. data.arms.image .. '|' .. data.arms.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.arms.link .. '|' .. data.arms.label .. ']]</small></td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = '"' .. motto .. '"', reference = reference and "<ref>" .. reference .. "</ref>" or nil } end -- Wikidata P1451 = motto local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = "“" .. value.text .. "”", reference = getWikidataReference(statement) } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = '"' .. national .. '"', reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = '"' .. royal .. '"', reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = '"' .. other .. '"', reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then local title = normaliseCityName(capital) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = capital, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then local title = normaliseCityName(centre) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = centre, entity = entity, reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = normaliseCityName(city) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = city, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. normaliseCityName(city.text) .. "]]" end end local title = normaliseCityName(city.text) return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT (deprecated - captions are now -- embedded per-column inside p.images/buildFlagArmsBlock) -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest and not capitalIsLargest(capital, largest) then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN (assembles the whole infobox table directly, -- reusing the legacy table's classes/structure so -- borders and dividers render the same way) -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -- Header / country name do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -- Flag / arms do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -- Motto / anthem do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -- Locator map do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -- Capital / largest city / administrative centre do local cityLabel = p.city_label(frame) local cityData = p.city_data(frame) if cityLabel and cityData then table.insert(rows, '<tr><th style="' .. dividerStyle .. ' vertical-align:top; white-space:nowrap; text-align:left;">' .. cityLabel .. '</th><td style="' .. dividerStyle .. ' vertical-align:top;">' .. cityData .. '</td></tr>' ) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p ji2l8ql6duds4etoxqe4875lau209z5 392862 392861 2026-09-06T17:08:04Z MacTire02 219 prowal 392862 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- TITLE -------------------------------------------------- -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getFlagArmsData(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if not flag and not arms then return nil end local name = getCountryGenitive(args) or "" local data = {} if flag then data.flag = { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px", link = "Brattagh " .. name, label = getManual(args, { "fo-heidyl_brattagh" }) or "Brattagh" } end if arms then local kind = getManual(args, { "art_sorçh_cowrey" }) or getManual(args, { "sorçh_cowrey" }) or "Armys" data.arms = { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "85px", link = kind .. " " .. name, label = getManual(args, { "sorçh_cowrey" }) or "Armys" } end return data end -------------------------------------------------- -- FLAG / ARMS BLOCK (images + per-column captions) -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} if data.flag then table.insert(imageCells, '<td align="center" style="' .. (data.arms and "width:58%; " or "") .. 'vertical-align:middle;">[[Coadan:' .. data.flag.image .. '|' .. data.flag.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.flag.link .. '|' .. data.flag.label .. ']]</small></td>' ) end if data.arms then table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">[[Coadan:' .. data.arms.image .. '|' .. data.arms.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.arms.link .. '|' .. data.arms.label .. ']]</small></td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = '"' .. motto .. '"', reference = reference and "<ref>" .. reference .. "</ref>" or nil } end -- Wikidata P1451 = motto local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = "“" .. value.text .. "”", reference = getWikidataReference(statement) } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = '"' .. national .. '"', reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = '"' .. royal .. '"', reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = '"' .. other .. '"', reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then local title = normaliseCityName(capital) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = capital, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then local title = normaliseCityName(centre) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = centre, entity = entity, reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = normaliseCityName(city) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = city, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. normaliseCityName(city.text) .. "]]" end end local title = normaliseCityName(city.text) return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT (deprecated - captions are now -- embedded per-column inside p.images/buildFlagArmsBlock) -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest and not capitalIsLargest(capital, largest) then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN (assembles the whole infobox table directly, -- reusing the legacy table's classes/structure so -- borders and dividers render the same way) -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -- Header / country name do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -- Flag / arms do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -- Motto / anthem do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -- Locator map do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -- Capital / largest city / administrative centre do local cityLabel = p.city_label(frame) local cityData = p.city_data(frame) if cityLabel and cityData then table.insert(rows, '<tr><th style="' .. dividerStyle .. ' vertical-align:top; white-space:nowrap; text-align:left;">' .. cityLabel .. '</th><td style="' .. dividerStyle .. ' vertical-align:top;">' .. cityData .. '</td></tr>' ) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p hnozhb7j9rdlbgpelji49894q1b77r5 392863 392862 2026-09-06T17:12:45Z MacTire02 219 goaill cowraghyn aaraa magh 392863 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- TITLE -------------------------------------------------- -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getFlagArmsData(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if not flag and not arms then return nil end local name = getCountryGenitive(args) or "" local data = {} if flag then data.flag = { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px", link = "Brattagh " .. name, label = getManual(args, { "fo-heidyl_brattagh" }) or "Brattagh" } end if arms then local kind = getManual(args, { "art_sorçh_cowrey" }) or getManual(args, { "sorçh_cowrey" }) or "Armys" data.arms = { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "85px", link = kind .. " " .. name, label = getManual(args, { "sorçh_cowrey" }) or "Armys" } end return data end -------------------------------------------------- -- FLAG / ARMS BLOCK (images + per-column captions) -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} if data.flag then table.insert(imageCells, '<td align="center" style="' .. (data.arms and "width:58%; " or "") .. 'vertical-align:middle;">[[Coadan:' .. data.flag.image .. '|' .. data.flag.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.flag.link .. '|' .. data.flag.label .. ']]</small></td>' ) end if data.arms then table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">[[Coadan:' .. data.arms.image .. '|' .. data.arms.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.arms.link .. '|' .. data.arms.label .. ']]</small></td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = '"' .. motto .. '"', reference = reference and "<ref>" .. reference .. "</ref>" or nil } end -- Wikidata P1451 = motto local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = "“" .. value.text .. "”", reference = getWikidataReference(statement) } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then local title = normaliseCityName(capital) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = capital, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then local title = normaliseCityName(centre) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = centre, entity = entity, reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = normaliseCityName(city) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = city, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. normaliseCityName(city.text) .. "]]" end end local title = normaliseCityName(city.text) return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT (deprecated - captions are now -- embedded per-column inside p.images/buildFlagArmsBlock) -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest and not capitalIsLargest(capital, largest) then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN (assembles the whole infobox table directly, -- reusing the legacy table's classes/structure so -- borders and dividers render the same way) -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -- Header / country name do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -- Flag / arms do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -- Motto / anthem do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -- Locator map do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -- Capital / largest city / administrative centre do local cityLabel = p.city_label(frame) local cityData = p.city_data(frame) if cityLabel and cityData then table.insert(rows, '<tr><th style="' .. dividerStyle .. ' vertical-align:top; white-space:nowrap; text-align:left;">' .. cityLabel .. '</th><td style="' .. dividerStyle .. ' vertical-align:top;">' .. cityData .. '</td></tr>' ) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p dtbflaszce5gtbhqg2q02hrjjoprrdz 392864 392863 2026-09-06T18:48:44Z MacTire02 219 ++ 392864 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- TITLE -------------------------------------------------- -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getFlagArmsData(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if not flag and not arms then return nil end local name = getCountryGenitive(args) or "" local data = {} if flag then data.flag = { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px", link = "Brattagh " .. name, label = getManual(args, { "fo-heidyl_brattagh" }) or "Brattagh" } end if arms then local kind = getManual(args, { "art_sorçh_cowrey" }) or getManual(args, { "sorçh_cowrey" }) or "Armys" data.arms = { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "85px", link = kind .. " " .. name, label = getManual(args, { "sorçh_cowrey" }) or "Armys" } end return data end -------------------------------------------------- -- FLAG / ARMS BLOCK (images + per-column captions) -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} if data.flag then table.insert(imageCells, '<td align="center" style="' .. (data.arms and "width:58%; " or "") .. 'vertical-align:middle;">[[Coadan:' .. data.flag.image .. '|' .. data.flag.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.flag.link .. '|' .. data.flag.label .. ']]</small></td>' ) end if data.arms then table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">[[Coadan:' .. data.arms.image .. '|' .. data.arms.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.arms.link .. '|' .. data.arms.label .. ']]</small></td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = '"' .. motto .. '"', reference = reference and "<ref>" .. reference .. "</ref>" or nil } end -- Wikidata P1451 = motto local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = "“" .. value.text .. "”", reference = getWikidataReference(statement) } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then local title = normaliseCityName(capital) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = capital, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then local title = normaliseCityName(centre) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = centre, entity = entity, reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = normaliseCityName(city) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = city, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. normaliseCityName(city.text) .. "]]" end end local title = normaliseCityName(city.text) return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT (deprecated - captions are now -- embedded per-column inside p.images/buildFlagArmsBlock) -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest and not capitalIsLargest(capital, largest) then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN (assembles the whole infobox table directly, -- reusing the legacy table's classes/structure so -- borders and dividers render the same way) -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -- Header / country name do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -- Flag / arms do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -- Motto / anthem do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -- Locator map do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -- Capital / largest city / administrative centre do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels -- Capital if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. dividerStyle .. ' vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. dividerStyle .. ' vertical-align:top;">' .. text .. '</td></tr>' ) end -- Administrative centre if administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. dividerStyle .. ' vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. dividerStyle .. ' vertical-align:top;">' .. text .. '</td></tr>' ) end -- Largest city if largest and not capitalIsLargest(capital, largest) then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. dividerStyle .. ' vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. dividerStyle .. ' vertical-align:top;">' .. text .. '</td></tr>' ) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p h8h1fprk94wvzh5gwl90xr9ie42139w 392865 392864 2026-09-06T18:50:53Z MacTire02 219 ++ 392865 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- TITLE -------------------------------------------------- -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getFlagArmsData(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if not flag and not arms then return nil end local name = getCountryGenitive(args) or "" local data = {} if flag then data.flag = { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px", link = "Brattagh " .. name, label = getManual(args, { "fo-heidyl_brattagh" }) or "Brattagh" } end if arms then local kind = getManual(args, { "art_sorçh_cowrey" }) or getManual(args, { "sorçh_cowrey" }) or "Armys" data.arms = { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "85px", link = kind .. " " .. name, label = getManual(args, { "sorçh_cowrey" }) or "Armys" } end return data end -------------------------------------------------- -- FLAG / ARMS BLOCK (images + per-column captions) -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} if data.flag then table.insert(imageCells, '<td align="center" style="' .. (data.arms and "width:58%; " or "") .. 'vertical-align:middle;">[[Coadan:' .. data.flag.image .. '|' .. data.flag.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.flag.link .. '|' .. data.flag.label .. ']]</small></td>' ) end if data.arms then table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">[[Coadan:' .. data.arms.image .. '|' .. data.arms.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.arms.link .. '|' .. data.arms.label .. ']]</small></td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = '"' .. motto .. '"', reference = reference and "<ref>" .. reference .. "</ref>" or nil } end -- Wikidata P1451 = motto local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = "“" .. value.text .. "”", reference = getWikidataReference(statement) } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then local title = normaliseCityName(capital) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = capital, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then local title = normaliseCityName(centre) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = centre, entity = entity, reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = normaliseCityName(city) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = city, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. normaliseCityName(city.text) .. "]]" end end local title = normaliseCityName(city.text) return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT (deprecated - captions are now -- embedded per-column inside p.images/buildFlagArmsBlock) -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest and not capitalIsLargest(capital, largest) then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN (assembles the whole infobox table directly, -- reusing the legacy table's classes/structure so -- borders and dividers render the same way) -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -- Header / country name do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -- Flag / arms do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -- Motto / anthem do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -- Locator map do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -- Capital / largest city / administrative centre do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels -- Capital if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. dividerStyle .. ' vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. dividerStyle .. ' vertical-align:top;">' .. text .. '</td></tr>' ) end -- Administrative centre if administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. dividerStyle .. ' vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. dividerStyle .. ' vertical-align:top;">' .. text .. '</td></tr>' ) end -- Largest city if largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. dividerStyle .. ' vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. dividerStyle .. ' vertical-align:top;">' .. text .. '</td></tr>' ) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p sjw09bkwycocdi8lpm7flh8w6ywf9y5 392866 392865 2026-09-06T19:00:19Z MacTire02 219 +kiangley 392866 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- TITLE -------------------------------------------------- -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getFlagArmsData(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if not flag and not arms then return nil end local name = getCountryGenitive(args) or "" local data = {} if flag then data.flag = { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px", link = "Brattagh " .. name, label = getManual(args, { "fo-heidyl_brattagh" }) or "Brattagh" } end if arms then local kind = getManual(args, { "art_sorçh_cowrey" }) or getManual(args, { "sorçh_cowrey" }) or "Armys" data.arms = { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "85px", link = kind .. " " .. name, label = getManual(args, { "sorçh_cowrey" }) or "Armys" } end return data end -------------------------------------------------- -- FLAG / ARMS BLOCK (images + per-column captions) -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} if data.flag then table.insert(imageCells, '<td align="center" style="' .. (data.arms and "width:58%; " or "") .. 'vertical-align:middle;">[[Coadan:' .. data.flag.image .. '|' .. data.flag.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.flag.link .. '|' .. data.flag.label .. ']]</small></td>' ) end if data.arms then table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">[[Coadan:' .. data.arms.image .. '|' .. data.arms.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.arms.link .. '|' .. data.arms.label .. ']]</small></td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = '"' .. motto .. '"', reference = reference and "<ref>" .. reference .. "</ref>" or nil } end -- Wikidata P1451 = motto local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = "“" .. value.text .. "”", reference = getWikidataReference(statement) } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then local title = normaliseCityName(capital) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = capital, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then local title = normaliseCityName(centre) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = centre, entity = entity, reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = normaliseCityName(city) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = city, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. normaliseCityName(city.text) .. "]]" end end local title = normaliseCityName(city.text) return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT (deprecated - captions are now -- embedded per-column inside p.images/buildFlagArmsBlock) -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest and not capitalIsLargest(capital, largest) then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN (assembles the whole infobox table directly, -- reusing the legacy table's classes/structure so -- borders and dividers render the same way) -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -- Header / country name do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -- Flag / arms do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -- Motto / anthem do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -- Locator map do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -- Capital / largest city / administrative centre do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels -- Capital if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. dividerStyle .. ' vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. dividerStyle .. ' vertical-align:top;">' .. text .. '</td></tr>' ) end -- Administrative centre if administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. dividerStyle .. ' vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. dividerStyle .. ' vertical-align:top;">' .. text .. '</td></tr>' ) end -- Largest city if largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. dividerStyle .. ' vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. dividerStyle .. ' vertical-align:top;">' .. text .. '</td></tr>' ) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p oysyrzn7zql17lbd397km2wmetqyfru 392867 392866 2026-09-06T19:01:43Z MacTire02 219 ++ 392867 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- TITLE -------------------------------------------------- -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getFlagArmsData(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if not flag and not arms then return nil end local name = getCountryGenitive(args) or "" local data = {} if flag then data.flag = { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px", link = "Brattagh " .. name, label = getManual(args, { "fo-heidyl_brattagh" }) or "Brattagh" } end if arms then local kind = getManual(args, { "art_sorçh_cowrey" }) or getManual(args, { "sorçh_cowrey" }) or "Armys" data.arms = { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "85px", link = kind .. " " .. name, label = getManual(args, { "sorçh_cowrey" }) or "Armys" } end return data end -------------------------------------------------- -- FLAG / ARMS BLOCK (images + per-column captions) -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} if data.flag then table.insert(imageCells, '<td align="center" style="' .. (data.arms and "width:58%; " or "") .. 'vertical-align:middle;">[[Coadan:' .. data.flag.image .. '|' .. data.flag.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.flag.link .. '|' .. data.flag.label .. ']]</small></td>' ) end if data.arms then table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">[[Coadan:' .. data.arms.image .. '|' .. data.arms.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.arms.link .. '|' .. data.arms.label .. ']]</small></td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = '"' .. motto .. '"', reference = reference and "<ref>" .. reference .. "</ref>" or nil } end -- Wikidata P1451 = motto local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = "“" .. value.text .. "”", reference = getWikidataReference(statement) } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then local title = normaliseCityName(capital) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = capital, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then local title = normaliseCityName(centre) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = centre, entity = entity, reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = normaliseCityName(city) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = city, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. normaliseCityName(city.text) .. "]]" end end local title = normaliseCityName(city.text) return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT (deprecated - captions are now -- embedded per-column inside p.images/buildFlagArmsBlock) -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest and not capitalIsLargest(capital, largest) then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN (assembles the whole infobox table directly, -- reusing the legacy table's classes/structure so -- borders and dividers render the same way) -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -- Header / country name do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -- Flag / arms do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -- Motto / anthem do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -- Locator map do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -- Capital / largest city / administrative centre do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels -- Capital if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. dividerStyle .. ' vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. dividerStyle .. ' vertical-align:top;">' .. text .. '</td></tr>' ) end -- Administrative centre if administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. dividerStyle .. ' vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. dividerStyle .. ' vertical-align:top;">' .. text .. '</td></tr>' ) end -- Largest city if largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. dividerStyle .. ' vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. dividerStyle .. ' vertical-align:top;">' .. text .. '</td></tr>' ) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p hij18bq3mmikxlbu0o4f72rnbrslh2c 392868 392867 2026-09-06T19:11:10Z MacTire02 219 ++ 392868 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- TITLE -------------------------------------------------- -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getFlagArmsData(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if not flag and not arms then return nil end local name = getCountryGenitive(args) or "" local data = {} if flag then data.flag = { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px", link = "Brattagh " .. name, label = getManual(args, { "fo-heidyl_brattagh" }) or "Brattagh" } end if arms then local kind = getManual(args, { "art_sorçh_cowrey" }) or getManual(args, { "sorçh_cowrey" }) or "Armys" data.arms = { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "85px", link = kind .. " " .. name, label = getManual(args, { "sorçh_cowrey" }) or "Armys" } end return data end -------------------------------------------------- -- FLAG / ARMS BLOCK (images + per-column captions) -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} if data.flag then table.insert(imageCells, '<td align="center" style="' .. (data.arms and "width:58%; " or "") .. 'vertical-align:middle;">[[Coadan:' .. data.flag.image .. '|' .. data.flag.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.flag.link .. '|' .. data.flag.label .. ']]</small></td>' ) end if data.arms then table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">[[Coadan:' .. data.arms.image .. '|' .. data.arms.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.arms.link .. '|' .. data.arms.label .. ']]</small></td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = '"' .. motto .. '"', reference = reference and "<ref>" .. reference .. "</ref>" or nil } end -- Wikidata P1451 = motto local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = "“" .. value.text .. "”", reference = getWikidataReference(statement) } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then local title = normaliseCityName(capital) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = capital, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local label = entity:getLabel() if label and label ~= "" then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then local title = normaliseCityName(centre) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = centre, entity = entity, reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = normaliseCityName(city) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = city, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local label = entity:getLabel() if label and label ~= "" then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) local capital = getCapitalData(args) local administrative = getAdministrativeCentreData(args) local largest = getLargestCityData(args) local labels = getCityLabels(args) return { capital = capital, administrative = administrative, largest = largest, labels = labels } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end if city.entity then local sitelink = city.entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return "[[" .. sitelink .. "|" .. sitelink .. "]]" end end local title = normaliseCityName(city.text) return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT (deprecated - captions are now -- embedded per-column inside p.images/buildFlagArmsBlock) -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest and not capitalIsLargest(capital, largest) then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN (assembles the whole infobox table directly, -- reusing the legacy table's classes/structure so -- borders and dividers render the same way) -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -- Header / country name do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -- Flag / arms do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -- Motto / anthem do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -- Locator map do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -- Capital / largest city / administrative centre do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels -- Capital if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. dividerStyle .. ' vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. dividerStyle .. ' vertical-align:top;">' .. text .. '</td></tr>' ) end -- Administrative centre if administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. dividerStyle .. ' vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. dividerStyle .. ' vertical-align:top;">' .. text .. '</td></tr>' ) end -- Largest city if largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. dividerStyle .. ' vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. dividerStyle .. ' vertical-align:top;">' .. text .. '</td></tr>' ) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p 5o2mogpfp3dxakbp5hb8qmjeltcv22y 392869 392868 2026-09-06T19:16:38Z MacTire02 219 ++ 392869 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getFlagArmsData(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if not flag and not arms then return nil end local name = getCountryGenitive(args) or "" local data = {} if flag then data.flag = { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px", link = "Brattagh " .. name, label = getManual(args, { "fo-heidyl_brattagh" }) or "Brattagh" } end if arms then local kind = getManual(args, { "art_sorçh_cowrey" }) or getManual(args, { "sorçh_cowrey" }) or "Armys" data.arms = { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "85px", link = kind .. " " .. name, label = getManual(args, { "sorçh_cowrey" }) or "Armys" } end return data end -------------------------------------------------- -- FLAG / ARMS BLOCK -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} if data.flag then table.insert(imageCells, '<td align="center" style="' .. (data.arms and "width:58%; " or "") .. 'vertical-align:middle;">[[Coadan:' .. data.flag.image .. '|' .. data.flag.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.flag.link .. '|' .. data.flag.label .. ']]</small></td>' ) end if data.arms then table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">[[Coadan:' .. data.arms.image .. '|' .. data.arms.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.arms.link .. '|' .. data.arms.label .. ']]</small></td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = '"' .. motto .. '"', reference = reference and "<ref>" .. reference .. "</ref>" or nil } end local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = '"' .. value.text .. '"', reference = getWikidataReference(statement) } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCityEntityFromTitle(value) local title = normaliseCityName(value) if title == "" then return nil end local entityId = mw.wikibase.getEntityIdForTitle(title) if not entityId then return nil end return mw.wikibase.getEntity(entityId) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then return { text = capital, entity = getCityEntityFromTitle(capital), reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or entity:getLabel(), entity = entity, reference = getWikidataReference(statement) } end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then return { text = city, entity = getCityEntityFromTitle(city), reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or entity:getLabel(), entity = entity, reference = getWikidataReference(statement) } end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) return { capital = getCapitalData(args), administrative = getAdministrativeCentreData(args), largest = getLargestCityData(args), labels = getCityLabels(args) } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end local title if city.entity then title = city.entity:getSitelink("gvwiki") end if not title or title == "" then title = normaliseCityName(city.text) end return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -------------------------------------------------- -- HEADER -------------------------------------------------- do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -------------------------------------------------- -- FLAG / ARMS -------------------------------------------------- do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -------------------------------------------------- -- MOTTO / ANTHEM -------------------------------------------------- do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -------------------------------------------------- -- CAPITAL / ADMINISTRATIVE CENTRE / LARGEST CITY -------------------------------------------------- do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels -- Add one divider before the city section only. if capital or administrative or largest then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '"></td></tr>' ) end -- Capital if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[" .. label .. "]]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Administrative centre if administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Largest city if largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p b9u3x3ufzkk7qgyxryd7sgqwlxlbu34 392870 392869 2026-09-06T19:17:51Z MacTire02 219 kiartaghey beg lesh y lipaid 392870 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getFlagArmsData(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if not flag and not arms then return nil end local name = getCountryGenitive(args) or "" local data = {} if flag then data.flag = { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px", link = "Brattagh " .. name, label = getManual(args, { "fo-heidyl_brattagh" }) or "Brattagh" } end if arms then local kind = getManual(args, { "art_sorçh_cowrey" }) or getManual(args, { "sorçh_cowrey" }) or "Armys" data.arms = { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "85px", link = kind .. " " .. name, label = getManual(args, { "sorçh_cowrey" }) or "Armys" } end return data end -------------------------------------------------- -- FLAG / ARMS BLOCK -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} if data.flag then table.insert(imageCells, '<td align="center" style="' .. (data.arms and "width:58%; " or "") .. 'vertical-align:middle;">[[Coadan:' .. data.flag.image .. '|' .. data.flag.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.flag.link .. '|' .. data.flag.label .. ']]</small></td>' ) end if data.arms then table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">[[Coadan:' .. data.arms.image .. '|' .. data.arms.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.arms.link .. '|' .. data.arms.label .. ']]</small></td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = '"' .. motto .. '"', reference = reference and "<ref>" .. reference .. "</ref>" or nil } end local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = '"' .. value.text .. '"', reference = getWikidataReference(statement) } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCityEntityFromTitle(value) local title = normaliseCityName(value) if title == "" then return nil end local entityId = mw.wikibase.getEntityIdForTitle(title) if not entityId then return nil end return mw.wikibase.getEntity(entityId) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then return { text = capital, entity = getCityEntityFromTitle(capital), reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or entity:getLabel(), entity = entity, reference = getWikidataReference(statement) } end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then return { text = city, entity = getCityEntityFromTitle(city), reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or entity:getLabel(), entity = entity, reference = getWikidataReference(statement) } end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) return { capital = getCapitalData(args), administrative = getAdministrativeCentreData(args), largest = getLargestCityData(args), labels = getCityLabels(args) } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end local title if city.entity then title = city.entity:getSitelink("gvwiki") end if not title or title == "" then title = normaliseCityName(city.text) end return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -------------------------------------------------- -- HEADER -------------------------------------------------- do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -------------------------------------------------- -- FLAG / ARMS -------------------------------------------------- do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -------------------------------------------------- -- MOTTO / ANTHEM -------------------------------------------------- do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -------------------------------------------------- -- CAPITAL / ADMINISTRATIVE CENTRE / LARGEST CITY -------------------------------------------------- do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels -- Add one divider before the city section only. if capital or administrative or largest then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '"></td></tr>' ) end -- Capital if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Administrative centre if administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Largest city if largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p rj9g4rsquo8e8r7iewmcstf4rats8z6 392871 392870 2026-09-06T19:21:02Z MacTire02 219 ++ 392871 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getFlagArmsData(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if not flag and not arms then return nil end local name = getCountryGenitive(args) or "" local data = {} if flag then data.flag = { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px", link = "Brattagh " .. name, label = getManual(args, { "fo-heidyl_brattagh" }) or "Brattagh" } end if arms then local kind = getManual(args, { "art_sorçh_cowrey" }) or getManual(args, { "sorçh_cowrey" }) or "Armys" data.arms = { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "85px", link = kind .. " " .. name, label = getManual(args, { "sorçh_cowrey" }) or "Armys" } end return data end -------------------------------------------------- -- FLAG / ARMS BLOCK -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} if data.flag then table.insert(imageCells, '<td align="center" style="' .. (data.arms and "width:58%; " or "") .. 'vertical-align:middle;">[[Coadan:' .. data.flag.image .. '|' .. data.flag.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.flag.link .. '|' .. data.flag.label .. ']]</small></td>' ) end if data.arms then table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">[[Coadan:' .. data.arms.image .. '|' .. data.arms.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.arms.link .. '|' .. data.arms.label .. ']]</small></td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = '"' .. motto .. '"', reference = reference and "<ref>" .. reference .. "</ref>" or nil } end local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = '"' .. value.text .. '"', reference = getWikidataReference(statement) } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCityEntityFromTitle(value) local title = normaliseCityName(value) if title == "" then return nil end local entityId = mw.wikibase.getEntityIdForTitle(title) if not entityId then return nil end return mw.wikibase.getEntity(entityId) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then return { text = capital, entity = getCityEntityFromTitle(capital), reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or entity:getLabel(), entity = entity, reference = getWikidataReference(statement) } end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then return { text = city, entity = getCityEntityFromTitle(city), reference = nil } end -- Wikidata P13574 = most populous urban area. -- Follow the statement directly to its target item. local currentEntity = mw.wikibase.getEntityObject() if not currentEntity then return nil end local statements = currentEntity:getBestStatements("P13574") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id if targetId then local targetEntity = mw.wikibase.getEntity(targetId) if targetEntity then -- The target item is the city itself. -- Use its Manx Wikipedia sitelink, not its -- Wikidata label. local sitelink = targetEntity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return { text = sitelink, entity = targetEntity, reference = getWikidataReference(statement) } end end end end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) return { capital = getCapitalData(args), administrative = getAdministrativeCentreData(args), largest = getLargestCityData(args), labels = getCityLabels(args) } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end local title if city.entity then title = city.entity:getSitelink("gvwiki") end if not title or title == "" then title = normaliseCityName(city.text) end return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -------------------------------------------------- -- HEADER -------------------------------------------------- do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -------------------------------------------------- -- FLAG / ARMS -------------------------------------------------- do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -------------------------------------------------- -- MOTTO / ANTHEM -------------------------------------------------- do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -------------------------------------------------- -- CAPITAL / ADMINISTRATIVE CENTRE / LARGEST CITY -------------------------------------------------- do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels -- Add one divider before the city section only. if capital or administrative or largest then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '"></td></tr>' ) end -- Capital if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Administrative centre if administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Largest city if largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p 7o6gzn0qp41x7rjx84oc336dpw6mppo 392872 392871 2026-09-06T19:24:07Z MacTire02 219 prowal 392872 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getFlagArmsData(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if not flag and not arms then return nil end local name = getCountryGenitive(args) or "" local data = {} if flag then data.flag = { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px", link = "Brattagh " .. name, label = getManual(args, { "fo-heidyl_brattagh" }) or "Brattagh" } end if arms then local kind = getManual(args, { "art_sorçh_cowrey" }) or getManual(args, { "sorçh_cowrey" }) or "Armys" data.arms = { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "85px", link = kind .. " " .. name, label = getManual(args, { "sorçh_cowrey" }) or "Armys" } end return data end -------------------------------------------------- -- FLAG / ARMS BLOCK -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} if data.flag then table.insert(imageCells, '<td align="center" style="' .. (data.arms and "width:58%; " or "") .. 'vertical-align:middle;">[[Coadan:' .. data.flag.image .. '|' .. data.flag.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.flag.link .. '|' .. data.flag.label .. ']]</small></td>' ) end if data.arms then table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">[[Coadan:' .. data.arms.image .. '|' .. data.arms.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.arms.link .. '|' .. data.arms.label .. ']]</small></td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = '"' .. motto .. '"', reference = reference and "<ref>" .. reference .. "</ref>" or nil } end local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = '"' .. value.text .. '"', reference = getWikidataReference(statement) } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCityEntityFromTitle(value) local title = normaliseCityName(value) if title == "" then return nil end local entityId = mw.wikibase.getEntityIdForTitle(title) if not entityId then return nil end return mw.wikibase.getEntity(entityId) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then return { text = capital, entity = getCityEntityFromTitle(capital), reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or entity:getLabel(), entity = entity, reference = getWikidataReference(statement) } end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = normaliseCityName(city) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = city, entity = entity, reference = nil } end local entity, statement = getWikidataItem("P13574") if entity then local sitelink = entity:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return { text = sitelink, entity = entity, reference = getWikidataReference(statement) } end local label = entity:getLabel() if label and label ~= "" then return { text = label, entity = entity, reference = getWikidataReference(statement) } end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) return { capital = getCapitalData(args), administrative = getAdministrativeCentreData(args), largest = getLargestCityData(args), labels = getCityLabels(args) } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end local title = nil if city.entity then title = city.entity:getSitelink("gvwiki") end if not title or title == "" then title = normaliseCityName(city.text) end if not title or title == "" then return "" end return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -------------------------------------------------- -- HEADER -------------------------------------------------- do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -------------------------------------------------- -- FLAG / ARMS -------------------------------------------------- do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -------------------------------------------------- -- MOTTO / ANTHEM -------------------------------------------------- do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -------------------------------------------------- -- CAPITAL / ADMINISTRATIVE CENTRE / LARGEST CITY -------------------------------------------------- do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels -- Add one divider before the city section only. if capital or administrative or largest then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '"></td></tr>' ) end -- Capital if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Administrative centre if administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Largest city if largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p czwx7ewtrjdy0f50976u6skw0ltt97n 392873 392872 2026-09-06T19:25:54Z MacTire02 219 ++ 392873 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getFlagArmsData(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if not flag and not arms then return nil end local name = getCountryGenitive(args) or "" local data = {} if flag then data.flag = { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px", link = "Brattagh " .. name, label = getManual(args, { "fo-heidyl_brattagh" }) or "Brattagh" } end if arms then local kind = getManual(args, { "art_sorçh_cowrey" }) or getManual(args, { "sorçh_cowrey" }) or "Armys" data.arms = { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "85px", link = kind .. " " .. name, label = getManual(args, { "sorçh_cowrey" }) or "Armys" } end return data end -------------------------------------------------- -- FLAG / ARMS BLOCK -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} if data.flag then table.insert(imageCells, '<td align="center" style="' .. (data.arms and "width:58%; " or "") .. 'vertical-align:middle;">[[Coadan:' .. data.flag.image .. '|' .. data.flag.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.flag.link .. '|' .. data.flag.label .. ']]</small></td>' ) end if data.arms then table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">[[Coadan:' .. data.arms.image .. '|' .. data.arms.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.arms.link .. '|' .. data.arms.label .. ']]</small></td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = '"' .. motto .. '"', reference = reference and "<ref>" .. reference .. "</ref>" or nil } end local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = '"' .. value.text .. '"', reference = getWikidataReference(statement) } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCityEntityFromTitle(value) local title = normaliseCityName(value) if title == "" then return nil end local entityId = mw.wikibase.getEntityIdForTitle(title) if not entityId then return nil end return mw.wikibase.getEntity(entityId) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then return { text = capital, entity = getCityEntityFromTitle(capital), reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or entity:getLabel(), entity = entity, reference = getWikidataReference(statement) } end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = normaliseCityName(city) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = city, entity = entity, reference = nil } end -------------------------------------------------- -- WIKIDATA P13574 -------------------------------------------------- local country = mw.wikibase.getEntityObject() if not country then return nil end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id local target = mw.wikibase.getEntity(targetId) if target then -- Use the actual Manx Wikipedia sitelink, -- never the Manx Wikidata label. local sitelink = target:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return { text = sitelink, entity = target, reference = getWikidataReference(statement) } end end end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) return { capital = getCapitalData(args), administrative = getAdministrativeCentreData(args), largest = getLargestCityData(args), labels = getCityLabels(args) } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end local title = nil if city.entity then title = city.entity:getSitelink("gvwiki") end if not title or title == "" then title = normaliseCityName(city.text) end if not title or title == "" then return "" end return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -------------------------------------------------- -- HEADER -------------------------------------------------- do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -------------------------------------------------- -- FLAG / ARMS -------------------------------------------------- do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -------------------------------------------------- -- MOTTO / ANTHEM -------------------------------------------------- do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -------------------------------------------------- -- CAPITAL / ADMINISTRATIVE CENTRE / LARGEST CITY -------------------------------------------------- do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels -- Add one divider before the city section only. if capital or administrative or largest then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '"></td></tr>' ) end -- Capital if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Administrative centre if administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Largest city if largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p 2z7rzd15mmse67w2wyz5vijxrebrtai 392874 392873 2026-09-06T19:32:09Z MacTire02 219 prowal 392874 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getFlagArmsData(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if not flag and not arms then return nil end local name = getCountryGenitive(args) or "" local data = {} if flag then data.flag = { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px", link = "Brattagh " .. name, label = getManual(args, { "fo-heidyl_brattagh" }) or "Brattagh" } end if arms then local kind = getManual(args, { "art_sorçh_cowrey" }) or getManual(args, { "sorçh_cowrey" }) or "Armys" data.arms = { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "85px", link = kind .. " " .. name, label = getManual(args, { "sorçh_cowrey" }) or "Armys" } end return data end -------------------------------------------------- -- FLAG / ARMS BLOCK -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} if data.flag then table.insert(imageCells, '<td align="center" style="' .. (data.arms and "width:58%; " or "") .. 'vertical-align:middle;">[[Coadan:' .. data.flag.image .. '|' .. data.flag.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.flag.link .. '|' .. data.flag.label .. ']]</small></td>' ) end if data.arms then table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">[[Coadan:' .. data.arms.image .. '|' .. data.arms.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.arms.link .. '|' .. data.arms.label .. ']]</small></td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = '"' .. motto .. '"', reference = reference and "<ref>" .. reference .. "</ref>" or nil } end local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = '"' .. value.text .. '"', reference = getWikidataReference(statement) } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCityEntityFromTitle(value) local title = normaliseCityName(value) if title == "" then return nil end local entityId = mw.wikibase.getEntityIdForTitle(title) if not entityId then return nil end return mw.wikibase.getEntity(entityId) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then return { text = capital, entity = getCityEntityFromTitle(capital), reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or entity:getLabel(), entity = entity, reference = getWikidataReference(statement) } end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil } end return nil end function p.debug_largest(frame) local country = mw.wikibase.getEntityObject() if not country then return "NO COUNTRY ENTITY" end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return "NO P13574" end local output = {} table.insert(output, "Country entity: " .. tostring(country.id) ) for i, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id table.insert(output, "P13574 target: " .. tostring(targetId) ) local target = mw.wikibase.getEntity(targetId) if target then table.insert(output, "Target entity: " .. tostring(target.id) ) table.insert(output, "English label: " .. tostring(target:getLabel("en")) ) table.insert(output, "gvwiki sitelink: " .. tostring(target:getSitelink("gvwiki")) ) else table.insert(output, "TARGET ENTITY FAILED" ) end else table.insert(output, "P13574 statement has no usable entity value" ) end end return table.concat(output, "<br/>") end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = normaliseCityName(city) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = city, entity = entity, reference = nil } end -------------------------------------------------- -- WIKIDATA P13574 -------------------------------------------------- local country = mw.wikibase.getEntityObject() if not country then return nil end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id local target = mw.wikibase.getEntity(targetId) if target then -- Use the actual Manx Wikipedia sitelink, -- never the Manx Wikidata label. local sitelink = target:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return { text = sitelink, entity = target, reference = getWikidataReference(statement) } end end end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) return { capital = getCapitalData(args), administrative = getAdministrativeCentreData(args), largest = getLargestCityData(args), labels = getCityLabels(args) } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end local title = nil if city.entity then title = city.entity:getSitelink("gvwiki") end if not title or title == "" then title = normaliseCityName(city.text) end if not title or title == "" then return "" end return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -------------------------------------------------- -- HEADER -------------------------------------------------- do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -------------------------------------------------- -- FLAG / ARMS -------------------------------------------------- do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -------------------------------------------------- -- MOTTO / ANTHEM -------------------------------------------------- do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -------------------------------------------------- -- CAPITAL / ADMINISTRATIVE CENTRE / LARGEST CITY -------------------------------------------------- do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels -- Add one divider before the city section only. if capital or administrative or largest then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '"></td></tr>' ) end -- Capital if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Administrative centre if administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Largest city if largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p t8ex3dodzh7arjg6h6h7wkenjvklha3 392875 392874 2026-09-06T19:36:42Z MacTire02 219 +faaishnys-enneydagh 392875 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getFlagArmsData(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if not flag and not arms then return nil end local name = getCountryGenitive(args) or "" local data = {} if flag then data.flag = { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px", link = "Brattagh " .. name, label = getManual(args, { "fo-heidyl_brattagh" }) or "Brattagh" } end if arms then local kind = getManual(args, { "art_sorçh_cowrey" }) or getManual(args, { "sorçh_cowrey" }) or "Armys" data.arms = { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "85px", link = kind .. " " .. name, label = getManual(args, { "sorçh_cowrey" }) or "Armys" } end return data end -------------------------------------------------- -- FLAG / ARMS BLOCK -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} if data.flag then table.insert(imageCells, '<td align="center" style="' .. (data.arms and "width:58%; " or "") .. 'vertical-align:middle;">[[Coadan:' .. data.flag.image .. '|' .. data.flag.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.flag.link .. '|' .. data.flag.label .. ']]</small></td>' ) end if data.arms then table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">[[Coadan:' .. data.arms.image .. '|' .. data.arms.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.arms.link .. '|' .. data.arms.label .. ']]</small></td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = '"' .. motto .. '"', reference = reference and "<ref>" .. reference .. "</ref>" or nil } end local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = '"' .. value.text .. '"', reference = getWikidataReference(statement) } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCityEntityFromTitle(value) local title = normaliseCityName(value) if title == "" then return nil end local entityId = mw.wikibase.getEntityIdForTitle(title) if not entityId then return nil end return mw.wikibase.getEntity(entityId) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then return { text = capital, entity = getCityEntityFromTitle(capital), reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or entity:getLabel(), entity = entity, reference = getWikidataReference(statement) } end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil } end return nil end function p.debug_largest(frame) local country = mw.wikibase.getEntityObject() if not country then return "NO COUNTRY ENTITY" end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return "NO P13574" end local output = {} table.insert(output, "Country entity: " .. tostring(country.id) ) for i, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id table.insert(output, "P13574 target: " .. tostring(targetId) ) local target = mw.wikibase.getEntity(targetId) if target then table.insert(output, "Target entity: " .. tostring(target.id) ) table.insert(output, "English label: " .. tostring(target:getLabel("en")) ) table.insert(output, "gvwiki sitelink: " .. tostring(target:getSitelink("gvwiki")) ) else table.insert(output, "TARGET ENTITY FAILED" ) end else table.insert(output, "P13574 statement has no usable entity value" ) end end return table.concat(output, "<br/>") end function p.debug_args(frame) local args = getArgs(frame) local value = args["balley_smoo"] if value then return "balley_smoo = [" .. tostring(value) .. "]" end return "balley_smoo = NIL" end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = normaliseCityName(city) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = city, entity = entity, reference = nil } end -------------------------------------------------- -- WIKIDATA P13574 -------------------------------------------------- local country = mw.wikibase.getEntityObject() if not country then return nil end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id local target = mw.wikibase.getEntity(targetId) if target then -- Use the actual Manx Wikipedia sitelink, -- never the Manx Wikidata label. local sitelink = target:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return { text = sitelink, entity = target, reference = getWikidataReference(statement) } end end end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) return { capital = getCapitalData(args), administrative = getAdministrativeCentreData(args), largest = getLargestCityData(args), labels = getCityLabels(args) } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end local title = nil if city.entity then title = city.entity:getSitelink("gvwiki") end if not title or title == "" then title = normaliseCityName(city.text) end if not title or title == "" then return "" end return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -------------------------------------------------- -- HEADER -------------------------------------------------- do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -------------------------------------------------- -- FLAG / ARMS -------------------------------------------------- do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -------------------------------------------------- -- MOTTO / ANTHEM -------------------------------------------------- do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -------------------------------------------------- -- CAPITAL / ADMINISTRATIVE CENTRE / LARGEST CITY -------------------------------------------------- do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels -- Add one divider before the city section only. if capital or administrative or largest then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '"></td></tr>' ) end -- Capital if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Administrative centre if administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Largest city if largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p pz79aq98bnek6z15q98tb5wnhyyetce 392876 392875 2026-09-06T20:35:13Z MacTire02 219 ++ 392876 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getFlagArmsData(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if not flag and not arms then return nil end local name = getCountryGenitive(args) or "" local data = {} if flag then data.flag = { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px", link = "Brattagh " .. name, label = getManual(args, { "fo-heidyl_brattagh" }) or "Brattagh" } end if arms then local kind = getManual(args, { "art_sorçh_cowrey" }) or getManual(args, { "sorçh_cowrey" }) or "Armys" data.arms = { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "85px", link = kind .. " " .. name, label = getManual(args, { "sorçh_cowrey" }) or "Armys" } end return data end -------------------------------------------------- -- FLAG / ARMS BLOCK -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} if data.flag then table.insert(imageCells, '<td align="center" style="' .. (data.arms and "width:58%; " or "") .. 'vertical-align:middle;">[[Coadan:' .. data.flag.image .. '|' .. data.flag.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.flag.link .. '|' .. data.flag.label .. ']]</small></td>' ) end if data.arms then table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">[[Coadan:' .. data.arms.image .. '|' .. data.arms.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.arms.link .. '|' .. data.arms.label .. ']]</small></td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = '"' .. motto .. '"', reference = reference and "<ref>" .. reference .. "</ref>" or nil } end local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = '"' .. value.text .. '"', reference = getWikidataReference(statement) } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCityEntityFromTitle(value) local title = normaliseCityName(value) if title == "" then return nil end local entityId = mw.wikibase.getEntityIdForTitle(title) if not entityId then return nil end return mw.wikibase.getEntity(entityId) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then return { text = capital, entity = getCityEntityFromTitle(capital), reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or entity:getLabel(), entity = entity, reference = getWikidataReference(statement) } end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil } end return nil end function p.debug_largest(frame) local country = mw.wikibase.getEntityObject() if not country then return "NO COUNTRY ENTITY" end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return "NO P13574" end local output = {} table.insert(output, "Country entity: " .. tostring(country.id) ) for i, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id table.insert(output, "P13574 target: " .. tostring(targetId) ) local target = mw.wikibase.getEntity(targetId) if target then table.insert(output, "Target entity: " .. tostring(target.id) ) table.insert(output, "English label: " .. tostring(target:getLabel("en")) ) table.insert(output, "gvwiki sitelink: " .. tostring(target:getSitelink("gvwiki")) ) else table.insert(output, "TARGET ENTITY FAILED" ) end else table.insert(output, "P13574 statement has no usable entity value" ) end end return table.concat(output, "<br/>") end function p.debug_args(frame) local args = getArgs(frame) local value = args["balley_smoo"] if value then return "balley_smoo = [" .. tostring(value) .. "]" end return "balley_smoo = NIL" end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then local title = normaliseCityName(city) local entity = nil if title ~= "" then local entityId = mw.wikibase.getEntityIdForTitle(title) if entityId then entity = mw.wikibase.getEntity(entityId) end end return { text = city, entity = entity, reference = nil } end -------------------------------------------------- -- WIKIDATA P13574 -------------------------------------------------- local country = mw.wikibase.getEntityObject() if not country then return nil end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id local target = mw.wikibase.getEntity(targetId) if target then -- Use the actual Manx Wikipedia sitelink, -- never the Manx Wikidata label. local sitelink = target:getSitelink("gvwiki") if sitelink and sitelink ~= "" then return { text = sitelink, entity = target, reference = getWikidataReference(statement) } end end end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) return { capital = getCapitalData(args), administrative = getAdministrativeCentreData(args), largest = getLargestCityData(args), labels = getCityLabels(args) } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end local title = nil if city.entity then title = city.entity:getSitelink("gvwiki") end if not title or title == "" then title = normaliseCityName(city.text) end if not title or title == "" then return "" end return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN -------------------------------------------------- function p.debug_render(frame) local args = getArgs(frame) local cityData = getCityData(args) local largest = cityData.largest if not largest then return "largest = NIL" end local output = {} table.insert(output, "largest.text = [" .. tostring(largest.text) .. "]" ) table.insert(output, "largest.entity = [" .. tostring(largest.entity and largest.entity.id or "NIL") .. "]" ) if largest.entity then table.insert(output, "entity label = [" .. tostring(largest.entity:getLabel()) .. "]" ) table.insert(output, "entity gvwiki = [" .. tostring(largest.entity:getSitelink("gvwiki")) .. "]" ) table.insert(output, "makeCityLink = [" .. makeCityLink(largest) .. "]" ) end return table.concat(output, "<br/>") end function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -------------------------------------------------- -- HEADER -------------------------------------------------- do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -------------------------------------------------- -- FLAG / ARMS -------------------------------------------------- do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -------------------------------------------------- -- MOTTO / ANTHEM -------------------------------------------------- do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -------------------------------------------------- -- CAPITAL / ADMINISTRATIVE CENTRE / LARGEST CITY -------------------------------------------------- do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels -- Add one divider before the city section only. if capital or administrative or largest then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '"></td></tr>' ) end -- Capital if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Administrative centre if administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Largest city if largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p iotbw8xxrcn50lgzehndibfr4zyscq2 392878 392876 2026-09-06T20:37:59Z MacTire02 219 ++prowal 392878 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getFlagArmsData(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if not flag and not arms then return nil end local name = getCountryGenitive(args) or "" local data = {} if flag then data.flag = { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px", link = "Brattagh " .. name, label = getManual(args, { "fo-heidyl_brattagh" }) or "Brattagh" } end if arms then local kind = getManual(args, { "art_sorçh_cowrey" }) or getManual(args, { "sorçh_cowrey" }) or "Armys" data.arms = { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "85px", link = kind .. " " .. name, label = getManual(args, { "sorçh_cowrey" }) or "Armys" } end return data end -------------------------------------------------- -- FLAG / ARMS BLOCK -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} if data.flag then table.insert(imageCells, '<td align="center" style="' .. (data.arms and "width:58%; " or "") .. 'vertical-align:middle;">[[Coadan:' .. data.flag.image .. '|' .. data.flag.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.flag.link .. '|' .. data.flag.label .. ']]</small></td>' ) end if data.arms then table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">[[Coadan:' .. data.arms.image .. '|' .. data.arms.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.arms.link .. '|' .. data.arms.label .. ']]</small></td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = '"' .. motto .. '"', reference = reference and "<ref>" .. reference .. "</ref>" or nil } end local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = '"' .. value.text .. '"', reference = getWikidataReference(statement) } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCityEntityFromTitle(value) local title = normaliseCityName(value) if title == "" then return nil end local entityId = mw.wikibase.getEntityIdForTitle(title) if not entityId then return nil end return mw.wikibase.getEntity(entityId) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then return { text = capital, entity = getCityEntityFromTitle(capital), reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or entity:getLabel(), entity = entity, reference = getWikidataReference(statement) } end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil } end return nil end function p.debug_largest(frame) local country = mw.wikibase.getEntityObject() if not country then return "NO COUNTRY ENTITY" end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return "NO P13574" end local output = {} table.insert(output, "Country entity: " .. tostring(country.id) ) for i, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id table.insert(output, "P13574 target: " .. tostring(targetId) ) local target = mw.wikibase.getEntity(targetId) if target then table.insert(output, "Target entity: " .. tostring(target.id) ) table.insert(output, "English label: " .. tostring(target:getLabel("en")) ) table.insert(output, "gvwiki sitelink: " .. tostring(target:getSitelink("gvwiki")) ) else table.insert(output, "TARGET ENTITY FAILED" ) end else table.insert(output, "P13574 statement has no usable entity value" ) end end return table.concat(output, "<br/>") end function p.debug_args(frame) local args = getArgs(frame) local value = args["balley_smoo"] if value then return "balley_smoo = [" .. tostring(value) .. "]" end return "balley_smoo = NIL" end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then return { text = city, entity = getCityEntityFromTitle(city), reference = nil } end local country = mw.wikibase.getEntityObject() if not country then return { text = "DEBUG: no country", entity = nil, reference = nil } end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return { text = "DEBUG: no P13574", entity = nil, reference = nil } end local statement = statements[1] local mainsnak = statement.mainsnak if not mainsnak or mainsnak.snaktype ~= "value" or not mainsnak.datavalue or mainsnak.datavalue.type ~= "wikibase-entityid" then return { text = "DEBUG: bad P13574", entity = nil, reference = nil } end local targetId = mainsnak.datavalue.value.id local target = mw.wikibase.getEntity(targetId) if not target then return { text = "DEBUG: target failed " .. tostring(targetId), entity = nil, reference = nil } end local sitelink = target:getSitelink("gvwiki") return { text = "DEBUG: target=" .. tostring(target.id) .. " / sitelink=" .. tostring(sitelink), entity = target, reference = nil } end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) return { capital = getCapitalData(args), administrative = getAdministrativeCentreData(args), largest = getLargestCityData(args), labels = getCityLabels(args) } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end local title = nil if city.entity then title = city.entity:getSitelink("gvwiki") end if not title or title == "" then title = normaliseCityName(city.text) end if not title or title == "" then return "" end return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN -------------------------------------------------- function p.debug_render(frame) local args = getArgs(frame) local cityData = getCityData(args) local largest = cityData.largest if not largest then return "largest = NIL" end local output = {} table.insert(output, "largest.text = [" .. tostring(largest.text) .. "]" ) table.insert(output, "largest.entity = [" .. tostring(largest.entity and largest.entity.id or "NIL") .. "]" ) if largest.entity then table.insert(output, "entity label = [" .. tostring(largest.entity:getLabel()) .. "]" ) table.insert(output, "entity gvwiki = [" .. tostring(largest.entity:getSitelink("gvwiki")) .. "]" ) table.insert(output, "makeCityLink = [" .. makeCityLink(largest) .. "]" ) end return table.concat(output, "<br/>") end function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -------------------------------------------------- -- HEADER -------------------------------------------------- do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -------------------------------------------------- -- FLAG / ARMS -------------------------------------------------- do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -------------------------------------------------- -- MOTTO / ANTHEM -------------------------------------------------- do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -------------------------------------------------- -- CAPITAL / ADMINISTRATIVE CENTRE / LARGEST CITY -------------------------------------------------- do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels -- Add one divider before the city section only. if capital or administrative or largest then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '"></td></tr>' ) end -- Capital if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Administrative centre if administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Largest city if largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p hfp3bbelvrsnmhnqk17l4928uh9j9wz 392880 392878 2026-09-06T20:54:26Z MacTire02 219 ++ 392880 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- DISAMBIGUATION GUARD -------------------------------------------------- -- Some Wikidata statements resolve to a general/ambiguous -- item rather than the specific thing we want (e.g. a -- country's "most populous urban area" pointing at the -- ambiguous "New York" (Q22654) instead of "New York City" -- (Q60)). Skip anything flagged as a disambiguation page. local function isDisambiguationPage(entity) if not entity then return false end local statements = entity:getBestStatements("P31") if not statements then return false end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" and mainsnak.datavalue.value.id == "Q4167410" then return true end end return false end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity and not isDisambiguationPage(linkedEntity) then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getFlagArmsData(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if not flag and not arms then return nil end local name = getCountryGenitive(args) or "" local data = {} if flag then data.flag = { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px", link = "Brattagh " .. name, label = getManual(args, { "fo-heidyl_brattagh" }) or "Brattagh" } end if arms then local kind = getManual(args, { "art_sorçh_cowrey" }) or getManual(args, { "sorçh_cowrey" }) or "Armys" data.arms = { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "85px", link = kind .. " " .. name, label = getManual(args, { "sorçh_cowrey" }) or "Armys" } end return data end -------------------------------------------------- -- FLAG / ARMS BLOCK -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} if data.flag then table.insert(imageCells, '<td align="center" style="' .. (data.arms and "width:58%; " or "") .. 'vertical-align:middle;">[[Coadan:' .. data.flag.image .. '|' .. data.flag.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.flag.link .. '|' .. data.flag.label .. ']]</small></td>' ) end if data.arms then table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">[[Coadan:' .. data.arms.image .. '|' .. data.arms.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.arms.link .. '|' .. data.arms.label .. ']]</small></td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = '"' .. motto .. '"', reference = reference and "<ref>" .. reference .. "</ref>" or nil } end local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = '"' .. value.text .. '"', reference = getWikidataReference(statement) } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCityEntityFromTitle(value) local title = normaliseCityName(value) if title == "" then return nil end local entityId = mw.wikibase.getEntityIdForTitle(title) if not entityId then return nil end return mw.wikibase.getEntity(entityId) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then return { text = capital, entity = getCityEntityFromTitle(capital), reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or entity:getLabel(), entity = entity, reference = getWikidataReference(statement) } end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then return { text = city, entity = getCityEntityFromTitle(city), reference = nil } end local country = mw.wikibase.getEntityObject() if not country then return nil end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id local target = mw.wikibase.getEntity(targetId) if target and not isDisambiguationPage(target) then local sitelink = target:getSitelink("gvwiki") return { text = sitelink or target:getLabel(), entity = target, reference = getWikidataReference(statement) } end end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) return { capital = getCapitalData(args), administrative = getAdministrativeCentreData(args), largest = getLargestCityData(args), labels = getCityLabels(args) } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end local title = nil if city.entity then title = city.entity:getSitelink("gvwiki") end if not title or title == "" then title = normaliseCityName(city.text) end if not title or title == "" then return "" end return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -------------------------------------------------- -- HEADER -------------------------------------------------- do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -------------------------------------------------- -- FLAG / ARMS -------------------------------------------------- do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -------------------------------------------------- -- MOTTO / ANTHEM -------------------------------------------------- do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -------------------------------------------------- -- CAPITAL / ADMINISTRATIVE CENTRE / LARGEST CITY -------------------------------------------------- do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels -- Add one divider before the city section only. if capital or administrative or largest then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '"></td></tr>' ) end -- Capital if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Administrative centre if administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Largest city if largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p 2h1scjsa9xixq0rr4i56rx0hzlr8puu 392881 392880 2026-09-06T21:18:15Z MacTire02 219 chengaghyn nish 392881 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- DISAMBIGUATION GUARD -------------------------------------------------- -- Some Wikidata statements resolve to a general/ambiguous -- item rather than the specific thing we want (e.g. a -- country's "most populous urban area" pointing at the -- ambiguous "New York" (Q22654) instead of "New York City" -- (Q60)). Skip anything flagged as a disambiguation page. local function isDisambiguationPage(entity) if not entity then return false end local statements = entity:getBestStatements("P31") if not statements then return false end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" and mainsnak.datavalue.value.id == "Q4167410" then return true end end return false end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity and not isDisambiguationPage(linkedEntity) then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getFlagArmsData(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if not flag and not arms then return nil end local name = getCountryGenitive(args) or "" local data = {} if flag then data.flag = { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px", link = "Brattagh " .. name, label = getManual(args, { "fo-heidyl_brattagh" }) or "Brattagh" } end if arms then local kind = getManual(args, { "art_sorçh_cowrey" }) or getManual(args, { "sorçh_cowrey" }) or "Armys" data.arms = { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "85px", link = kind .. " " .. name, label = getManual(args, { "sorçh_cowrey" }) or "Armys" } end return data end -------------------------------------------------- -- FLAG / ARMS BLOCK -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} if data.flag then table.insert(imageCells, '<td align="center" style="' .. (data.arms and "width:58%; " or "") .. 'vertical-align:middle;">[[Coadan:' .. data.flag.image .. '|' .. data.flag.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.flag.link .. '|' .. data.flag.label .. ']]</small></td>' ) end if data.arms then table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">[[Coadan:' .. data.arms.image .. '|' .. data.arms.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.arms.link .. '|' .. data.arms.label .. ']]</small></td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = '"' .. motto .. '"', reference = reference and "<ref>" .. reference .. "</ref>" or nil } end local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = '"' .. value.text .. '"', reference = getWikidataReference(statement) } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- local function getLanguagesFromWikidata() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P37") if not statements or #statements == 0 then return {} end local languages = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local langEntity = mw.wikibase.getEntity(id) if langEntity then local label = langEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(languages, { text = label, role = role, reference = getWikidataReference(statement) }) end end end end return languages end local function classifyLanguages(languages) local result = { official = {}, regional = {}, minority = {} } for _, language in ipairs(languages) do local role = language.role or "" local lowerRole = mw.ustring.lower(role) if mw.ustring.find(lowerRole, "minority") then table.insert(result.minority, language) elseif mw.ustring.find(lowerRole, "regional") then table.insert(result.regional, language) else table.insert(result.official, language) end end return result end local function joinLanguageList(languages) if not languages or #languages == 0 then return nil end local parts = {} for _, language in ipairs(languages) do local text = language.text if language.reference then text = text .. language.reference end table.insert(parts, text) end if #parts == 0 then return nil end return table.concat(parts, ", ") end -- Splits text on a top-level separator character, without -- splitting inside {{...}} or [[...]] (so a piped wikilink -- like [[Country|Display]], or a nested template, doesn't -- get miscounted as two items). local function splitTopLevel(text, sep) local parts = {} local current = {} local depthCurly = 0 local depthSquare = 0 local len = mw.ustring.len(text) local i = 1 while i <= len do local two = mw.ustring.sub(text, i, i + 1) local one = mw.ustring.sub(text, i, i) if two == "{{" then depthCurly = depthCurly + 1 table.insert(current, two) i = i + 2 elseif two == "}}" and depthCurly > 0 then depthCurly = depthCurly - 1 table.insert(current, two) i = i + 2 elseif two == "[[" then depthSquare = depthSquare + 1 table.insert(current, two) i = i + 2 elseif two == "]]" and depthSquare > 0 then depthSquare = depthSquare - 1 table.insert(current, two) i = i + 2 elseif one == sep and depthCurly == 0 and depthSquare == 0 then table.insert(parts, table.concat(current)) current = {} i = i + 1 else table.insert(current, one) i = i + 1 end end table.insert(parts, table.concat(current)) return parts end -- Counts the items inside a {{hlist|...}}/{{flatlist|...}}/ -- {{ubl|...}}/{{unbulleted list|...}} template call (the -- convention most legacy articles already use for this -- field). Returns nil if the text isn't one of these, so -- the caller can fall back to a plain heuristic. -- Finds the first call to a template matching namePattern -- anywhere in text (not just at the start/whole-string), -- respecting nested {{...}} so a template argument that -- itself contains braces doesn't break the search. Returns -- the inner content (everything after the first "|") or nil -- if no such template call is found. local function findTemplateCall(text, namePattern) local searchPattern = "{{%s*" .. namePattern .. "%s*|" local matchStart, matchEnd = mw.ustring.find(text, searchPattern) if not matchStart then return nil end local contentStart = matchEnd + 1 local depth = 1 local i = contentStart local len = mw.ustring.len(text) while i <= len do local two = mw.ustring.sub(text, i, i + 1) if two == "{{" then depth = depth + 1 i = i + 2 elseif two == "}}" then depth = depth - 1 i = i + 2 if depth == 0 then local contentEnd = i - 3 return mw.ustring.sub(text, contentStart, contentEnd) end else i = i + 1 end end return nil end -- Pulls any <ref>...</ref> (or self-closing <ref .../>) tags -- out of text, returning the text with them removed plus the -- extracted ref markup (already-valid <ref> tags, ready to -- use as-is - not to be re-wrapped). Returns (text, nil) if -- none are found. local function extractReferences(text) if not text then return text, nil end local refs = {} local cleaned = mw.ustring.gsub(text, "<ref[^>]*>.-</ref>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.ustring.gsub(cleaned, "<ref[^>]*/>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.text.trim(cleaned) if #refs == 0 then return cleaned, nil end return cleaned, table.concat(refs) end local function countHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local segments = splitTopLevel(inner, "|") local count = 0 for _, segment in ipairs(segments) do local trimmedSegment = mw.text.trim(segment) -- Skip named parameters (class=, style=, indent=, etc.) -- rather than counting them as list items. if trimmedSegment ~= "" and not mw.ustring.find(trimmedSegment, "^[%w_%- ]+=") then count = count + 1 end end return count end -- Count of items in a manually-entered language/list field, -- used to decide between a singular ("çhengey") and plural -- ("çhengaghyn") label. Wikidata-derived lists are counted -- exactly (see getLanguageData). Handles the {{hlist}} family -- (searched for anywhere in the text, not just as the entire -- value, since editors often append a trailing <ref> after -- the closing "}}") most legacy articles already use; -- otherwise falls back to a plain comma-count heuristic. local function countListItems(text) if not text or text == "" then return 0 end local hlistCount = countHlistItems(text) if hlistCount then return hlistCount end local count = 0 for _ in mw.text.gsplit(text, ",", true) do count = count + 1 end return count end -- Resolves one language tier from its raw manual parameter: -- strips out any inline <ref> tags (used as-is, since they're -- already valid markup), counts the list on the ref-stripped -- text, then re-appends the extracted ref(s) and/or a manual -- imraa_ reference (which - unlike an inline <ref> - is raw -- citation text that still needs wrapping) to the display value. local function buildLanguageValue(raw, manualReference) if not raw or mw.ustring.lower(mw.text.trim(raw)) == "none" then return nil, 0 end local cleaned, inlineRefs = extractReferences(raw) local count = countListItems(cleaned) local display = cleaned if inlineRefs then display = display .. inlineRefs end if manualReference then display = display .. "<ref>" .. manualReference .. "</ref>" end return display, count end local function getLanguageData(args) local officialRaw = getManual(args, { "çhengaghyn_oikoil", "çhengey_oikoil" }) local officialReference = getManual(args, { "imraa_çhengaghyn_oikoil", "imraa_çhengey_oikoil" }) local regionalRaw = getManual(args, { "çhengaghyn_ardjynagh", "çhengey_ardjynagh" }) local regionalReference = getManual(args, { "imraa_çhengaghyn_ardjynagh", "imraa_çhengey_ardjynagh" }) local minorityRaw = getManual(args, { "mynçhengaghyn", "mynçhengey" }) local minorityReference = getManual(args, { "imraa_mynçhengaghyn", "imraa_mynçhengey" }) local otherRaw = getManual(args, { "çhengaghyn", "çhengey" }) local otherReference = getManual(args, { "imraa_çhengaghyn", "imraa_çhengey" }) local otherLabel = getManual(args, { "sorçh_çhengaghyn" }) local result = { otherLabel = otherLabel } result.official, result.officialCount = buildLanguageValue(officialRaw, officialReference) result.regional, result.regionalCount = buildLanguageValue(regionalRaw, regionalReference) result.minority, result.minorityCount = buildLanguageValue(minorityRaw, minorityReference) result.other, result.otherCount = buildLanguageValue(otherRaw, otherReference) -- Only reach for Wikidata if none of the three tiers -- were set manually - a manual "none" or partial set -- of overrides always wins over the auto-fetch. if not result.official and not result.regional and not result.minority then local classified = classifyLanguages(getLanguagesFromWikidata()) result.official = joinLanguageList(classified.official) result.officialCount = #classified.official result.regional = joinLanguageList(classified.regional) result.regionalCount = #classified.regional result.minority = joinLanguageList(classified.minority) result.minorityCount = #classified.minority end return result end local function buildLanguageRows(args) local data = getLanguageData(args) local rows = {} if data.official then local officialLabel = data.officialCount > 1 and "[[Çhengey oikoil|Çhengaghyn oikoil]]" or "[[Çhengey oikoil]]" local officialRow = '<tr><th colspan="2" style="vertical-align:middle; white-space:nowrap;">' .. officialLabel .. '</th><td>' .. data.official .. '</td></tr>' if data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn&nbsp;ardjynagh er&nbsp;enney" or "Çhengey&nbsp;ardjynagh er&nbsp;enney" officialRow = officialRow .. '<tr class="mergedbottomrow">' .. '<td colspan="2">[[Çhengey ardjynagh|' .. regionalLabel .. ']]</td>' .. '<td style="vertical-align:middle;">' .. data.regional .. '</td></tr>' end table.insert(rows, officialRow) elseif data.regional then -- Regional recognised even without a separate -- official-language statement. local regionalLabel = data.regionalCount > 1 and "Çhengaghyn ardjynagh er enney" or "Çhengey ardjynagh er enney" table.insert(rows, '<tr><th colspan="2" style="vertical-align:middle; white-space:nowrap;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th><td>' .. data.regional .. '</td></tr>' ) end if data.minority then local minorityLabel = data.minorityCount > 1 and "[[Mynçhengey|Mynçhengaghyn]]" or "[[Mynçhengey]]" table.insert(rows, '<tr><th colspan="2" style="vertical-align:middle; white-space:nowrap;">' .. minorityLabel .. '</th><td>' .. data.minority .. '</td></tr>' ) end if data.other then local otherLabel = data.otherLabel or (data.otherCount > 1 and "Çhengaghyn" or "Çhengey") table.insert(rows, '<tr><th colspan="2" style="vertical-align:middle; white-space:nowrap;">' .. otherLabel .. '</th><td>' .. data.other .. '</td></tr>' ) end if #rows == 0 then return nil end return table.concat(rows) end function p.languages(frame) local args = getArgs(frame) return buildLanguageRows(args) end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCityEntityFromTitle(value) local title = normaliseCityName(value) if title == "" then return nil end local entityId = mw.wikibase.getEntityIdForTitle(title) if not entityId then return nil end return mw.wikibase.getEntity(entityId) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then return { text = capital, entity = getCityEntityFromTitle(capital), reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or entity:getLabel(), entity = entity, reference = getWikidataReference(statement) } end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then return { text = city, entity = getCityEntityFromTitle(city), reference = nil } end local country = mw.wikibase.getEntityObject() if not country then return nil end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id local target = mw.wikibase.getEntity(targetId) if target and not isDisambiguationPage(target) then local sitelink = target:getSitelink("gvwiki") return { text = sitelink or target:getLabel(), entity = target, reference = getWikidataReference(statement) } end end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) return { capital = getCapitalData(args), administrative = getAdministrativeCentreData(args), largest = getLargestCityData(args), labels = getCityLabels(args) } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end local title = nil if city.entity then title = city.entity:getSitelink("gvwiki") end if not title or title == "" then title = normaliseCityName(city.text) end if not title or title == "" then return "" end return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -------------------------------------------------- -- HEADER -------------------------------------------------- do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -------------------------------------------------- -- FLAG / ARMS -------------------------------------------------- do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -------------------------------------------------- -- MOTTO / ANTHEM -------------------------------------------------- do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -------------------------------------------------- -- CAPITAL / ADMINISTRATIVE CENTRE / LARGEST CITY -------------------------------------------------- do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels -- Add one divider before the city section only. if capital or administrative or largest then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '"></td></tr>' ) end -- Capital if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Administrative centre if administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Largest city if largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- do local languageRows = buildLanguageRows(args) if languageRows then table.insert(rows, languageRows) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p b0f40gcnjal7p7wm56dmii2wpvbnhqz 392882 392881 2026-09-06T21:20:59Z MacTire02 219 ++ 392882 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- DISAMBIGUATION GUARD -------------------------------------------------- -- Some Wikidata statements resolve to a general/ambiguous -- item rather than the specific thing we want (e.g. a -- country's "most populous urban area" pointing at the -- ambiguous "New York" (Q22654) instead of "New York City" -- (Q60)). Skip anything flagged as a disambiguation page. local function isDisambiguationPage(entity) if not entity then return false end local statements = entity:getBestStatements("P31") if not statements then return false end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" and mainsnak.datavalue.value.id == "Q4167410" then return true end end return false end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity and not isDisambiguationPage(linkedEntity) then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getFlagArmsData(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if not flag and not arms then return nil end local name = getCountryGenitive(args) or "" local data = {} if flag then data.flag = { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px", link = "Brattagh " .. name, label = getManual(args, { "fo-heidyl_brattagh" }) or "Brattagh" } end if arms then local kind = getManual(args, { "art_sorçh_cowrey" }) or getManual(args, { "sorçh_cowrey" }) or "Armys" data.arms = { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "85px", link = kind .. " " .. name, label = getManual(args, { "sorçh_cowrey" }) or "Armys" } end return data end -------------------------------------------------- -- FLAG / ARMS BLOCK -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} if data.flag then table.insert(imageCells, '<td align="center" style="' .. (data.arms and "width:58%; " or "") .. 'vertical-align:middle;">[[Coadan:' .. data.flag.image .. '|' .. data.flag.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.flag.link .. '|' .. data.flag.label .. ']]</small></td>' ) end if data.arms then table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">[[Coadan:' .. data.arms.image .. '|' .. data.arms.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.arms.link .. '|' .. data.arms.label .. ']]</small></td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = '"' .. motto .. '"', reference = reference and "<ref>" .. reference .. "</ref>" or nil } end local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = '"' .. value.text .. '"', reference = getWikidataReference(statement) } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- local function getLanguagesFromWikidata() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P37") if not statements or #statements == 0 then return {} end local languages = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local langEntity = mw.wikibase.getEntity(id) if langEntity then local label = langEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(languages, { text = label, role = role, reference = getWikidataReference(statement) }) end end end end return languages end local function classifyLanguages(languages) local result = { official = {}, regional = {}, minority = {} } for _, language in ipairs(languages) do local role = language.role or "" local lowerRole = mw.ustring.lower(role) if mw.ustring.find(lowerRole, "minority") then table.insert(result.minority, language) elseif mw.ustring.find(lowerRole, "regional") then table.insert(result.regional, language) else table.insert(result.official, language) end end return result end local function joinLanguageList(languages) if not languages or #languages == 0 then return nil end local parts = {} for _, language in ipairs(languages) do local text = language.text if language.reference then text = text .. language.reference end table.insert(parts, text) end if #parts == 0 then return nil end return table.concat(parts, ", ") end -- Splits text on a top-level separator character, without -- splitting inside {{...}} or [[...]] (so a piped wikilink -- like [[Country|Display]], or a nested template, doesn't -- get miscounted as two items). local function splitTopLevel(text, sep) local parts = {} local current = {} local depthCurly = 0 local depthSquare = 0 local len = mw.ustring.len(text) local i = 1 while i <= len do local two = mw.ustring.sub(text, i, i + 1) local one = mw.ustring.sub(text, i, i) if two == "{{" then depthCurly = depthCurly + 1 table.insert(current, two) i = i + 2 elseif two == "}}" and depthCurly > 0 then depthCurly = depthCurly - 1 table.insert(current, two) i = i + 2 elseif two == "[[" then depthSquare = depthSquare + 1 table.insert(current, two) i = i + 2 elseif two == "]]" and depthSquare > 0 then depthSquare = depthSquare - 1 table.insert(current, two) i = i + 2 elseif one == sep and depthCurly == 0 and depthSquare == 0 then table.insert(parts, table.concat(current)) current = {} i = i + 1 else table.insert(current, one) i = i + 1 end end table.insert(parts, table.concat(current)) return parts end -- Counts the items inside a {{hlist|...}}/{{flatlist|...}}/ -- {{ubl|...}}/{{unbulleted list|...}} template call (the -- convention most legacy articles already use for this -- field). Returns nil if the text isn't one of these, so -- the caller can fall back to a plain heuristic. -- Finds the first call to a template matching namePattern -- anywhere in text (not just at the start/whole-string), -- respecting nested {{...}} so a template argument that -- itself contains braces doesn't break the search. Returns -- the inner content (everything after the first "|") or nil -- if no such template call is found. local function findTemplateCall(text, namePattern) local searchPattern = "{{%s*" .. namePattern .. "%s*|" local matchStart, matchEnd = mw.ustring.find(text, searchPattern) if not matchStart then return nil end local contentStart = matchEnd + 1 local depth = 1 local i = contentStart local len = mw.ustring.len(text) while i <= len do local two = mw.ustring.sub(text, i, i + 1) if two == "{{" then depth = depth + 1 i = i + 2 elseif two == "}}" then depth = depth - 1 i = i + 2 if depth == 0 then local contentEnd = i - 3 return mw.ustring.sub(text, contentStart, contentEnd) end else i = i + 1 end end return nil end -- Pulls any <ref>...</ref> (or self-closing <ref .../>) tags -- out of text, returning the text with them removed plus the -- extracted ref markup (already-valid <ref> tags, ready to -- use as-is - not to be re-wrapped). Returns (text, nil) if -- none are found. local function extractReferences(text) if not text then return text, nil end local refs = {} local cleaned = mw.ustring.gsub(text, "<ref[^>]*>.-</ref>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.ustring.gsub(cleaned, "<ref[^>]*/>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.text.trim(cleaned) if #refs == 0 then return cleaned, nil end return cleaned, table.concat(refs) end local function countHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local segments = splitTopLevel(inner, "|") local count = 0 for _, segment in ipairs(segments) do local trimmedSegment = mw.text.trim(segment) -- Skip named parameters (class=, style=, indent=, etc.) -- rather than counting them as list items. if trimmedSegment ~= "" and not mw.ustring.find(trimmedSegment, "^[%w_%- ]+=") then count = count + 1 end end return count end -- Count of items in a manually-entered language/list field, -- used to decide between a singular ("çhengey") and plural -- ("çhengaghyn") label. Wikidata-derived lists are counted -- exactly (see getLanguageData). Handles the {{hlist}} family -- (searched for anywhere in the text, not just as the entire -- value, since editors often append a trailing <ref> after -- the closing "}}") most legacy articles already use; -- otherwise falls back to a plain comma-count heuristic. local function countListItems(text) if not text or text == "" then return 0 end local hlistCount = countHlistItems(text) if hlistCount then return hlistCount end local count = 0 for _ in mw.text.gsplit(text, ",", true) do count = count + 1 end return count end -- Resolves one language tier from its raw manual parameter: -- strips out any inline <ref> tags (used as-is, since they're -- already valid markup), counts the list on the ref-stripped -- text, then re-appends the extracted ref(s) and/or a manual -- imraa_ reference (which - unlike an inline <ref> - is raw -- citation text that still needs wrapping) to the display value. local function buildLanguageValue(raw, manualReference) if not raw or mw.ustring.lower(mw.text.trim(raw)) == "none" then return nil, 0 end local cleaned, inlineRefs = extractReferences(raw) local count = countListItems(cleaned) local display = cleaned if inlineRefs then display = display .. inlineRefs end if manualReference then display = display .. "<ref>" .. manualReference .. "</ref>" end return display, count end local function getLanguageData(args) local officialRaw = getManual(args, { "çhengaghyn_oikoil", "çhengey_oikoil" }) local officialReference = getManual(args, { "imraa_çhengaghyn_oikoil", "imraa_çhengey_oikoil" }) local regionalRaw = getManual(args, { "çhengaghyn_ardjynagh", "çhengey_ardjynagh" }) local regionalReference = getManual(args, { "imraa_çhengaghyn_ardjynagh", "imraa_çhengey_ardjynagh" }) local minorityRaw = getManual(args, { "mynçhengaghyn", "mynçhengey" }) local minorityReference = getManual(args, { "imraa_mynçhengaghyn", "imraa_mynçhengey" }) local otherRaw = getManual(args, { "çhengaghyn", "çhengey" }) local otherReference = getManual(args, { "imraa_çhengaghyn", "imraa_çhengey" }) local otherLabel = getManual(args, { "sorçh_çhengaghyn" }) local result = { otherLabel = otherLabel } result.official, result.officialCount = buildLanguageValue(officialRaw, officialReference) result.regional, result.regionalCount = buildLanguageValue(regionalRaw, regionalReference) result.minority, result.minorityCount = buildLanguageValue(minorityRaw, minorityReference) result.other, result.otherCount = buildLanguageValue(otherRaw, otherReference) -- Only reach for Wikidata if none of the three tiers -- were set manually - a manual "none" or partial set -- of overrides always wins over the auto-fetch. if not result.official and not result.regional and not result.minority then local classified = classifyLanguages(getLanguagesFromWikidata()) result.official = joinLanguageList(classified.official) result.officialCount = #classified.official result.regional = joinLanguageList(classified.regional) result.regionalCount = #classified.regional result.minority = joinLanguageList(classified.minority) result.minorityCount = #classified.minority end return result end local function buildLanguageRows(args) local data = getLanguageData(args) local rows = {} if data.official then local officialLabel = data.officialCount > 1 and "[[Çhengey oikoil|Çhengaghyn oikoil]]" or "[[Çhengey oikoil]]" local officialRow = '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. officialLabel .. '</th><td style="vertical-align:top;">' .. data.official .. '</td></tr>' if data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn&nbsp;ardjynagh er&nbsp;enney" or "Çhengey&nbsp;ardjynagh er&nbsp;enney" officialRow = officialRow .. '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:normal;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th>' .. '<td style="vertical-align:top;">' .. data.regional .. '</td></tr>' end table.insert(rows, officialRow) elseif data.regional then -- Regional recognised even without a separate -- official-language statement. local regionalLabel = data.regionalCount > 1 and "Çhengaghyn ardjynagh er enney" or "Çhengey ardjynagh er enney" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th><td style="vertical-align:top;">' .. data.regional .. '</td></tr>' ) end if data.minority then local minorityLabel = data.minorityCount > 1 and "[[Mynçhengey|Mynçhengaghyn]]" or "[[Mynçhengey]]" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. minorityLabel .. '</th><td style="vertical-align:top;">' .. data.minority .. '</td></tr>' ) end if data.other then local otherLabel = data.otherLabel or (data.otherCount > 1 and "Çhengaghyn" or "Çhengey") table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. otherLabel .. '</th><td style="vertical-align:top;">' .. data.other .. '</td></tr>' ) end if #rows == 0 then return nil end return table.concat(rows) end function p.languages(frame) local args = getArgs(frame) return buildLanguageRows(args) end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCityEntityFromTitle(value) local title = normaliseCityName(value) if title == "" then return nil end local entityId = mw.wikibase.getEntityIdForTitle(title) if not entityId then return nil end return mw.wikibase.getEntity(entityId) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then return { text = capital, entity = getCityEntityFromTitle(capital), reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or entity:getLabel(), entity = entity, reference = getWikidataReference(statement) } end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then return { text = city, entity = getCityEntityFromTitle(city), reference = nil } end local country = mw.wikibase.getEntityObject() if not country then return nil end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id local target = mw.wikibase.getEntity(targetId) if target and not isDisambiguationPage(target) then local sitelink = target:getSitelink("gvwiki") return { text = sitelink or target:getLabel(), entity = target, reference = getWikidataReference(statement) } end end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) return { capital = getCapitalData(args), administrative = getAdministrativeCentreData(args), largest = getLargestCityData(args), labels = getCityLabels(args) } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end local title = nil if city.entity then title = city.entity:getSitelink("gvwiki") end if not title or title == "" then title = normaliseCityName(city.text) end if not title or title == "" then return "" end return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -------------------------------------------------- -- HEADER -------------------------------------------------- do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -------------------------------------------------- -- FLAG / ARMS -------------------------------------------------- do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -------------------------------------------------- -- MOTTO / ANTHEM -------------------------------------------------- do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -------------------------------------------------- -- CAPITAL / ADMINISTRATIVE CENTRE / LARGEST CITY -------------------------------------------------- do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels -- Add one divider before the city section only. if capital or administrative or largest then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '"></td></tr>' ) end -- Capital if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Administrative centre if administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Largest city if largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- do local languageRows = buildLanguageRows(args) if languageRows then table.insert(rows, languageRows) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p 0jov9gpkp76wo6gihpdsgp6n18a6hl4 392883 392882 2026-09-06T23:16:03Z MacTire02 219 ++ 392883 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- DISAMBIGUATION GUARD -------------------------------------------------- -- Some Wikidata statements resolve to a general/ambiguous -- item rather than the specific thing we want (e.g. a -- country's "most populous urban area" pointing at the -- ambiguous "New York" (Q22654) instead of "New York City" -- (Q60)). Skip anything flagged as a disambiguation page. local function isDisambiguationPage(entity) if not entity then return false end local statements = entity:getBestStatements("P31") if not statements then return false end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" and mainsnak.datavalue.value.id == "Q4167410" then return true end end return false end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity and not isDisambiguationPage(linkedEntity) then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getFlagArmsData(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if not flag and not arms then return nil end local name = getCountryGenitive(args) or "" local data = {} if flag then data.flag = { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px", link = "Brattagh " .. name, label = getManual(args, { "fo-heidyl_brattagh" }) or "Brattagh" } end if arms then local kind = getManual(args, { "art_sorçh_cowrey" }) or getManual(args, { "sorçh_cowrey" }) or "Armys" data.arms = { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "85px", link = kind .. " " .. name, label = getManual(args, { "sorçh_cowrey" }) or "Armys" } end return data end -------------------------------------------------- -- FLAG / ARMS BLOCK -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} if data.flag then table.insert(imageCells, '<td align="center" style="' .. (data.arms and "width:58%; " or "") .. 'vertical-align:middle;">[[Coadan:' .. data.flag.image .. '|' .. data.flag.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.flag.link .. '|' .. data.flag.label .. ']]</small></td>' ) end if data.arms then table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">[[Coadan:' .. data.arms.image .. '|' .. data.arms.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.arms.link .. '|' .. data.arms.label .. ']]</small></td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = '"' .. motto .. '"', reference = reference and "<ref>" .. reference .. "</ref>" or nil } end local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = '"' .. value.text .. '"', reference = getWikidataReference(statement) } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- local function getLanguagesFromWikidata() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P37") if not statements or #statements == 0 then return {} end local languages = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local langEntity = mw.wikibase.getEntity(id) if langEntity then local label = langEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(languages, { text = label, entity = langEntity, role = role, reference = getWikidataReference(statement) }) end end end end return languages end local function classifyLanguages(languages) local result = { official = {}, regional = {}, minority = {} } for _, language in ipairs(languages) do local role = language.role or "" local lowerRole = mw.ustring.lower(role) if mw.ustring.find(lowerRole, "minority") then table.insert(result.minority, language) elseif mw.ustring.find(lowerRole, "regional") then table.insert(result.regional, language) else table.insert(result.official, language) end end return result end local function makeLanguageLink(language) if not language or not language.text then return "" end local title = nil if language.entity then title = language.entity:getSitelink("gvwiki") end if not title or title == "" then title = language.text end if not title or title == "" then return language.text end return "[[" .. title .. "|" .. language.text .. "]]" end local function joinLanguageList(languages) if not languages or #languages == 0 then return nil end local parts = {} for _, language in ipairs(languages) do local text = makeLanguageLink(language) if language.reference then text = text .. language.reference end table.insert(parts, text) end if #parts == 0 then return nil end return table.concat(parts, ", ") end -- Splits text on a top-level separator character, without -- splitting inside {{...}} or [[...]] (so a piped wikilink -- like [[Country|Display]], or a nested template, doesn't -- get miscounted as two items). local function splitTopLevel(text, sep) local parts = {} local current = {} local depthCurly = 0 local depthSquare = 0 local len = mw.ustring.len(text) local i = 1 while i <= len do local two = mw.ustring.sub(text, i, i + 1) local one = mw.ustring.sub(text, i, i) if two == "{{" then depthCurly = depthCurly + 1 table.insert(current, two) i = i + 2 elseif two == "}}" and depthCurly > 0 then depthCurly = depthCurly - 1 table.insert(current, two) i = i + 2 elseif two == "[[" then depthSquare = depthSquare + 1 table.insert(current, two) i = i + 2 elseif two == "]]" and depthSquare > 0 then depthSquare = depthSquare - 1 table.insert(current, two) i = i + 2 elseif one == sep and depthCurly == 0 and depthSquare == 0 then table.insert(parts, table.concat(current)) current = {} i = i + 1 else table.insert(current, one) i = i + 1 end end table.insert(parts, table.concat(current)) return parts end -- Counts the items inside a {{hlist|...}}/{{flatlist|...}}/ -- {{ubl|...}}/{{unbulleted list|...}} template call (the -- convention most legacy articles already use for this -- field). Returns nil if the text isn't one of these, so -- the caller can fall back to a plain heuristic. -- Finds the first call to a template matching namePattern -- anywhere in text (not just at the start/whole-string), -- respecting nested {{...}} so a template argument that -- itself contains braces doesn't break the search. Returns -- the inner content (everything after the first "|") or nil -- if no such template call is found. local function findTemplateCall(text, namePattern) local searchPattern = "{{%s*" .. namePattern .. "%s*|" local matchStart, matchEnd = mw.ustring.find(text, searchPattern) if not matchStart then return nil end local contentStart = matchEnd + 1 local depth = 1 local i = contentStart local len = mw.ustring.len(text) while i <= len do local two = mw.ustring.sub(text, i, i + 1) if two == "{{" then depth = depth + 1 i = i + 2 elseif two == "}}" then depth = depth - 1 i = i + 2 if depth == 0 then local contentEnd = i - 3 return mw.ustring.sub(text, contentStart, contentEnd) end else i = i + 1 end end return nil end -- Pulls any <ref>...</ref> (or self-closing <ref .../>) tags -- out of text, returning the text with them removed plus the -- extracted ref markup (already-valid <ref> tags, ready to -- use as-is - not to be re-wrapped). Returns (text, nil) if -- none are found. local function extractReferences(text) if not text then return text, nil end local refs = {} local cleaned = mw.ustring.gsub(text, "<ref[^>]*>.-</ref>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.ustring.gsub(cleaned, "<ref[^>]*/>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.text.trim(cleaned) if #refs == 0 then return cleaned, nil end return cleaned, table.concat(refs) end local function countHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local segments = splitTopLevel(inner, "|") local count = 0 for _, segment in ipairs(segments) do local trimmedSegment = mw.text.trim(segment) -- Skip named parameters (class=, style=, indent=, etc.) -- rather than counting them as list items. if trimmedSegment ~= "" and not mw.ustring.find(trimmedSegment, "^[%w_%- ]+=") then count = count + 1 end end return count end -- Count of items in a manually-entered language/list field, -- used to decide between a singular ("çhengey") and plural -- ("çhengaghyn") label. Wikidata-derived lists are counted -- exactly (see getLanguageData). Handles the {{hlist}} family -- (searched for anywhere in the text, not just as the entire -- value, since editors often append a trailing <ref> after -- the closing "}}") most legacy articles already use; -- otherwise falls back to a plain comma-count heuristic. local function countListItems(text) if not text or text == "" then return 0 end local hlistCount = countHlistItems(text) if hlistCount then return hlistCount end local count = 0 for _ in mw.text.gsplit(text, ",", true) do count = count + 1 end return count end -- Resolves one language tier from its raw manual parameter: -- strips out any inline <ref> tags (used as-is, since they're -- already valid markup), counts the list on the ref-stripped -- text, then re-appends the extracted ref(s) and/or a manual -- imraa_ reference (which - unlike an inline <ref> - is raw -- citation text that still needs wrapping) to the display value. local function buildLanguageValue(raw, manualReference) if not raw or mw.ustring.lower(mw.text.trim(raw)) == "none" then return nil, 0 end local cleaned, inlineRefs = extractReferences(raw) local count = countListItems(cleaned) local display = cleaned if inlineRefs then display = display .. inlineRefs end if manualReference then display = display .. "<ref>" .. manualReference .. "</ref>" end return display, count end local function getLanguageData(args) local officialRaw = getManual(args, { "çhengaghyn_oikoil", "çhengey_oikoil" }) local officialReference = getManual(args, { "imraa_çhengaghyn_oikoil", "imraa_çhengey_oikoil" }) local regionalRaw = getManual(args, { "çhengaghyn_ardjynagh", "çhengey_ardjynagh" }) local regionalReference = getManual(args, { "imraa_çhengaghyn_ardjynagh", "imraa_çhengey_ardjynagh" }) local minorityRaw = getManual(args, { "mynçhengaghyn", "mynçhengey" }) local minorityReference = getManual(args, { "imraa_mynçhengaghyn", "imraa_mynçhengey" }) local otherRaw = getManual(args, { "çhengaghyn", "çhengey" }) local otherReference = getManual(args, { "imraa_çhengaghyn", "imraa_çhengey" }) local otherLabel = getManual(args, { "sorçh_çhengaghyn" }) local result = { otherLabel = otherLabel } result.official, result.officialCount = buildLanguageValue(officialRaw, officialReference) result.regional, result.regionalCount = buildLanguageValue(regionalRaw, regionalReference) result.minority, result.minorityCount = buildLanguageValue(minorityRaw, minorityReference) result.other, result.otherCount = buildLanguageValue(otherRaw, otherReference) -- Only reach for Wikidata if none of the three tiers -- were set manually - a manual "none" or partial set -- of overrides always wins over the auto-fetch. if not result.official and not result.regional and not result.minority then local classified = classifyLanguages(getLanguagesFromWikidata()) result.official = joinLanguageList(classified.official) result.officialCount = #classified.official result.regional = joinLanguageList(classified.regional) result.regionalCount = #classified.regional result.minority = joinLanguageList(classified.minority) result.minorityCount = #classified.minority end return result end local function buildLanguageRows(args) local data = getLanguageData(args) local rows = {} if data.official then local officialLabel = data.officialCount > 1 and "[[Çhengey oikoil|Çhengaghyn oikoil]]" or "[[Çhengey oikoil]]" local officialRow = '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. officialLabel .. '</th><td style="vertical-align:top;">' .. data.official .. '</td></tr>' if data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn&nbsp;ardjynagh er&nbsp;enney" or "Çhengey&nbsp;ardjynagh er&nbsp;enney" officialRow = officialRow .. '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:normal;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th>' .. '<td style="vertical-align:top;">' .. data.regional .. '</td></tr>' end table.insert(rows, officialRow) elseif data.regional then -- Regional recognised even without a separate -- official-language statement. local regionalLabel = data.regionalCount > 1 and "Çhengaghyn ardjynagh er enney" or "Çhengey ardjynagh er enney" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th><td style="vertical-align:top;">' .. data.regional .. '</td></tr>' ) end if data.minority then local minorityLabel = data.minorityCount > 1 and "[[Mynçhengey|Mynçhengaghyn]]" or "[[Mynçhengey]]" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. minorityLabel .. '</th><td style="vertical-align:top;">' .. data.minority .. '</td></tr>' ) end if data.other then local otherLabel = data.otherLabel or (data.otherCount > 1 and "Çhengaghyn" or "Çhengey") table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. otherLabel .. '</th><td style="vertical-align:top;">' .. data.other .. '</td></tr>' ) end if #rows == 0 then return nil end return table.concat(rows) end function p.languages(frame) local args = getArgs(frame) return buildLanguageRows(args) end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCityEntityFromTitle(value) local title = normaliseCityName(value) if title == "" then return nil end local entityId = mw.wikibase.getEntityIdForTitle(title) if not entityId then return nil end return mw.wikibase.getEntity(entityId) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then return { text = capital, entity = getCityEntityFromTitle(capital), reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or entity:getLabel(), entity = entity, reference = getWikidataReference(statement) } end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then return { text = city, entity = getCityEntityFromTitle(city), reference = nil } end local country = mw.wikibase.getEntityObject() if not country then return nil end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id local target = mw.wikibase.getEntity(targetId) if target and not isDisambiguationPage(target) then local sitelink = target:getSitelink("gvwiki") return { text = sitelink or target:getLabel(), entity = target, reference = getWikidataReference(statement) } end end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) return { capital = getCapitalData(args), administrative = getAdministrativeCentreData(args), largest = getLargestCityData(args), labels = getCityLabels(args) } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end local title = nil if city.entity then title = city.entity:getSitelink("gvwiki") end if not title or title == "" then title = normaliseCityName(city.text) end if not title or title == "" then return "" end return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -------------------------------------------------- -- HEADER -------------------------------------------------- do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -------------------------------------------------- -- FLAG / ARMS -------------------------------------------------- do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -------------------------------------------------- -- MOTTO / ANTHEM -------------------------------------------------- do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -------------------------------------------------- -- CAPITAL / ADMINISTRATIVE CENTRE / LARGEST CITY -------------------------------------------------- do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels -- Add one divider before the city section only. if capital or administrative or largest then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '"></td></tr>' ) end -- Capital if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Administrative centre if administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Largest city if largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- do local languageRows = buildLanguageRows(args) if languageRows then table.insert(rows, languageRows) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p dl7o04rrpsztd1dfk5xsa7htbiaxpdf 392884 392883 2026-09-06T23:19:02Z MacTire02 219 ++ 392884 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- DISAMBIGUATION GUARD -------------------------------------------------- -- Some Wikidata statements resolve to a general/ambiguous -- item rather than the specific thing we want (e.g. a -- country's "most populous urban area" pointing at the -- ambiguous "New York" (Q22654) instead of "New York City" -- (Q60)). Skip anything flagged as a disambiguation page. local function isDisambiguationPage(entity) if not entity then return false end local statements = entity:getBestStatements("P31") if not statements then return false end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" and mainsnak.datavalue.value.id == "Q4167410" then return true end end return false end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity and not isDisambiguationPage(linkedEntity) then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getFlagArmsData(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if not flag and not arms then return nil end local name = getCountryGenitive(args) or "" local data = {} if flag then data.flag = { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px", link = "Brattagh " .. name, label = getManual(args, { "fo-heidyl_brattagh" }) or "Brattagh" } end if arms then local kind = getManual(args, { "art_sorçh_cowrey" }) or getManual(args, { "sorçh_cowrey" }) or "Armys" data.arms = { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "85px", link = kind .. " " .. name, label = getManual(args, { "sorçh_cowrey" }) or "Armys" } end return data end -------------------------------------------------- -- FLAG / ARMS BLOCK -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} if data.flag then table.insert(imageCells, '<td align="center" style="' .. (data.arms and "width:58%; " or "") .. 'vertical-align:middle;">[[Coadan:' .. data.flag.image .. '|' .. data.flag.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.flag.link .. '|' .. data.flag.label .. ']]</small></td>' ) end if data.arms then table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">[[Coadan:' .. data.arms.image .. '|' .. data.arms.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.arms.link .. '|' .. data.arms.label .. ']]</small></td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = '"' .. motto .. '"', reference = reference and "<ref>" .. reference .. "</ref>" or nil } end local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = '"' .. value.text .. '"', reference = getWikidataReference(statement) } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- local function getLanguagesFromWikidata() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P37") if not statements or #statements == 0 then return {} end local languages = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local langEntity = mw.wikibase.getEntity(id) if langEntity then local label = langEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(languages, { text = label, entity = langEntity, role = role, reference = getWikidataReference(statement) }) end end end end return languages end local function classifyLanguages(languages) local result = { official = {}, regional = {}, minority = {} } for _, language in ipairs(languages) do local role = language.role or "" local lowerRole = mw.ustring.lower(role) if mw.ustring.find(lowerRole, "minority") then table.insert(result.minority, language) elseif mw.ustring.find(lowerRole, "regional") then table.insert(result.regional, language) else table.insert(result.official, language) end end return result end local function makeLanguageLink(language) if not language or not language.text then return "" end local title = nil if language.entity then title = language.entity:getSitelink("gvwiki") end if not title or title == "" then title = language.text end if not title or title == "" then return language.text end return "[[" .. title .. "|" .. language.text .. "]]" end local function joinLanguageList(languages) if not languages or #languages == 0 then return nil end local parts = {} for _, language in ipairs(languages) do local text = makeLanguageLink(language) if language.reference then text = text .. language.reference end table.insert(parts, text) end if #parts == 0 then return nil end return table.concat(parts, ", ") end -- Splits text on a top-level separator character, without -- splitting inside {{...}} or [[...]] (so a piped wikilink -- like [[Country|Display]], or a nested template, doesn't -- get miscounted as two items). local function splitTopLevel(text, sep) local parts = {} local current = {} local depthCurly = 0 local depthSquare = 0 local len = mw.ustring.len(text) local i = 1 while i <= len do local two = mw.ustring.sub(text, i, i + 1) local one = mw.ustring.sub(text, i, i) if two == "{{" then depthCurly = depthCurly + 1 table.insert(current, two) i = i + 2 elseif two == "}}" and depthCurly > 0 then depthCurly = depthCurly - 1 table.insert(current, two) i = i + 2 elseif two == "[[" then depthSquare = depthSquare + 1 table.insert(current, two) i = i + 2 elseif two == "]]" and depthSquare > 0 then depthSquare = depthSquare - 1 table.insert(current, two) i = i + 2 elseif one == sep and depthCurly == 0 and depthSquare == 0 then table.insert(parts, table.concat(current)) current = {} i = i + 1 else table.insert(current, one) i = i + 1 end end table.insert(parts, table.concat(current)) return parts end -- Counts the items inside a {{hlist|...}}/{{flatlist|...}}/ -- {{ubl|...}}/{{unbulleted list|...}} template call (the -- convention most legacy articles already use for this -- field). Returns nil if the text isn't one of these, so -- the caller can fall back to a plain heuristic. -- Finds the first call to a template matching namePattern -- anywhere in text (not just at the start/whole-string), -- respecting nested {{...}} so a template argument that -- itself contains braces doesn't break the search. Returns -- the inner content (everything after the first "|") or nil -- if no such template call is found. local function findTemplateCall(text, namePattern) local searchPattern = "{{%s*" .. namePattern .. "%s*|" local matchStart, matchEnd = mw.ustring.find(text, searchPattern) if not matchStart then return nil end local contentStart = matchEnd + 1 local depth = 1 local i = contentStart local len = mw.ustring.len(text) while i <= len do local two = mw.ustring.sub(text, i, i + 1) if two == "{{" then depth = depth + 1 i = i + 2 elseif two == "}}" then depth = depth - 1 i = i + 2 if depth == 0 then local contentEnd = i - 3 return mw.ustring.sub(text, contentStart, contentEnd) end else i = i + 1 end end return nil end -- Pulls any <ref>...</ref> (or self-closing <ref .../>) tags -- out of text, returning the text with them removed plus the -- extracted ref markup (already-valid <ref> tags, ready to -- use as-is - not to be re-wrapped). Returns (text, nil) if -- none are found. local function extractReferences(text) if not text then return text, nil end local refs = {} local cleaned = mw.ustring.gsub(text, "<ref[^>]*>.-</ref>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.ustring.gsub(cleaned, "<ref[^>]*/>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.text.trim(cleaned) if #refs == 0 then return cleaned, nil end return cleaned, table.concat(refs) end local function countHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local segments = splitTopLevel(inner, "|") local count = 0 for _, segment in ipairs(segments) do local trimmedSegment = mw.text.trim(segment) -- Skip named parameters (class=, style=, indent=, etc.) -- rather than counting them as list items. if trimmedSegment ~= "" and not mw.ustring.find(trimmedSegment, "^[%w_%- ]+=") then count = count + 1 end end return count end -- Count of items in a manually-entered language/list field, -- used to decide between a singular ("çhengey") and plural -- ("çhengaghyn") label. Wikidata-derived lists are counted -- exactly (see getLanguageData). Handles the {{hlist}} family -- (searched for anywhere in the text, not just as the entire -- value, since editors often append a trailing <ref> after -- the closing "}}") most legacy articles already use; -- otherwise falls back to a plain comma-count heuristic. local function countListItems(text) if not text or text == "" then return 0 end local hlistCount = countHlistItems(text) if hlistCount then return hlistCount end local count = 0 for _ in mw.text.gsplit(text, ",", true) do count = count + 1 end return count end -- Resolves one language tier from its raw manual parameter: -- strips out any inline <ref> tags (used as-is, since they're -- already valid markup), counts the list on the ref-stripped -- text, then re-appends the extracted ref(s) and/or a manual -- imraa_ reference (which - unlike an inline <ref> - is raw -- citation text that still needs wrapping) to the display value. local function buildLanguageValue(raw, manualReference) if not raw or mw.ustring.lower(mw.text.trim(raw)) == "none" then return nil, 0 end local cleaned, inlineRefs = extractReferences(raw) local count = countListItems(cleaned) local display = cleaned if inlineRefs then display = display .. inlineRefs end if manualReference then display = display .. "<ref>" .. manualReference .. "</ref>" end return display, count end local function getLanguageData(args) local officialRaw = getManual(args, { "çhengaghyn_oikoil", "çhengey_oikoil" }) local officialReference = getManual(args, { "imraa_çhengaghyn_oikoil", "imraa_çhengey_oikoil" }) local regionalRaw = getManual(args, { "çhengaghyn_ardjynagh", "çhengey_ardjynagh" }) local regionalReference = getManual(args, { "imraa_çhengaghyn_ardjynagh", "imraa_çhengey_ardjynagh" }) local minorityRaw = getManual(args, { "mynçhengaghyn", "mynçhengey" }) local minorityReference = getManual(args, { "imraa_mynçhengaghyn", "imraa_mynçhengey" }) local otherRaw = getManual(args, { "çhengaghyn", "çhengey" }) local otherReference = getManual(args, { "imraa_çhengaghyn", "imraa_çhengey" }) local otherLabel = getManual(args, { "sorçh_çhengaghyn" }) local result = { otherLabel = otherLabel } result.official, result.officialCount = buildLanguageValue(officialRaw, officialReference) result.regional, result.regionalCount = buildLanguageValue(regionalRaw, regionalReference) result.minority, result.minorityCount = buildLanguageValue(minorityRaw, minorityReference) result.other, result.otherCount = buildLanguageValue(otherRaw, otherReference) -- Only reach for Wikidata if none of the three tiers -- were set manually - a manual "none" or partial set -- of overrides always wins over the auto-fetch. if not result.official and not result.regional and not result.minority then local classified = classifyLanguages(getLanguagesFromWikidata()) result.official = joinLanguageList(classified.official) result.officialCount = #classified.official result.regional = joinLanguageList(classified.regional) result.regionalCount = #classified.regional result.minority = joinLanguageList(classified.minority) result.minorityCount = #classified.minority end return result end local function buildLanguageRows(args) local data = getLanguageData(args) local rows = {} if data.official then local officialLabel = data.officialCount > 1 and "[[Çhengey oikoil|Çhengaghyn oikoil]]" or "[[Çhengey oikoil]]" local officialRow = '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. officialLabel .. '</th><td style="vertical-align:top;">' .. data.official .. '</td></tr>' if data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn&nbsp;ardjynagh er&nbsp;enney" or "Çhengey&nbsp;ardjynagh er&nbsp;enney" officialRow = officialRow .. '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:normal;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th>' .. '<td style="vertical-align:top;">' .. data.regional .. '</td></tr>' end table.insert(rows, officialRow) elseif data.regional then -- Regional recognised even without a separate -- official-language statement. local regionalLabel = data.regionalCount > 1 and "Çhengaghyn ardjynagh er enney" or "Çhengey ardjynagh er enney" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th><td style="vertical-align:top;">' .. data.regional .. '</td></tr>' ) end if data.minority then local minorityLabel = data.minorityCount > 1 and "[[Mynçhengey|Mynçhengaghyn]]" or "[[Mynçhengey]]" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. minorityLabel .. '</th><td style="vertical-align:top;">' .. data.minority .. '</td></tr>' ) end if data.other then local otherLabel = data.otherLabel or (data.otherCount > 1 and "Çhengaghyn" or "Çhengey") table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. otherLabel .. '</th><td style="vertical-align:top;">' .. data.other .. '</td></tr>' ) end if #rows == 0 then return nil end return table.concat(rows) end function p.languages(frame) local args = getArgs(frame) return buildLanguageRows(args) end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCityEntityFromTitle(value) local title = normaliseCityName(value) if title == "" then return nil end local entityId = mw.wikibase.getEntityIdForTitle(title) if not entityId then return nil end return mw.wikibase.getEntity(entityId) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then return { text = capital, entity = getCityEntityFromTitle(capital), reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or entity:getLabel(), entity = entity, reference = getWikidataReference(statement) } end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then return { text = city, entity = getCityEntityFromTitle(city), reference = nil } end local country = mw.wikibase.getEntityObject() if not country then return nil end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id local target = mw.wikibase.getEntity(targetId) if target and not isDisambiguationPage(target) then local sitelink = target:getSitelink("gvwiki") return { text = sitelink or target:getLabel(), entity = target, reference = getWikidataReference(statement) } end end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) return { capital = getCapitalData(args), administrative = getAdministrativeCentreData(args), largest = getLargestCityData(args), labels = getCityLabels(args) } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end local title = nil if city.entity then title = city.entity:getSitelink("gvwiki") end if not title or title == "" then title = normaliseCityName(city.text) end if not title or title == "" then return "" end return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -------------------------------------------------- -- HEADER -------------------------------------------------- do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -------------------------------------------------- -- FLAG / ARMS -------------------------------------------------- do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -------------------------------------------------- -- MOTTO / ANTHEM -------------------------------------------------- do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -------------------------------------------------- -- CAPITAL / ADMINISTRATIVE CENTRE / LARGEST CITY -------------------------------------------------- do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels -- Add one divider before the city section only. if capital or administrative or largest then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '"></td></tr>' ) end -- Capital if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Administrative centre if administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Largest city if largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- do local languageRows = buildLanguageRows(args) if languageRows then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '"></td></tr>' ) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p gw0pp4z4co9yc92nlj336ceiqc71lh5 392885 392884 2026-09-06T23:46:12Z MacTire02 219 ++ 392885 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- DISAMBIGUATION GUARD -------------------------------------------------- -- Some Wikidata statements resolve to a general/ambiguous -- item rather than the specific thing we want (e.g. a -- country's "most populous urban area" pointing at the -- ambiguous "New York" (Q22654) instead of "New York City" -- (Q60)). Skip anything flagged as a disambiguation page. local function isDisambiguationPage(entity) if not entity then return false end local statements = entity:getBestStatements("P31") if not statements then return false end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" and mainsnak.datavalue.value.id == "Q4167410" then return true end end return false end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity and not isDisambiguationPage(linkedEntity) then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- IMAGES -------------------------------------------------- local function getFlagArmsData(args) local flag = getManual(args, { "jalloo_brattagh" }) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end if not flag and not arms then return nil end local name = getCountryGenitive(args) or "" local data = {} if flag then data.flag = { image = flag, width = getManual(args, { "lheead_brattagh" }) or "125px", link = "Brattagh " .. name, label = getManual(args, { "fo-heidyl_brattagh" }) or "Brattagh" } end if arms then local kind = getManual(args, { "art_sorçh_cowrey" }) or getManual(args, { "sorçh_cowrey" }) or "Armys" data.arms = { image = arms, width = getManual(args, { "lheead_armys", "lheead_cleinney", "lheead_cowrey" }) or "85px", link = kind .. " " .. name, label = getManual(args, { "sorçh_cowrey" }) or "Armys" } end return data end -------------------------------------------------- -- FLAG / ARMS BLOCK -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} if data.flag then table.insert(imageCells, '<td align="center" style="' .. (data.arms and "width:58%; " or "") .. 'vertical-align:middle;">[[Coadan:' .. data.flag.image .. '|' .. data.flag.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.flag.link .. '|' .. data.flag.label .. ']]</small></td>' ) end if data.arms then table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">[[Coadan:' .. data.arms.image .. '|' .. data.arms.width .. ']]</td>' ) table.insert(captionCells, '<td align="center"><small>[[' .. data.arms.link .. '|' .. data.arms.label .. ']]</small></td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = '"' .. motto .. '"', reference = reference and "<ref>" .. reference .. "</ref>" or nil } end local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = '"' .. value.text .. '"', reference = getWikidataReference(statement) } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- local function getLanguagesFromWikidata() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P37") if not statements or #statements == 0 then return {} end local languages = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local langEntity = mw.wikibase.getEntity(id) if langEntity then local label = langEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(languages, { text = label, role = role, reference = getWikidataReference(statement) }) end end end end return languages end local function classifyLanguages(languages) local result = { official = {}, regional = {}, minority = {} } for _, language in ipairs(languages) do local role = language.role or "" local lowerRole = mw.ustring.lower(role) if mw.ustring.find(lowerRole, "minority") then table.insert(result.minority, language) elseif mw.ustring.find(lowerRole, "regional") then table.insert(result.regional, language) else table.insert(result.official, language) end end return result end local function joinLanguageList(languages) if not languages or #languages == 0 then return nil end local parts = {} for _, language in ipairs(languages) do local text = language.text if language.reference then text = text .. language.reference end table.insert(parts, text) end if #parts == 0 then return nil end return table.concat(parts, ", ") end -- Splits text on a top-level separator character, without -- splitting inside {{...}} or [[...]] (so a piped wikilink -- like [[Country|Display]], or a nested template, doesn't -- get miscounted as two items). local function splitTopLevel(text, sep) local parts = {} local current = {} local depthCurly = 0 local depthSquare = 0 local len = mw.ustring.len(text) local i = 1 while i <= len do local two = mw.ustring.sub(text, i, i + 1) local one = mw.ustring.sub(text, i, i) if two == "{{" then depthCurly = depthCurly + 1 table.insert(current, two) i = i + 2 elseif two == "}}" and depthCurly > 0 then depthCurly = depthCurly - 1 table.insert(current, two) i = i + 2 elseif two == "[[" then depthSquare = depthSquare + 1 table.insert(current, two) i = i + 2 elseif two == "]]" and depthSquare > 0 then depthSquare = depthSquare - 1 table.insert(current, two) i = i + 2 elseif one == sep and depthCurly == 0 and depthSquare == 0 then table.insert(parts, table.concat(current)) current = {} i = i + 1 else table.insert(current, one) i = i + 1 end end table.insert(parts, table.concat(current)) return parts end -- Counts the items inside a {{hlist|...}}/{{flatlist|...}}/ -- {{ubl|...}}/{{unbulleted list|...}} template call (the -- convention most legacy articles already use for this -- field). Returns nil if the text isn't one of these, so -- the caller can fall back to a plain heuristic. -- Finds the first call to a template matching namePattern -- anywhere in text (not just at the start/whole-string), -- respecting nested {{...}} so a template argument that -- itself contains braces doesn't break the search. Returns -- the inner content (everything after the first "|") or nil -- if no such template call is found. local function findTemplateCall(text, namePattern) local searchPattern = "{{%s*" .. namePattern .. "%s*|" local matchStart, matchEnd = mw.ustring.find(text, searchPattern) if not matchStart then return nil end local contentStart = matchEnd + 1 local depth = 1 local i = contentStart local len = mw.ustring.len(text) while i <= len do local two = mw.ustring.sub(text, i, i + 1) if two == "{{" then depth = depth + 1 i = i + 2 elseif two == "}}" then depth = depth - 1 i = i + 2 if depth == 0 then local contentEnd = i - 3 return mw.ustring.sub(text, contentStart, contentEnd) end else i = i + 1 end end return nil end -- Pulls any <ref>...</ref> (or self-closing <ref .../>) tags -- out of text, returning the text with them removed plus the -- extracted ref markup (already-valid <ref> tags, ready to -- use as-is - not to be re-wrapped). Returns (text, nil) if -- none are found. local function extractReferences(text) if not text then return text, nil end local refs = {} local cleaned = mw.ustring.gsub(text, "<ref[^>]*>.-</ref>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.ustring.gsub(cleaned, "<ref[^>]*/>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.text.trim(cleaned) if #refs == 0 then return cleaned, nil end return cleaned, table.concat(refs) end local function countHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local segments = splitTopLevel(inner, "|") local count = 0 for _, segment in ipairs(segments) do local trimmedSegment = mw.text.trim(segment) -- Skip named parameters (class=, style=, indent=, etc.) -- rather than counting them as list items. if trimmedSegment ~= "" and not mw.ustring.find(trimmedSegment, "^[%w_%- ]+=") then count = count + 1 end end return count end -- Count of items in a manually-entered language/list field, -- used to decide between a singular ("çhengey") and plural -- ("çhengaghyn") label. Wikidata-derived lists are counted -- exactly (see getLanguageData). Handles the {{hlist}} family -- (searched for anywhere in the text, not just as the entire -- value, since editors often append a trailing <ref> after -- the closing "}}") most legacy articles already use; -- otherwise falls back to a plain comma-count heuristic. local function countListItems(text) if not text or text == "" then return 0 end local hlistCount = countHlistItems(text) if hlistCount then return hlistCount end local count = 0 for _ in mw.text.gsplit(text, ",", true) do count = count + 1 end return count end -- Resolves one language tier from its raw manual parameter: -- strips out any inline <ref> tags (used as-is, since they're -- already valid markup), counts the list on the ref-stripped -- text, then re-appends the extracted ref(s) and/or a manual -- imraa_ reference (which - unlike an inline <ref> - is raw -- citation text that still needs wrapping) to the display value. local function buildLanguageValue(raw, manualReference) if not raw or mw.ustring.lower(mw.text.trim(raw)) == "none" then return nil, 0 end local cleaned, inlineRefs = extractReferences(raw) local count = countListItems(cleaned) local display = cleaned if inlineRefs then display = display .. inlineRefs end if manualReference then display = display .. "<ref>" .. manualReference .. "</ref>" end return display, count end local function getLanguageData(args) local officialRaw = getManual(args, { "çhengaghyn_oikoil", "çhengey_oikoil" }) local officialReference = getManual(args, { "imraa_çhengaghyn_oikoil", "imraa_çhengey_oikoil" }) local regionalRaw = getManual(args, { "çhengaghyn_ardjynagh", "çhengey_ardjynagh" }) local regionalReference = getManual(args, { "imraa_çhengaghyn_ardjynagh", "imraa_çhengey_ardjynagh" }) local minorityRaw = getManual(args, { "mynçhengaghyn", "mynçhengey" }) local minorityReference = getManual(args, { "imraa_mynçhengaghyn", "imraa_mynçhengey" }) local otherRaw = getManual(args, { "çhengaghyn", "çhengey" }) local otherReference = getManual(args, { "imraa_çhengaghyn", "imraa_çhengey" }) local otherLabel = getManual(args, { "sorçh_çhengaghyn" }) local result = { otherLabel = otherLabel } result.official, result.officialCount = buildLanguageValue(officialRaw, officialReference) result.regional, result.regionalCount = buildLanguageValue(regionalRaw, regionalReference) result.minority, result.minorityCount = buildLanguageValue(minorityRaw, minorityReference) result.other, result.otherCount = buildLanguageValue(otherRaw, otherReference) -- Only reach for Wikidata if none of the three tiers -- were set manually - a manual "none" or partial set -- of overrides always wins over the auto-fetch. if not result.official and not result.regional and not result.minority then local classified = classifyLanguages(getLanguagesFromWikidata()) result.official = joinLanguageList(classified.official) result.officialCount = #classified.official result.regional = joinLanguageList(classified.regional) result.regionalCount = #classified.regional result.minority = joinLanguageList(classified.minority) result.minorityCount = #classified.minority end return result end local function buildLanguageRows(args) local data = getLanguageData(args) local rows = {} if data.official then local officialLabel = data.officialCount > 1 and "[[Çhengey oikoil|Çhengaghyn oikoil]]" or "[[Çhengey oikoil]]" local officialRow = '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. officialLabel .. '</th><td style="vertical-align:top;">' .. data.official .. '</td></tr>' if data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn&nbsp;ardjynagh er&nbsp;enney" or "Çhengey&nbsp;ardjynagh er&nbsp;enney" officialRow = officialRow .. '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:normal;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th>' .. '<td style="vertical-align:top;">' .. data.regional .. '</td></tr>' end table.insert(rows, officialRow) elseif data.regional then -- Regional recognised even without a separate -- official-language statement. local regionalLabel = data.regionalCount > 1 and "Çhengaghyn ardjynagh er enney" or "Çhengey ardjynagh er enney" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th><td style="vertical-align:top;">' .. data.regional .. '</td></tr>' ) end if data.minority then local minorityLabel = data.minorityCount > 1 and "[[Mynçhengey|Mynçhengaghyn]]" or "[[Mynçhengey]]" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. minorityLabel .. '</th><td style="vertical-align:top;">' .. data.minority .. '</td></tr>' ) end if data.other then local otherLabel = data.otherLabel or (data.otherCount > 1 and "Çhengaghyn" or "Çhengey") table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. otherLabel .. '</th><td style="vertical-align:top;">' .. data.other .. '</td></tr>' ) end if #rows == 0 then return nil end return table.concat(rows) end function p.languages(frame) local args = getArgs(frame) return buildLanguageRows(args) end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCityEntityFromTitle(value) local title = normaliseCityName(value) if title == "" then return nil end local entityId = mw.wikibase.getEntityIdForTitle(title) if not entityId then return nil end return mw.wikibase.getEntity(entityId) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then return { text = capital, entity = getCityEntityFromTitle(capital), reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or entity:getLabel(), entity = entity, reference = getWikidataReference(statement) } end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then return { text = city, entity = getCityEntityFromTitle(city), reference = nil } end local country = mw.wikibase.getEntityObject() if not country then return nil end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id local target = mw.wikibase.getEntity(targetId) if target and not isDisambiguationPage(target) then local sitelink = target:getSitelink("gvwiki") return { text = sitelink or target:getLabel(), entity = target, reference = getWikidataReference(statement) } end end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) return { capital = getCapitalData(args), administrative = getAdministrativeCentreData(args), largest = getLargestCityData(args), labels = getCityLabels(args) } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end local title = nil if city.entity then title = city.entity:getSitelink("gvwiki") end if not title or title == "" then title = normaliseCityName(city.text) end if not title or title == "" then return "" end return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -------------------------------------------------- -- HEADER -------------------------------------------------- do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -------------------------------------------------- -- FLAG / ARMS -------------------------------------------------- do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -------------------------------------------------- -- MOTTO / ANTHEM -------------------------------------------------- do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -------------------------------------------------- -- CAPITAL / ADMINISTRATIVE CENTRE / LARGEST CITY -------------------------------------------------- do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels -- Add one divider before the city section only. if capital or administrative or largest then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '"></td></tr>' ) end -- Capital if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Administrative centre if administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Largest city if largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- do local languageRows = buildLanguageRows(args) if languageRows then table.insert(rows, languageRows) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p 0jov9gpkp76wo6gihpdsgp6n18a6hl4 392886 392885 2026-09-07T00:06:44Z MacTire02 219 prowal red noa 392886 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- DISAMBIGUATION GUARD -------------------------------------------------- -- Some Wikidata statements resolve to a general/ambiguous -- item rather than the specific thing we want (e.g. a -- country's "most populous urban area" pointing at the -- ambiguous "New York" (Q22654) instead of "New York City" -- (Q60)). Skip anything flagged as a disambiguation page. local function isDisambiguationPage(entity) if not entity then return false end local statements = entity:getBestStatements("P31") if not statements then return false end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" and mainsnak.datavalue.value.id == "Q4167410" then return true end end return false end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity and not isDisambiguationPage(linkedEntity) then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- FLAG BORDER CHECK -------------------------------------------------- -- List of countries with non-rectangular flags (no border needed) local NON_RECTANGULAR_FLAGS = { ["Flag of Nepal.svg"] = true, ["Flag of Ohio.svg"] = true, ["Flag of Switzerland.svg"] = true, } -- Check if a flag needs a border local function needsFlagBorder(flagFile) if not flagFile then return true end if NON_RECTANGULAR_FLAGS[flagFile] then return false end local lowerFile = mw.ustring.lower(flagFile) if mw.ustring.find(lowerFile, "nepal") then return false end return true end -------------------------------------------------- -- MULTI-FLAG SUPPORT -------------------------------------------------- local function getFlagData(args) -- Get primary flag local flag = getManual(args, {"jalloo_brattagh"}) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end -- Get second flag (if any) local flag2 = getManual(args, {"jalloo_brattagh_2", "jalloo_brattagh_elley"}) if flag2 and mw.ustring.lower(flag2) == "none" then flag2 = nil elseif not flag2 then flag2 = getWikidataImage("P163") end -- Get arms local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end -- Get second arms (if any) local arms2 = getManual(args, { "jalloo_armys_2", "jalloo_cleinney_2" }) if arms2 and mw.ustring.lower(arms2) == "none" then arms2 = nil elseif not arms2 then arms2 = getWikidataImage("P237") end if not flag and not flag2 and not arms and not arms2 then return nil end local name = getCountryGenitive(args) or "" local data = { flags = {}, armses = {} } -- Primary flag if flag then local flagWidth = getManual(args, {"lheead_brattagh"}) or "125px" local hasBorder = needsFlagBorder(flag) table.insert(data.flags, { image = flag, width = flagWidth, hasBorder = hasBorder, link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh"}) or "Brattagh", isPrimary = true }) end -- Second flag if flag2 then local flag2Width = getManual(args, {"lheead_brattagh_2", "lheead_brattagh"}) or "100px" local hasBorder2 = needsFlagBorder(flag2) table.insert(data.flags, { image = flag2, width = flag2Width, hasBorder = hasBorder2, link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh_2"}) or "Brattagh elley", isPrimary = false }) end -- Primary arms if arms then local kind = getManual(args, {"art_sorçh_cowrey"}) or getManual(args, {"sorçh_cowrey"}) or "Armys" table.insert(data.armses, { image = arms, width = getManual(args, {"lheead_armys", "lheead_cleinney", "lheead_cowrey"}) or "85px", link = kind .. " " .. name, label = getManual(args, {"sorçh_cowrey"}) or "Armys", isPrimary = true }) end -- Second arms if arms2 then table.insert(data.armses, { image = arms2, width = getManual(args, {"lheead_armys_2", "lheead_cleinney_2"}) or "85px", link = "Armys " .. name, label = getManual(args, {"sorçh_cowrey_2"}) or "Armys", isPrimary = false }) end return data end -------------------------------------------------- -- FLAG / ARMS BLOCK (UPDATED) -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} local hasFlags = #data.flags > 0 local hasArms = #data.armses > 0 -- Build flag column if hasFlags then local flagContent = {} for i, flagData in ipairs(data.flags) do local borderStyle = "" if flagData.hasBorder then borderStyle = '|style="border:1px solid #a2a9b1;"' end local flagImage = '[[Coadan:' .. flagData.image .. '|' .. flagData.width .. borderStyle .. ']]' table.insert(flagContent, flagImage) end local combinedFlags = table.concat(flagContent, '<br/>') table.insert(imageCells, '<td align="center" style="' .. (hasArms and "width:58%; " or "width:100%; ") .. 'vertical-align:middle;">' .. combinedFlags .. '</td>' ) local flagCaptions = {} for i, flagData in ipairs(data.flags) do table.insert(flagCaptions, '<small>[[' .. flagData.link .. '|' .. flagData.label .. ']]</small>' ) end table.insert(captionCells, '<td align="center">' .. table.concat(flagCaptions, '<br/>') .. '</td>' ) end -- Build arms column if hasArms then local armsContent = {} for i, armsData in ipairs(data.armses) do local armsImage = '[[Coadan:' .. armsData.image .. '|' .. armsData.width .. ']]' table.insert(armsContent, armsImage) end local combinedArms = table.concat(armsContent, '<br/>') table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">' .. combinedArms .. '</td>' ) local armsCaptions = {} for i, armsData in ipairs(data.armses) do table.insert(armsCaptions, '<small>[[' .. armsData.link .. '|' .. armsData.label .. ']]</small>' ) end table.insert(captionCells, '<td align="center">' .. table.concat(armsCaptions, '<br/>') .. '</td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- UPDATED getFlagArmsData (replaces old function) -------------------------------------------------- local function getFlagArmsData(args) return getFlagData(args) end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = '"' .. motto .. '"', reference = reference and "<ref>" .. reference .. "</ref>" or nil } end local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = '"' .. value.text .. '"', reference = getWikidataReference(statement) } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- local function getLanguagesFromWikidata() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P37") if not statements or #statements == 0 then return {} end local languages = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local langEntity = mw.wikibase.getEntity(id) if langEntity then local label = langEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(languages, { text = label, role = role, reference = getWikidataReference(statement) }) end end end end return languages end local function classifyLanguages(languages) local result = { official = {}, regional = {}, minority = {} } for _, language in ipairs(languages) do local role = language.role or "" local lowerRole = mw.ustring.lower(role) if mw.ustring.find(lowerRole, "minority") then table.insert(result.minority, language) elseif mw.ustring.find(lowerRole, "regional") then table.insert(result.regional, language) else table.insert(result.official, language) end end return result end local function joinLanguageList(languages) if not languages or #languages == 0 then return nil end local parts = {} for _, language in ipairs(languages) do local text = language.text if language.reference then text = text .. language.reference end table.insert(parts, text) end if #parts == 0 then return nil end return table.concat(parts, ", ") end -- Splits text on a top-level separator character, without -- splitting inside {{...}} or [[...]] (so a piped wikilink -- like [[Country|Display]], or a nested template, doesn't -- get miscounted as two items). local function splitTopLevel(text, sep) local parts = {} local current = {} local depthCurly = 0 local depthSquare = 0 local len = mw.ustring.len(text) local i = 1 while i <= len do local two = mw.ustring.sub(text, i, i + 1) local one = mw.ustring.sub(text, i, i) if two == "{{" then depthCurly = depthCurly + 1 table.insert(current, two) i = i + 2 elseif two == "}}" and depthCurly > 0 then depthCurly = depthCurly - 1 table.insert(current, two) i = i + 2 elseif two == "[[" then depthSquare = depthSquare + 1 table.insert(current, two) i = i + 2 elseif two == "]]" and depthSquare > 0 then depthSquare = depthSquare - 1 table.insert(current, two) i = i + 2 elseif one == sep and depthCurly == 0 and depthSquare == 0 then table.insert(parts, table.concat(current)) current = {} i = i + 1 else table.insert(current, one) i = i + 1 end end table.insert(parts, table.concat(current)) return parts end -- Counts the items inside a {{hlist|...}}/{{flatlist|...}}/ -- {{ubl|...}}/{{unbulleted list|...}} template call (the -- convention most legacy articles already use for this -- field). Returns nil if the text isn't one of these, so -- the caller can fall back to a plain heuristic. -- Finds the first call to a template matching namePattern -- anywhere in text (not just at the start/whole-string), -- respecting nested {{...}} so a template argument that -- itself contains braces doesn't break the search. Returns -- the inner content (everything after the first "|") or nil -- if no such template call is found. local function findTemplateCall(text, namePattern) local searchPattern = "{{%s*" .. namePattern .. "%s*|" local matchStart, matchEnd = mw.ustring.find(text, searchPattern) if not matchStart then return nil end local contentStart = matchEnd + 1 local depth = 1 local i = contentStart local len = mw.ustring.len(text) while i <= len do local two = mw.ustring.sub(text, i, i + 1) if two == "{{" then depth = depth + 1 i = i + 2 elseif two == "}}" then depth = depth - 1 i = i + 2 if depth == 0 then local contentEnd = i - 3 return mw.ustring.sub(text, contentStart, contentEnd) end else i = i + 1 end end return nil end -- Pulls any <ref>...</ref> (or self-closing <ref .../>) tags -- out of text, returning the text with them removed plus the -- extracted ref markup (already-valid <ref> tags, ready to -- use as-is - not to be re-wrapped). Returns (text, nil) if -- none are found. local function extractReferences(text) if not text then return text, nil end local refs = {} local cleaned = mw.ustring.gsub(text, "<ref[^>]*>.-</ref>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.ustring.gsub(cleaned, "<ref[^>]*/>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.text.trim(cleaned) if #refs == 0 then return cleaned, nil end return cleaned, table.concat(refs) end local function countHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local segments = splitTopLevel(inner, "|") local count = 0 for _, segment in ipairs(segments) do local trimmedSegment = mw.text.trim(segment) -- Skip named parameters (class=, style=, indent=, etc.) -- rather than counting them as list items. if trimmedSegment ~= "" and not mw.ustring.find(trimmedSegment, "^[%w_%- ]+=") then count = count + 1 end end return count end -- Count of items in a manually-entered language/list field, -- used to decide between a singular ("çhengey") and plural -- ("çhengaghyn") label. Wikidata-derived lists are counted -- exactly (see getLanguageData). Handles the {{hlist}} family -- (searched for anywhere in the text, not just as the entire -- value, since editors often append a trailing <ref> after -- the closing "}}") most legacy articles already use; -- otherwise falls back to a plain comma-count heuristic. local function countListItems(text) if not text or text == "" then return 0 end local hlistCount = countHlistItems(text) if hlistCount then return hlistCount end local count = 0 for _ in mw.text.gsplit(text, ",", true) do count = count + 1 end return count end -- Resolves one language tier from its raw manual parameter: -- strips out any inline <ref> tags (used as-is, since they're -- already valid markup), counts the list on the ref-stripped -- text, then re-appends the extracted ref(s) and/or a manual -- imraa_ reference (which - unlike an inline <ref> - is raw -- citation text that still needs wrapping) to the display value. local function buildLanguageValue(raw, manualReference) if not raw or mw.ustring.lower(mw.text.trim(raw)) == "none" then return nil, 0 end local cleaned, inlineRefs = extractReferences(raw) local count = countListItems(cleaned) local display = cleaned if inlineRefs then display = display .. inlineRefs end if manualReference then display = display .. "<ref>" .. manualReference .. "</ref>" end return display, count end local function getLanguageData(args) local officialRaw = getManual(args, { "çhengaghyn_oikoil", "çhengey_oikoil" }) local officialReference = getManual(args, { "imraa_çhengaghyn_oikoil", "imraa_çhengey_oikoil" }) local regionalRaw = getManual(args, { "çhengaghyn_ardjynagh", "çhengey_ardjynagh" }) local regionalReference = getManual(args, { "imraa_çhengaghyn_ardjynagh", "imraa_çhengey_ardjynagh" }) local minorityRaw = getManual(args, { "mynçhengaghyn", "mynçhengey" }) local minorityReference = getManual(args, { "imraa_mynçhengaghyn", "imraa_mynçhengey" }) local otherRaw = getManual(args, { "çhengaghyn", "çhengey" }) local otherReference = getManual(args, { "imraa_çhengaghyn", "imraa_çhengey" }) local otherLabel = getManual(args, { "sorçh_çhengaghyn" }) local result = { otherLabel = otherLabel } result.official, result.officialCount = buildLanguageValue(officialRaw, officialReference) result.regional, result.regionalCount = buildLanguageValue(regionalRaw, regionalReference) result.minority, result.minorityCount = buildLanguageValue(minorityRaw, minorityReference) result.other, result.otherCount = buildLanguageValue(otherRaw, otherReference) -- Only reach for Wikidata if none of the three tiers -- were set manually - a manual "none" or partial set -- of overrides always wins over the auto-fetch. if not result.official and not result.regional and not result.minority then local classified = classifyLanguages(getLanguagesFromWikidata()) result.official = joinLanguageList(classified.official) result.officialCount = #classified.official result.regional = joinLanguageList(classified.regional) result.regionalCount = #classified.regional result.minority = joinLanguageList(classified.minority) result.minorityCount = #classified.minority end return result end local function buildLanguageRows(args) local data = getLanguageData(args) local rows = {} if data.official then local officialLabel = data.officialCount > 1 and "[[Çhengey oikoil|Çhengaghyn oikoil]]" or "[[Çhengey oikoil]]" local officialRow = '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. officialLabel .. '</th><td style="vertical-align:top;">' .. data.official .. '</td></tr>' if data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn&nbsp;ardjynagh er&nbsp;enney" or "Çhengey&nbsp;ardjynagh er&nbsp;enney" officialRow = officialRow .. '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:normal;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th>' .. '<td style="vertical-align:top;">' .. data.regional .. '</td></tr>' end table.insert(rows, officialRow) elseif data.regional then -- Regional recognised even without a separate -- official-language statement. local regionalLabel = data.regionalCount > 1 and "Çhengaghyn ardjynagh er enney" or "Çhengey ardjynagh er enney" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th><td style="vertical-align:top;">' .. data.regional .. '</td></tr>' ) end if data.minority then local minorityLabel = data.minorityCount > 1 and "[[Mynçhengey|Mynçhengaghyn]]" or "[[Mynçhengey]]" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. minorityLabel .. '</th><td style="vertical-align:top;">' .. data.minority .. '</td></tr>' ) end if data.other then local otherLabel = data.otherLabel or (data.otherCount > 1 and "Çhengaghyn" or "Çhengey") table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. otherLabel .. '</th><td style="vertical-align:top;">' .. data.other .. '</td></tr>' ) end if #rows == 0 then return nil end return table.concat(rows) end function p.languages(frame) local args = getArgs(frame) return buildLanguageRows(args) end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCityEntityFromTitle(value) local title = normaliseCityName(value) if title == "" then return nil end local entityId = mw.wikibase.getEntityIdForTitle(title) if not entityId then return nil end return mw.wikibase.getEntity(entityId) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then return { text = capital, entity = getCityEntityFromTitle(capital), reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or entity:getLabel(), entity = entity, reference = getWikidataReference(statement) } end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then return { text = city, entity = getCityEntityFromTitle(city), reference = nil } end local country = mw.wikibase.getEntityObject() if not country then return nil end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id local target = mw.wikibase.getEntity(targetId) if target and not isDisambiguationPage(target) then local sitelink = target:getSitelink("gvwiki") return { text = sitelink or target:getLabel(), entity = target, reference = getWikidataReference(statement) } end end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) return { capital = getCapitalData(args), administrative = getAdministrativeCentreData(args), largest = getLargestCityData(args), labels = getCityLabels(args) } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end local title = nil if city.entity then title = city.entity:getSitelink("gvwiki") end if not title or title == "" then title = normaliseCityName(city.text) end if not title or title == "" then return "" end return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -------------------------------------------------- -- HEADER -------------------------------------------------- do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -------------------------------------------------- -- FLAG / ARMS -------------------------------------------------- do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -------------------------------------------------- -- MOTTO / ANTHEM -------------------------------------------------- do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -------------------------------------------------- -- CAPITAL / ADMINISTRATIVE CENTRE / LARGEST CITY -------------------------------------------------- do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels -- Add one divider before the city section only. if capital or administrative or largest then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '"></td></tr>' ) end -- Capital if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Administrative centre if administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Largest city if largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- do local languageRows = buildLanguageRows(args) if languageRows then table.insert(rows, languageRows) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p b2psqlgfmo435t4kakc1gwwwgwjn17a 392887 392886 2026-09-07T00:14:40Z MacTire02 219 prowal 392887 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- DISAMBIGUATION GUARD -------------------------------------------------- -- Some Wikidata statements resolve to a general/ambiguous -- item rather than the specific thing we want (e.g. a -- country's "most populous urban area" pointing at the -- ambiguous "New York" (Q22654) instead of "New York City" -- (Q60)). Skip anything flagged as a disambiguation page. local function isDisambiguationPage(entity) if not entity then return false end local statements = entity:getBestStatements("P31") if not statements then return false end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" and mainsnak.datavalue.value.id == "Q4167410" then return true end end return false end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity and not isDisambiguationPage(linkedEntity) then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- FLAG BORDER CHECK -------------------------------------------------- -- List of countries with non-rectangular flags (no border needed) local NON_RECTANGULAR_FLAGS = { ["Flag of Nepal.svg"] = true, ["Flag of Ohio.svg"] = true, ["Flag of Switzerland.svg"] = true, } -- Check if a flag needs a border local function needsFlagBorder(flagFile) if not flagFile then return true end if NON_RECTANGULAR_FLAGS[flagFile] then return false end local lowerFile = mw.ustring.lower(flagFile) if mw.ustring.find(lowerFile, "nepal") then return false end return true end -------------------------------------------------- -- MULTI-FLAG SUPPORT -------------------------------------------------- local function getFlagData(args) -- Get primary flag local flag = getManual(args, {"jalloo_brattagh"}) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end -- Get second flag (if any) local flag2 = getManual(args, {"jalloo_brattagh_2", "jalloo_brattagh_elley"}) if flag2 and mw.ustring.lower(flag2) == "none" then flag2 = nil elseif not flag2 then flag2 = getWikidataImage("P163") end -- Get arms local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end -- Get second arms (if any) local arms2 = getManual(args, { "jalloo_armys_2", "jalloo_cleinney_2" }) if arms2 and mw.ustring.lower(arms2) == "none" then arms2 = nil elseif not arms2 then arms2 = getWikidataImage("P237") end if not flag and not flag2 and not arms and not arms2 then return nil end local name = getCountryGenitive(args) or "" local data = { flags = {}, armses = {} } -- Primary flag if flag then local flagWidth = getManual(args, {"lheead_brattagh"}) or "125px" local hasBorder = needsFlagBorder(flag) table.insert(data.flags, { image = flag, width = flagWidth, hasBorder = hasBorder, link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh"}) or "Brattagh", isPrimary = true }) end -- Second flag if flag2 then local flag2Width = getManual(args, {"lheead_brattagh_2", "lheead_brattagh"}) or "100px" local hasBorder2 = needsFlagBorder(flag2) table.insert(data.flags, { image = flag2, width = flag2Width, hasBorder = hasBorder2, link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh_2"}) or "Brattagh elley", isPrimary = false }) end -- Primary arms if arms then local kind = getManual(args, {"art_sorçh_cowrey"}) or getManual(args, {"sorçh_cowrey"}) or "Armys" table.insert(data.armses, { image = arms, width = getManual(args, {"lheead_armys", "lheead_cleinney", "lheead_cowrey"}) or "85px", link = kind .. " " .. name, label = getManual(args, {"sorçh_cowrey"}) or "Armys", isPrimary = true }) end -- Second arms if arms2 then table.insert(data.armses, { image = arms2, width = getManual(args, {"lheead_armys_2", "lheead_cleinney_2"}) or "85px", link = "Armys " .. name, label = getManual(args, {"sorçh_cowrey_2"}) or "Armys", isPrimary = false }) end return data end -------------------------------------------------- -- UPDATED getFlagArmsData (replaces old function) -------------------------------------------------- local function getFlagArmsData(args) return getFlagData(args) end -------------------------------------------------- -- FLAG / ARMS BLOCK (UPDATED) -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} local hasFlags = #data.flags > 0 local hasArms = #data.armses > 0 -- Build flag column if hasFlags then local flagContent = {} for i, flagData in ipairs(data.flags) do local borderStyle = "" if flagData.hasBorder then borderStyle = '|style="border:1px solid #a2a9b1;"' end local flagImage = '[[Coadan:' .. flagData.image .. '|' .. flagData.width .. borderStyle .. ']]' table.insert(flagContent, flagImage) end local combinedFlags = table.concat(flagContent, '<br/>') table.insert(imageCells, '<td align="center" style="' .. (hasArms and "width:58%; " or "width:100%; ") .. 'vertical-align:middle;">' .. combinedFlags .. '</td>' ) local flagCaptions = {} for i, flagData in ipairs(data.flags) do table.insert(flagCaptions, '<small>[[' .. flagData.link .. '|' .. flagData.label .. ']]</small>' ) end table.insert(captionCells, '<td align="center">' .. table.concat(flagCaptions, '<br/>') .. '</td>' ) end -- Build arms column if hasArms then local armsContent = {} for i, armsData in ipairs(data.armses) do local armsImage = '[[Coadan:' .. armsData.image .. '|' .. armsData.width .. ']]' table.insert(armsContent, armsImage) end local combinedArms = table.concat(armsContent, '<br/>') table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">' .. combinedArms .. '</td>' ) local armsCaptions = {} for i, armsData in ipairs(data.armses) do table.insert(armsCaptions, '<small>[[' .. armsData.link .. '|' .. armsData.label .. ']]</small>' ) end table.insert(captionCells, '<td align="center">' .. table.concat(armsCaptions, '<br/>') .. '</td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = '"' .. motto .. '"', reference = reference and "<ref>" .. reference .. "</ref>" or nil } end local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = '"' .. value.text .. '"', reference = getWikidataReference(statement) } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- local function getLanguagesFromWikidata() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P37") if not statements or #statements == 0 then return {} end local languages = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local langEntity = mw.wikibase.getEntity(id) if langEntity then local label = langEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(languages, { text = label, role = role, reference = getWikidataReference(statement) }) end end end end return languages end local function classifyLanguages(languages) local result = { official = {}, regional = {}, minority = {} } for _, language in ipairs(languages) do local role = language.role or "" local lowerRole = mw.ustring.lower(role) if mw.ustring.find(lowerRole, "minority") then table.insert(result.minority, language) elseif mw.ustring.find(lowerRole, "regional") then table.insert(result.regional, language) else table.insert(result.official, language) end end return result end local function joinLanguageList(languages) if not languages or #languages == 0 then return nil end local parts = {} for _, language in ipairs(languages) do local text = language.text if language.reference then text = text .. language.reference end table.insert(parts, text) end if #parts == 0 then return nil end return table.concat(parts, ", ") end -- Splits text on a top-level separator character, without -- splitting inside {{...}} or [[...]] (so a piped wikilink -- like [[Country|Display]], or a nested template, doesn't -- get miscounted as two items). local function splitTopLevel(text, sep) local parts = {} local current = {} local depthCurly = 0 local depthSquare = 0 local len = mw.ustring.len(text) local i = 1 while i <= len do local two = mw.ustring.sub(text, i, i + 1) local one = mw.ustring.sub(text, i, i) if two == "{{" then depthCurly = depthCurly + 1 table.insert(current, two) i = i + 2 elseif two == "}}" and depthCurly > 0 then depthCurly = depthCurly - 1 table.insert(current, two) i = i + 2 elseif two == "[[" then depthSquare = depthSquare + 1 table.insert(current, two) i = i + 2 elseif two == "]]" and depthSquare > 0 then depthSquare = depthSquare - 1 table.insert(current, two) i = i + 2 elseif one == sep and depthCurly == 0 and depthSquare == 0 then table.insert(parts, table.concat(current)) current = {} i = i + 1 else table.insert(current, one) i = i + 1 end end table.insert(parts, table.concat(current)) return parts end -- Counts the items inside a {{hlist|...}}/{{flatlist|...}}/ -- {{ubl|...}}/{{unbulleted list|...}} template call (the -- convention most legacy articles already use for this -- field). Returns nil if the text isn't one of these, so -- the caller can fall back to a plain heuristic. -- Finds the first call to a template matching namePattern -- anywhere in text (not just at the start/whole-string), -- respecting nested {{...}} so a template argument that -- itself contains braces doesn't break the search. Returns -- the inner content (everything after the first "|") or nil -- if no such template call is found. local function findTemplateCall(text, namePattern) local searchPattern = "{{%s*" .. namePattern .. "%s*|" local matchStart, matchEnd = mw.ustring.find(text, searchPattern) if not matchStart then return nil end local contentStart = matchEnd + 1 local depth = 1 local i = contentStart local len = mw.ustring.len(text) while i <= len do local two = mw.ustring.sub(text, i, i + 1) if two == "{{" then depth = depth + 1 i = i + 2 elseif two == "}}" then depth = depth - 1 i = i + 2 if depth == 0 then local contentEnd = i - 3 return mw.ustring.sub(text, contentStart, contentEnd) end else i = i + 1 end end return nil end -- Pulls any <ref>...</ref> (or self-closing <ref .../>) tags -- out of text, returning the text with them removed plus the -- extracted ref markup (already-valid <ref> tags, ready to -- use as-is - not to be re-wrapped). Returns (text, nil) if -- none are found. local function extractReferences(text) if not text then return text, nil end local refs = {} local cleaned = mw.ustring.gsub(text, "<ref[^>]*>.-</ref>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.ustring.gsub(cleaned, "<ref[^>]*/>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.text.trim(cleaned) if #refs == 0 then return cleaned, nil end return cleaned, table.concat(refs) end local function countHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local segments = splitTopLevel(inner, "|") local count = 0 for _, segment in ipairs(segments) do local trimmedSegment = mw.text.trim(segment) -- Skip named parameters (class=, style=, indent=, etc.) -- rather than counting them as list items. if trimmedSegment ~= "" and not mw.ustring.find(trimmedSegment, "^[%w_%- ]+=") then count = count + 1 end end return count end -- Count of items in a manually-entered language/list field, -- used to decide between a singular ("çhengey") and plural -- ("çhengaghyn") label. Wikidata-derived lists are counted -- exactly (see getLanguageData). Handles the {{hlist}} family -- (searched for anywhere in the text, not just as the entire -- value, since editors often append a trailing <ref> after -- the closing "}}") most legacy articles already use; -- otherwise falls back to a plain comma-count heuristic. local function countListItems(text) if not text or text == "" then return 0 end local hlistCount = countHlistItems(text) if hlistCount then return hlistCount end local count = 0 for _ in mw.text.gsplit(text, ",", true) do count = count + 1 end return count end -- Resolves one language tier from its raw manual parameter: -- strips out any inline <ref> tags (used as-is, since they're -- already valid markup), counts the list on the ref-stripped -- text, then re-appends the extracted ref(s) and/or a manual -- imraa_ reference (which - unlike an inline <ref> - is raw -- citation text that still needs wrapping) to the display value. local function buildLanguageValue(raw, manualReference) if not raw or mw.ustring.lower(mw.text.trim(raw)) == "none" then return nil, 0 end local cleaned, inlineRefs = extractReferences(raw) local count = countListItems(cleaned) local display = cleaned if inlineRefs then display = display .. inlineRefs end if manualReference then display = display .. "<ref>" .. manualReference .. "</ref>" end return display, count end local function getLanguageData(args) local officialRaw = getManual(args, { "çhengaghyn_oikoil", "çhengey_oikoil" }) local officialReference = getManual(args, { "imraa_çhengaghyn_oikoil", "imraa_çhengey_oikoil" }) local regionalRaw = getManual(args, { "çhengaghyn_ardjynagh", "çhengey_ardjynagh" }) local regionalReference = getManual(args, { "imraa_çhengaghyn_ardjynagh", "imraa_çhengey_ardjynagh" }) local minorityRaw = getManual(args, { "mynçhengaghyn", "mynçhengey" }) local minorityReference = getManual(args, { "imraa_mynçhengaghyn", "imraa_mynçhengey" }) local otherRaw = getManual(args, { "çhengaghyn", "çhengey" }) local otherReference = getManual(args, { "imraa_çhengaghyn", "imraa_çhengey" }) local otherLabel = getManual(args, { "sorçh_çhengaghyn" }) local result = { otherLabel = otherLabel } result.official, result.officialCount = buildLanguageValue(officialRaw, officialReference) result.regional, result.regionalCount = buildLanguageValue(regionalRaw, regionalReference) result.minority, result.minorityCount = buildLanguageValue(minorityRaw, minorityReference) result.other, result.otherCount = buildLanguageValue(otherRaw, otherReference) -- Only reach for Wikidata if none of the three tiers -- were set manually - a manual "none" or partial set -- of overrides always wins over the auto-fetch. if not result.official and not result.regional and not result.minority then local classified = classifyLanguages(getLanguagesFromWikidata()) result.official = joinLanguageList(classified.official) result.officialCount = #classified.official result.regional = joinLanguageList(classified.regional) result.regionalCount = #classified.regional result.minority = joinLanguageList(classified.minority) result.minorityCount = #classified.minority end return result end local function buildLanguageRows(args) local data = getLanguageData(args) local rows = {} if data.official then local officialLabel = data.officialCount > 1 and "[[Çhengey oikoil|Çhengaghyn oikoil]]" or "[[Çhengey oikoil]]" local officialRow = '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. officialLabel .. '</th><td style="vertical-align:top;">' .. data.official .. '</td></tr>' if data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn&nbsp;ardjynagh er&nbsp;enney" or "Çhengey&nbsp;ardjynagh er&nbsp;enney" officialRow = officialRow .. '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:normal;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th>' .. '<td style="vertical-align:top;">' .. data.regional .. '</td></tr>' end table.insert(rows, officialRow) elseif data.regional then -- Regional recognised even without a separate -- official-language statement. local regionalLabel = data.regionalCount > 1 and "Çhengaghyn ardjynagh er enney" or "Çhengey ardjynagh er enney" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th><td style="vertical-align:top;">' .. data.regional .. '</td></tr>' ) end if data.minority then local minorityLabel = data.minorityCount > 1 and "[[Mynçhengey|Mynçhengaghyn]]" or "[[Mynçhengey]]" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. minorityLabel .. '</th><td style="vertical-align:top;">' .. data.minority .. '</td></tr>' ) end if data.other then local otherLabel = data.otherLabel or (data.otherCount > 1 and "Çhengaghyn" or "Çhengey") table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. otherLabel .. '</th><td style="vertical-align:top;">' .. data.other .. '</td></tr>' ) end if #rows == 0 then return nil end return table.concat(rows) end function p.languages(frame) local args = getArgs(frame) return buildLanguageRows(args) end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCityEntityFromTitle(value) local title = normaliseCityName(value) if title == "" then return nil end local entityId = mw.wikibase.getEntityIdForTitle(title) if not entityId then return nil end return mw.wikibase.getEntity(entityId) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then return { text = capital, entity = getCityEntityFromTitle(capital), reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or entity:getLabel(), entity = entity, reference = getWikidataReference(statement) } end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then return { text = city, entity = getCityEntityFromTitle(city), reference = nil } end local country = mw.wikibase.getEntityObject() if not country then return nil end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id local target = mw.wikibase.getEntity(targetId) if target and not isDisambiguationPage(target) then local sitelink = target:getSitelink("gvwiki") return { text = sitelink or target:getLabel(), entity = target, reference = getWikidataReference(statement) } end end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) return { capital = getCapitalData(args), administrative = getAdministrativeCentreData(args), largest = getLargestCityData(args), labels = getCityLabels(args) } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end local title = nil if city.entity then title = city.entity:getSitelink("gvwiki") end if not title or title == "" then title = normaliseCityName(city.text) end if not title or title == "" then return "" end return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -------------------------------------------------- -- HEADER -------------------------------------------------- do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -------------------------------------------------- -- FLAG / ARMS -------------------------------------------------- do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -------------------------------------------------- -- MOTTO / ANTHEM -------------------------------------------------- do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -------------------------------------------------- -- CAPITAL / ADMINISTRATIVE CENTRE / LARGEST CITY -------------------------------------------------- do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels -- Add one divider before the city section only. if capital or administrative or largest then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '"></td></tr>' ) end -- Capital if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Administrative centre if administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Largest city if largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- do local languageRows = buildLanguageRows(args) if languageRows then table.insert(rows, languageRows) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p 48uupmpslj1oupx0w8iuqs9ly5pwlvl 392888 392887 2026-09-07T00:27:46Z MacTire02 219 ++ 392888 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- DISAMBIGUATION GUARD -------------------------------------------------- -- Some Wikidata statements resolve to a general/ambiguous -- item rather than the specific thing we want (e.g. a -- country's "most populous urban area" pointing at the -- ambiguous "New York" (Q22654) instead of "New York City" -- (Q60)). Skip anything flagged as a disambiguation page. local function isDisambiguationPage(entity) if not entity then return false end local statements = entity:getBestStatements("P31") if not statements then return false end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" and mainsnak.datavalue.value.id == "Q4167410" then return true end end return false end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity and not isDisambiguationPage(linkedEntity) then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- FLAG BORDER CHECK -------------------------------------------------- -- List of countries with non-rectangular flags (no border needed) local NON_RECTANGULAR_FLAGS = { ["Flag of Nepal.svg"] = true, ["Flag of Ohio.svg"] = true, ["Flag of Switzerland.svg"] = true, } -- Check if a flag needs a border local function needsFlagBorder(flagFile) if not flagFile then return true end if NON_RECTANGULAR_FLAGS[flagFile] then return false end local lowerFile = mw.ustring.lower(flagFile) if mw.ustring.find(lowerFile, "nepal") then return false end return true end -------------------------------------------------- -- MULTI-FLAG SUPPORT -------------------------------------------------- local function getFlagData(args) -- Get primary flag local flag = getManual(args, {"jalloo_brattagh"}) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end -- Get second flag (if any) local flag2 = getManual(args, {"jalloo_brattagh_2", "jalloo_brattagh_elley"}) if flag2 and mw.ustring.lower(flag2) == "none" then flag2 = nil elseif not flag2 then flag2 = getWikidataImage("P163") end -- Get arms local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end -- Get second arms (if any) local arms2 = getManual(args, { "jalloo_armys_2", "jalloo_cleinney_2" }) if arms2 and mw.ustring.lower(arms2) == "none" then arms2 = nil elseif not arms2 then arms2 = getWikidataImage("P237") end if not flag and not flag2 and not arms and not arms2 then return nil end local name = getCountryGenitive(args) or "" local data = { flags = {}, armses = {} } -- Primary flag if flag then local flagWidth = getManual(args, {"lheead_brattagh"}) or "125px" local hasBorder = needsFlagBorder(flag) table.insert(data.flags, { image = flag, width = flagWidth, hasBorder = hasBorder, link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh"}) or "Brattagh", isPrimary = true }) end -- Second flag if flag2 then local flag2Width = getManual(args, {"lheead_brattagh_2", "lheead_brattagh"}) or "100px" local hasBorder2 = needsFlagBorder(flag2) table.insert(data.flags, { image = flag2, width = flag2Width, hasBorder = hasBorder2, link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh_2"}) or "Brattagh elley", isPrimary = false }) end -- Primary arms if arms then local kind = getManual(args, {"art_sorçh_cowrey"}) or getManual(args, {"sorçh_cowrey"}) or "Armys" table.insert(data.armses, { image = arms, width = getManual(args, {"lheead_armys", "lheead_cleinney", "lheead_cowrey"}) or "85px", link = kind .. " " .. name, label = getManual(args, {"sorçh_cowrey"}) or "Armys", isPrimary = true }) end -- Second arms if arms2 then table.insert(data.armses, { image = arms2, width = getManual(args, {"lheead_armys_2", "lheead_cleinney_2"}) or "85px", link = "Armys " .. name, label = getManual(args, {"sorçh_cowrey_2"}) or "Armys", isPrimary = false }) end return data end -------------------------------------------------- -- UPDATED getFlagArmsData (replaces old function) -------------------------------------------------- local function getFlagArmsData(args) return getFlagData(args) end -------------------------------------------------- -- FLAG / ARMS BLOCK (UPDATED) -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} local hasFlags = #data.flags > 0 local hasArms = #data.armses > 0 -- Build flag column if hasFlags then local flagContent = {} for i, flagData in ipairs(data.flags) do local borderStyle = "" if flagData.hasBorder then borderStyle = '|style="border:1px solid #a2a9b1;"' end local flagImage = '[[Coadan:' .. flagData.image .. '|' .. flagData.width .. borderStyle .. ']]' table.insert(flagContent, flagImage) end local combinedFlags = table.concat(flagContent, '<br/>') table.insert(imageCells, '<td align="center" style="' .. (hasArms and "width:58%; " or "width:100%; ") .. 'vertical-align:middle;">' .. combinedFlags .. '</td>' ) local flagCaptions = {} for i, flagData in ipairs(data.flags) do table.insert(flagCaptions, '<small>[[' .. flagData.link .. '|' .. flagData.label .. ']]</small>' ) end table.insert(captionCells, '<td align="center">' .. table.concat(flagCaptions, '<br/>') .. '</td>' ) end -- Build arms column if hasArms then local armsContent = {} for i, armsData in ipairs(data.armses) do local armsImage = '[[Coadan:' .. armsData.image .. '|' .. armsData.width .. ']]' table.insert(armsContent, armsImage) end local combinedArms = table.concat(armsContent, '<br/>') table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">' .. combinedArms .. '</td>' ) local armsCaptions = {} for i, armsData in ipairs(data.armses) do table.insert(armsCaptions, '<small>[[' .. armsData.link .. '|' .. armsData.label .. ']]</small>' ) end table.insert(captionCells, '<td align="center">' .. table.concat(armsCaptions, '<br/>') .. '</td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = '"' .. motto .. '"', reference = reference and "<ref>" .. reference .. "</ref>" or nil } end local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = '"' .. value.text .. '"', reference = getWikidataReference(statement) } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- local function getLanguagesFromWikidata() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P37") if not statements or #statements == 0 then return {} end local languages = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local langEntity = mw.wikibase.getEntity(id) if langEntity then local label = langEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(languages, { text = label, role = role, reference = getWikidataReference(statement) }) end end end end return languages end local function classifyLanguages(languages) local result = { official = {}, regional = {}, minority = {} } for _, language in ipairs(languages) do local role = language.role or "" local lowerRole = mw.ustring.lower(role) if mw.ustring.find(lowerRole, "minority") then table.insert(result.minority, language) elseif mw.ustring.find(lowerRole, "regional") then table.insert(result.regional, language) else table.insert(result.official, language) end end return result end local function joinLanguageList(languages) if not languages or #languages == 0 then return nil end local parts = {} for _, language in ipairs(languages) do local text = language.text -- Wrap language name in a wikilink (even if redlinked) text = '[[' .. text .. '|' .. text .. ']]' if language.reference then text = text .. language.reference end table.insert(parts, text) end if #parts == 0 then return nil end return table.concat(parts, ", ") end -- Splits text on a top-level separator character, without -- splitting inside {{...}} or [[...]] (so a piped wikilink -- like [[Country|Display]], or a nested template, doesn't -- get miscounted as two items). local function splitTopLevel(text, sep) local parts = {} local current = {} local depthCurly = 0 local depthSquare = 0 local len = mw.ustring.len(text) local i = 1 while i <= len do local two = mw.ustring.sub(text, i, i + 1) local one = mw.ustring.sub(text, i, i) if two == "{{" then depthCurly = depthCurly + 1 table.insert(current, two) i = i + 2 elseif two == "}}" and depthCurly > 0 then depthCurly = depthCurly - 1 table.insert(current, two) i = i + 2 elseif two == "[[" then depthSquare = depthSquare + 1 table.insert(current, two) i = i + 2 elseif two == "]]" and depthSquare > 0 then depthSquare = depthSquare - 1 table.insert(current, two) i = i + 2 elseif one == sep and depthCurly == 0 and depthSquare == 0 then table.insert(parts, table.concat(current)) current = {} i = i + 1 else table.insert(current, one) i = i + 1 end end table.insert(parts, table.concat(current)) return parts end -- Counts the items inside a {{hlist|...}}/{{flatlist|...}}/ -- {{ubl|...}}/{{unbulleted list|...}} template call (the -- convention most legacy articles already use for this -- field). Returns nil if the text isn't one of these, so -- the caller can fall back to a plain heuristic. -- Finds the first call to a template matching namePattern -- anywhere in text (not just at the start/whole-string), -- respecting nested {{...}} so a template argument that -- itself contains braces doesn't break the search. Returns -- the inner content (everything after the first "|") or nil -- if no such template call is found. local function findTemplateCall(text, namePattern) local searchPattern = "{{%s*" .. namePattern .. "%s*|" local matchStart, matchEnd = mw.ustring.find(text, searchPattern) if not matchStart then return nil end local contentStart = matchEnd + 1 local depth = 1 local i = contentStart local len = mw.ustring.len(text) while i <= len do local two = mw.ustring.sub(text, i, i + 1) if two == "{{" then depth = depth + 1 i = i + 2 elseif two == "}}" then depth = depth - 1 i = i + 2 if depth == 0 then local contentEnd = i - 3 return mw.ustring.sub(text, contentStart, contentEnd) end else i = i + 1 end end return nil end -- Pulls any <ref>...</ref> (or self-closing <ref .../>) tags -- out of text, returning the text with them removed plus the -- extracted ref markup (already-valid <ref> tags, ready to -- use as-is - not to be re-wrapped). Returns (text, nil) if -- none are found. local function extractReferences(text) if not text then return text, nil end local refs = {} local cleaned = mw.ustring.gsub(text, "<ref[^>]*>.-</ref>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.ustring.gsub(cleaned, "<ref[^>]*/>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.text.trim(cleaned) if #refs == 0 then return cleaned, nil end return cleaned, table.concat(refs) end local function countHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local segments = splitTopLevel(inner, "|") local count = 0 for _, segment in ipairs(segments) do local trimmedSegment = mw.text.trim(segment) -- Skip named parameters (class=, style=, indent=, etc.) -- rather than counting them as list items. if trimmedSegment ~= "" and not mw.ustring.find(trimmedSegment, "^[%w_%- ]+=") then count = count + 1 end end return count end -- Count of items in a manually-entered language/list field, -- used to decide between a singular ("çhengey") and plural -- ("çhengaghyn") label. Wikidata-derived lists are counted -- exactly (see getLanguageData). Handles the {{hlist}} family -- (searched for anywhere in the text, not just as the entire -- value, since editors often append a trailing <ref> after -- the closing "}}") most legacy articles already use; -- otherwise falls back to a plain comma-count heuristic. local function countListItems(text) if not text or text == "" then return 0 end local hlistCount = countHlistItems(text) if hlistCount then return hlistCount end local count = 0 for _ in mw.text.gsplit(text, ",", true) do count = count + 1 end return count end -- Resolves one language tier from its raw manual parameter: -- strips out any inline <ref> tags (used as-is, since they're -- already valid markup), counts the list on the ref-stripped -- text, then re-appends the extracted ref(s) and/or a manual -- imraa_ reference (which - unlike an inline <ref> - is raw -- citation text that still needs wrapping) to the display value. local function wrapInWikilink(text) -- If already has wikilink syntax, don't double-wrap if mw.ustring.find(text, "%[%[") then return text end -- Otherwise wrap in wikilink return '[[' .. text .. '|' .. text .. ']]' end local function buildLanguageValue(raw, manualReference) if not raw or mw.ustring.lower(mw.text.trim(raw)) == "none" then return nil, 0 end local cleaned, inlineRefs = extractReferences(raw) local count = countListItems(cleaned) -- Split by comma and wrap each language in a wikilink local parts = {} for part in mw.text.gsplit(cleaned, ",", true) do local trimmed = mw.text.trim(part) if trimmed ~= "" then table.insert(parts, wrapInWikilink(trimmed)) end end local display = table.concat(parts, ", ") if inlineRefs then display = display .. inlineRefs end if manualReference then display = display .. "<ref>" .. manualReference .. "</ref>" end return display, count end local function getLanguageData(args) local officialRaw = getManual(args, { "çhengaghyn_oikoil", "çhengey_oikoil" }) local officialReference = getManual(args, { "imraa_çhengaghyn_oikoil", "imraa_çhengey_oikoil" }) local regionalRaw = getManual(args, { "çhengaghyn_ardjynagh", "çhengey_ardjynagh" }) local regionalReference = getManual(args, { "imraa_çhengaghyn_ardjynagh", "imraa_çhengey_ardjynagh" }) local minorityRaw = getManual(args, { "mynçhengaghyn", "mynçhengey" }) local minorityReference = getManual(args, { "imraa_mynçhengaghyn", "imraa_mynçhengey" }) local otherRaw = getManual(args, { "çhengaghyn", "çhengey" }) local otherReference = getManual(args, { "imraa_çhengaghyn", "imraa_çhengey" }) local otherLabel = getManual(args, { "sorçh_çhengaghyn" }) local result = { otherLabel = otherLabel } result.official, result.officialCount = buildLanguageValue(officialRaw, officialReference) result.regional, result.regionalCount = buildLanguageValue(regionalRaw, regionalReference) result.minority, result.minorityCount = buildLanguageValue(minorityRaw, minorityReference) result.other, result.otherCount = buildLanguageValue(otherRaw, otherReference) -- Only reach for Wikidata if none of the three tiers -- were set manually - a manual "none" or partial set -- of overrides always wins over the auto-fetch. if not result.official and not result.regional and not result.minority then local classified = classifyLanguages(getLanguagesFromWikidata()) result.official = joinLanguageList(classified.official) result.officialCount = #classified.official result.regional = joinLanguageList(classified.regional) result.regionalCount = #classified.regional result.minority = joinLanguageList(classified.minority) result.minorityCount = #classified.minority end return result end local function buildLanguageRows(args) local data = getLanguageData(args) local rows = {} if data.official then local officialLabel = data.officialCount > 1 and "[[Çhengey oikoil|Çhengaghyn oikoil]]" or "[[Çhengey oikoil]]" local officialRow = '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. officialLabel .. '</th><td style="vertical-align:top;">' .. data.official .. '</td></tr>' if data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn&nbsp;ardjynagh er&nbsp;enney" or "Çhengey&nbsp;ardjynagh er&nbsp;enney" officialRow = officialRow .. '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:normal;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th>' .. '<td style="vertical-align:top;">' .. data.regional .. '</td></tr>' end table.insert(rows, officialRow) elseif data.regional then -- Regional recognised even without a separate -- official-language statement. local regionalLabel = data.regionalCount > 1 and "Çhengaghyn ardjynagh er enney" or "Çhengey ardjynagh er enney" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th><td style="vertical-align:top;">' .. data.regional .. '</td></tr>' ) end if data.minority then local minorityLabel = data.minorityCount > 1 and "[[Mynçhengey|Mynçhengaghyn]]" or "[[Mynçhengey]]" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. minorityLabel .. '</th><td style="vertical-align:top;">' .. data.minority .. '</td></tr>' ) end if data.other then local otherLabel = data.otherLabel or (data.otherCount > 1 and "Çhengaghyn" or "Çhengey") table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. otherLabel .. '</th><td style="vertical-align:top;">' .. data.other .. '</td></tr>' ) end if #rows == 0 then return nil end return table.concat(rows) end function p.languages(frame) local args = getArgs(frame) return buildLanguageRows(args) end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCityEntityFromTitle(value) local title = normaliseCityName(value) if title == "" then return nil end local entityId = mw.wikibase.getEntityIdForTitle(title) if not entityId then return nil end return mw.wikibase.getEntity(entityId) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then return { text = capital, entity = getCityEntityFromTitle(capital), reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or entity:getLabel(), entity = entity, reference = getWikidataReference(statement) } end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then return { text = city, entity = getCityEntityFromTitle(city), reference = nil } end local country = mw.wikibase.getEntityObject() if not country then return nil end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id local target = mw.wikibase.getEntity(targetId) if target and not isDisambiguationPage(target) then local sitelink = target:getSitelink("gvwiki") return { text = sitelink or target:getLabel(), entity = target, reference = getWikidataReference(statement) } end end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) return { capital = getCapitalData(args), administrative = getAdministrativeCentreData(args), largest = getLargestCityData(args), labels = getCityLabels(args) } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end local title = nil if city.entity then title = city.entity:getSitelink("gvwiki") end if not title or title == "" then title = normaliseCityName(city.text) end if not title or title == "" then return "" end return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -------------------------------------------------- -- HEADER -------------------------------------------------- do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -------------------------------------------------- -- FLAG / ARMS -------------------------------------------------- do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -------------------------------------------------- -- MOTTO / ANTHEM -------------------------------------------------- do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -------------------------------------------------- -- CAPITAL / ADMINISTRATIVE CENTRE / LARGEST CITY -------------------------------------------------- do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels -- Add one divider before the city section only. if capital or administrative or largest then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '"></td></tr>' ) end -- Capital if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Administrative centre if administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Largest city if largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- do local languageRows = buildLanguageRows(args) if languageRows then table.insert(rows, languageRows) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p g01accacu8282k2pcr7kujc4spoa8qx 392889 392888 2026-09-07T00:44:38Z MacTire02 219 ++ 392889 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -- Extract items from an hlist/flatlist/ubl template local function extractHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local items = {} local segments = splitTopLevel(inner, "|") for _, segment in ipairs(segments) do local trimmed = mw.text.trim(segment) -- Skip named parameters (class=, style=, etc.) if trimmed ~= "" and not mw.ustring.find(trimmed, "^[%w_%- ]+=") then -- Extract just the link text if it's a wikilink local linkText = mw.ustring.match(trimmed, "%[%[.-|(.+)%]%]") or mw.ustring.match(trimmed, "%[%[(.+)%]%]") or trimmed table.insert(items, mw.text.trim(linkText)) end end return items end -------------------------------------------------- -- DISAMBIGUATION GUARD -------------------------------------------------- -- Some Wikidata statements resolve to a general/ambiguous -- item rather than the specific thing we want (e.g. a -- country's "most populous urban area" pointing at the -- ambiguous "New York" (Q22654) instead of "New York City" -- (Q60)). Skip anything flagged as a disambiguation page. local function isDisambiguationPage(entity) if not entity then return false end local statements = entity:getBestStatements("P31") if not statements then return false end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" and mainsnak.datavalue.value.id == "Q4167410" then return true end end return false end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity and not isDisambiguationPage(linkedEntity) then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- FLAG BORDER CHECK -------------------------------------------------- -- List of countries with non-rectangular flags (no border needed) local NON_RECTANGULAR_FLAGS = { ["Flag of Nepal.svg"] = true, ["Flag of Ohio.svg"] = true, ["Flag of Switzerland.svg"] = true, } -- Check if a flag needs a border local function needsFlagBorder(flagFile) if not flagFile then return true end if NON_RECTANGULAR_FLAGS[flagFile] then return false end local lowerFile = mw.ustring.lower(flagFile) if mw.ustring.find(lowerFile, "nepal") then return false end return true end -------------------------------------------------- -- MULTI-FLAG SUPPORT -------------------------------------------------- local function getFlagData(args) -- Get primary flag local flag = getManual(args, {"jalloo_brattagh"}) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end -- Get second flag (if any) local flag2 = getManual(args, {"jalloo_brattagh_2", "jalloo_brattagh_elley"}) if flag2 and mw.ustring.lower(flag2) == "none" then flag2 = nil elseif not flag2 then flag2 = getWikidataImage("P163") end -- Get arms local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end -- Get second arms (if any) local arms2 = getManual(args, { "jalloo_armys_2", "jalloo_cleinney_2" }) if arms2 and mw.ustring.lower(arms2) == "none" then arms2 = nil elseif not arms2 then arms2 = getWikidataImage("P237") end if not flag and not flag2 and not arms and not arms2 then return nil end local name = getCountryGenitive(args) or "" local data = { flags = {}, armses = {} } -- Primary flag if flag then local flagWidth = getManual(args, {"lheead_brattagh"}) or "125px" local hasBorder = needsFlagBorder(flag) table.insert(data.flags, { image = flag, width = flagWidth, hasBorder = hasBorder, link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh"}) or "Brattagh", isPrimary = true }) end -- Second flag if flag2 then local flag2Width = getManual(args, {"lheead_brattagh_2", "lheead_brattagh"}) or "100px" local hasBorder2 = needsFlagBorder(flag2) table.insert(data.flags, { image = flag2, width = flag2Width, hasBorder = hasBorder2, link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh_2"}) or "Brattagh elley", isPrimary = false }) end -- Primary arms if arms then local kind = getManual(args, {"art_sorçh_cowrey"}) or getManual(args, {"sorçh_cowrey"}) or "Armys" table.insert(data.armses, { image = arms, width = getManual(args, {"lheead_armys", "lheead_cleinney", "lheead_cowrey"}) or "85px", link = kind .. " " .. name, label = getManual(args, {"sorçh_cowrey"}) or "Armys", isPrimary = true }) end -- Second arms if arms2 then table.insert(data.armses, { image = arms2, width = getManual(args, {"lheead_armys_2", "lheead_cleinney_2"}) or "85px", link = "Armys " .. name, label = getManual(args, {"sorçh_cowrey_2"}) or "Armys", isPrimary = false }) end return data end -------------------------------------------------- -- UPDATED getFlagArmsData (replaces old function) -------------------------------------------------- local function getFlagArmsData(args) return getFlagData(args) end -------------------------------------------------- -- FLAG / ARMS BLOCK (UPDATED) -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} local hasFlags = #data.flags > 0 local hasArms = #data.armses > 0 -- Build flag column if hasFlags then local flagContent = {} for i, flagData in ipairs(data.flags) do local borderStyle = "" if flagData.hasBorder then borderStyle = '|style="border:1px solid #a2a9b1;"' end local flagImage = '[[Coadan:' .. flagData.image .. '|' .. flagData.width .. borderStyle .. ']]' table.insert(flagContent, flagImage) end local combinedFlags = table.concat(flagContent, '<br/>') table.insert(imageCells, '<td align="center" style="' .. (hasArms and "width:58%; " or "width:100%; ") .. 'vertical-align:middle;">' .. combinedFlags .. '</td>' ) local flagCaptions = {} for i, flagData in ipairs(data.flags) do table.insert(flagCaptions, '<small>[[' .. flagData.link .. '|' .. flagData.label .. ']]</small>' ) end table.insert(captionCells, '<td align="center">' .. table.concat(flagCaptions, '<br/>') .. '</td>' ) end -- Build arms column if hasArms then local armsContent = {} for i, armsData in ipairs(data.armses) do local armsImage = '[[Coadan:' .. armsData.image .. '|' .. armsData.width .. ']]' table.insert(armsContent, armsImage) end local combinedArms = table.concat(armsContent, '<br/>') table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">' .. combinedArms .. '</td>' ) local armsCaptions = {} for i, armsData in ipairs(data.armses) do table.insert(armsCaptions, '<small>[[' .. armsData.link .. '|' .. armsData.label .. ']]</small>' ) end table.insert(captionCells, '<td align="center">' .. table.concat(armsCaptions, '<br/>') .. '</td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = '"' .. motto .. '"', reference = reference and "<ref>" .. reference .. "</ref>" or nil } end local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = '"' .. value.text .. '"', reference = getWikidataReference(statement) } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, { "arrane_ashoonagh" }) local royal = getManual(args, { "arrane_reeoil" }) local other = getManual(args, { "arrane" }) local nationalReference = getManual(args, { "imraa_arrane_ashoonagh" }) local royalReference = getManual(args, { "imraa_arrane_reeoil" }) local otherReference = getManual(args, { "imraa_arrane" }) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and "<ref>" .. nationalReference .. "</ref>" or nil } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and "<ref>" .. royalReference .. "</ref>" or nil } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and "<ref>" .. otherReference .. "</ref>" or nil } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text ) end if anthems.national then local text = '[[' .. anthems.national.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.national.reference then text = text .. anthems.national.reference end if anthems.national.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.national.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane ashoonagh]]:&nbsp;'''" .. text ) end if anthems.other then local text = '[[' .. anthems.other.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.other.reference then text = text .. anthems.other.reference end if anthems.other.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.other.audio .. ']]</div>' end table.insert(rows, "'''Anthym:&nbsp;'''" .. text ) end if anthems.royal then local text = '[[' .. anthems.royal.text .. ']]' text = mw.ustring.gsub(text, '^"+', '') text = mw.ustring.gsub(text, '"+$', '') text = '"' .. text .. '"' if anthems.royal.reference then text = text .. anthems.royal.reference end if anthems.royal.audio then text = text .. '<br/><div style="text-align:center;">[[Coadan:' .. anthems.royal.audio .. ']]</div>' end table.insert(rows, "'''[[Arrane reeoil]]:&nbsp;'''" .. text ) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- local function getLanguagesFromWikidata() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P37") if not statements or #statements == 0 then return {} end local languages = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local langEntity = mw.wikibase.getEntity(id) if langEntity then local label = langEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(languages, { text = label, role = role, reference = getWikidataReference(statement) }) end end end end return languages end local function classifyLanguages(languages) local result = { official = {}, regional = {}, minority = {} } for _, language in ipairs(languages) do local role = language.role or "" local lowerRole = mw.ustring.lower(role) if mw.ustring.find(lowerRole, "minority") then table.insert(result.minority, language) elseif mw.ustring.find(lowerRole, "regional") then table.insert(result.regional, language) else table.insert(result.official, language) end end return result end -- Manx-specific collation: çh sorts as ch local function manxSort(a, b) local function normalize(text) -- Replace çh with ch for sorting purposes text = mw.ustring.lower(text) text = mw.ustring.gsub(text, "çh", "ch") return text end return normalize(a) < normalize(b) end local function joinLanguageList(languages) if not languages or #languages == 0 then return nil end -- Sort languages alphabetically with Manx collation table.sort(languages, function(a, b) return manxSort(a.text, b.text) end) local parts = {} for _, language in ipairs(languages) do local text = language.text -- Wrap language name in a wikilink (even if redlinked) text = '[[' .. text .. '|' .. text .. ']]' if language.reference then text = text .. language.reference end table.insert(parts, text) end if #parts == 0 then return nil end -- Return as hlist format return '<div class="hlist">' .. table.concat(parts, '&nbsp;· ') .. '</div>' end -- Splits text on a top-level separator character, without -- splitting inside {{...}} or [[...]] (so a piped wikilink -- like [[Country|Display]], or a nested template, doesn't -- get miscounted as two items). local function splitTopLevel(text, sep) local parts = {} local current = {} local depthCurly = 0 local depthSquare = 0 local len = mw.ustring.len(text) local i = 1 while i <= len do local two = mw.ustring.sub(text, i, i + 1) local one = mw.ustring.sub(text, i, i) if two == "{{" then depthCurly = depthCurly + 1 table.insert(current, two) i = i + 2 elseif two == "}}" and depthCurly > 0 then depthCurly = depthCurly - 1 table.insert(current, two) i = i + 2 elseif two == "[[" then depthSquare = depthSquare + 1 table.insert(current, two) i = i + 2 elseif two == "]]" and depthSquare > 0 then depthSquare = depthSquare - 1 table.insert(current, two) i = i + 2 elseif one == sep and depthCurly == 0 and depthSquare == 0 then table.insert(parts, table.concat(current)) current = {} i = i + 1 else table.insert(current, one) i = i + 1 end end table.insert(parts, table.concat(current)) return parts end -- Counts the items inside a {{hlist|...}}/{{flatlist|...}}/ -- {{ubl|...}}/{{unbulleted list|...}} template call (the -- convention most legacy articles already use for this -- field). Returns nil if the text isn't one of these, so -- the caller can fall back to a plain heuristic. -- Finds the first call to a template matching namePattern -- anywhere in text (not just at the start/whole-string), -- respecting nested {{...}} so a template argument that -- itself contains braces doesn't break the search. Returns -- the inner content (everything after the first "|") or nil -- if no such template call is found. local function findTemplateCall(text, namePattern) local searchPattern = "{{%s*" .. namePattern .. "%s*|" local matchStart, matchEnd = mw.ustring.find(text, searchPattern) if not matchStart then return nil end local contentStart = matchEnd + 1 local depth = 1 local i = contentStart local len = mw.ustring.len(text) while i <= len do local two = mw.ustring.sub(text, i, i + 1) if two == "{{" then depth = depth + 1 i = i + 2 elseif two == "}}" then depth = depth - 1 i = i + 2 if depth == 0 then local contentEnd = i - 3 return mw.ustring.sub(text, contentStart, contentEnd) end else i = i + 1 end end return nil end -- Pulls any <ref>...</ref> (or self-closing <ref .../>) tags -- out of text, returning the text with them removed plus the -- extracted ref markup (already-valid <ref> tags, ready to -- use as-is - not to be re-wrapped). Returns (text, nil) if -- none are found. local function extractReferences(text) if not text then return text, nil end local refs = {} local cleaned = mw.ustring.gsub(text, "<ref[^>]*>.-</ref>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.ustring.gsub(cleaned, "<ref[^>]*/>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.text.trim(cleaned) if #refs == 0 then return cleaned, nil end return cleaned, table.concat(refs) end local function countHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local segments = splitTopLevel(inner, "|") local count = 0 for _, segment in ipairs(segments) do local trimmedSegment = mw.text.trim(segment) -- Skip named parameters (class=, style=, indent=, etc.) -- rather than counting them as list items. if trimmedSegment ~= "" and not mw.ustring.find(trimmedSegment, "^[%w_%- ]+=") then count = count + 1 end end return count end -- Count of items in a manually-entered language/list field, -- used to decide between a singular ("çhengey") and plural -- ("çhengaghyn") label. Wikidata-derived lists are counted -- exactly (see getLanguageData). Handles the {{hlist}} family -- (searched for anywhere in the text, not just as the entire -- value, since editors often append a trailing <ref> after -- the closing "}}") most legacy articles already use; -- otherwise falls back to a plain comma-count heuristic. local function countListItems(text) if not text or text == "" then return 0 end local hlistCount = countHlistItems(text) if hlistCount then return hlistCount end local count = 0 for _ in mw.text.gsplit(text, ",", true) do count = count + 1 end return count end -- Resolves one language tier from its raw manual parameter: -- strips out any inline <ref> tags (used as-is, since they're -- already valid markup), counts the list on the ref-stripped -- text, then re-appends the extracted ref(s) and/or a manual -- imraa_ reference (which - unlike an inline <ref> - is raw -- citation text that still needs wrapping) to the display value. local function wrapInWikilink(text) -- If already has wikilink syntax, don't double-wrap if mw.ustring.find(text, "%[%[") then return text end -- Otherwise wrap in wikilink return '[[' .. text .. '|' .. text .. ']]' end local function buildLanguageValue(raw, manualReference) if not raw or mw.ustring.lower(mw.text.trim(raw)) == "none" then return nil, 0 end local cleaned, inlineRefs = extractReferences(raw) local count = countListItems(cleaned) -- Try to extract from hlist template first local languageNames = extractHlistItems(cleaned) -- If not in hlist format, split by comma if not languageNames then languageNames = {} for part in mw.text.gsplit(cleaned, ",", true) do local trimmed = mw.text.trim(part) if trimmed ~= "" then table.insert(languageNames, trimmed) end end end -- Sort alphabetically with Manx collation table.sort(languageNames, manxSort) -- Wrap each in wikilink and build hlist local parts = {} for _, name in ipairs(languageNames) do table.insert(parts, '[[' .. name .. '|' .. name .. ']]') end local display = '<div class="hlist">' .. table.concat(parts, '&nbsp;· ') .. '</div>' if inlineRefs then display = display .. inlineRefs end if manualReference then display = display .. "<ref>" .. manualReference .. "</ref>" end return display, count end local function getLanguageData(args) local officialRaw = getManual(args, { "çhengaghyn_oikoil", "çhengey_oikoil" }) local officialReference = getManual(args, { "imraa_çhengaghyn_oikoil", "imraa_çhengey_oikoil" }) local regionalRaw = getManual(args, { "çhengaghyn_ardjynagh", "çhengey_ardjynagh" }) local regionalReference = getManual(args, { "imraa_çhengaghyn_ardjynagh", "imraa_çhengey_ardjynagh" }) local minorityRaw = getManual(args, { "mynçhengaghyn", "mynçhengey" }) local minorityReference = getManual(args, { "imraa_mynçhengaghyn", "imraa_mynçhengey" }) local otherRaw = getManual(args, { "çhengaghyn", "çhengey" }) local otherReference = getManual(args, { "imraa_çhengaghyn", "imraa_çhengey" }) local otherLabel = getManual(args, { "sorçh_çhengaghyn" }) local result = { otherLabel = otherLabel } result.official, result.officialCount = buildLanguageValue(officialRaw, officialReference) result.regional, result.regionalCount = buildLanguageValue(regionalRaw, regionalReference) result.minority, result.minorityCount = buildLanguageValue(minorityRaw, minorityReference) result.other, result.otherCount = buildLanguageValue(otherRaw, otherReference) -- Only reach for Wikidata if none of the three tiers -- were set manually - a manual "none" or partial set -- of overrides always wins over the auto-fetch. if not result.official and not result.regional and not result.minority then local classified = classifyLanguages(getLanguagesFromWikidata()) result.official = joinLanguageList(classified.official) result.officialCount = #classified.official result.regional = joinLanguageList(classified.regional) result.regionalCount = #classified.regional result.minority = joinLanguageList(classified.minority) result.minorityCount = #classified.minority end return result end local function buildLanguageRows(args) local data = getLanguageData(args) local rows = {} if data.official then local officialLabel = data.officialCount > 1 and "[[Çhengey oikoil|Çhengaghyn oikoil]]" or "[[Çhengey oikoil]]" local officialRow = '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. officialLabel .. '</th><td style="vertical-align:top;">' .. data.official .. '</td></tr>' if data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn&nbsp;ardjynagh er&nbsp;enney" or "Çhengey&nbsp;ardjynagh er&nbsp;enney" officialRow = officialRow .. '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:normal;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th>' .. '<td style="vertical-align:top;">' .. data.regional .. '</td></tr>' end table.insert(rows, officialRow) elseif data.regional then -- Regional recognised even without a separate -- official-language statement. local regionalLabel = data.regionalCount > 1 and "Çhengaghyn ardjynagh er enney" or "Çhengey ardjynagh er enney" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th><td style="vertical-align:top;">' .. data.regional .. '</td></tr>' ) end if data.minority then local minorityLabel = data.minorityCount > 1 and "[[Mynçhengey|Mynçhengaghyn]]" or "[[Mynçhengey]]" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. minorityLabel .. '</th><td style="vertical-align:top;">' .. data.minority .. '</td></tr>' ) end if data.other then local otherLabel = data.otherLabel or (data.otherCount > 1 and "Çhengaghyn" or "Çhengey") table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. otherLabel .. '</th><td style="vertical-align:top;">' .. data.other .. '</td></tr>' ) end if #rows == 0 then return nil end return table.concat(rows) end function p.languages(frame) local args = getArgs(frame) return buildLanguageRows(args) end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCityEntityFromTitle(value) local title = normaliseCityName(value) if title == "" then return nil end local entityId = mw.wikibase.getEntityIdForTitle(title) if not entityId then return nil end return mw.wikibase.getEntity(entityId) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then return { text = capital, entity = getCityEntityFromTitle(capital), reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or entity:getLabel(), entity = entity, reference = getWikidataReference(statement) } end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then return { text = city, entity = getCityEntityFromTitle(city), reference = nil } end local country = mw.wikibase.getEntityObject() if not country then return nil end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id local target = mw.wikibase.getEntity(targetId) if target and not isDisambiguationPage(target) then local sitelink = target:getSitelink("gvwiki") return { text = sitelink or target:getLabel(), entity = target, reference = getWikidataReference(statement) } end end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) return { capital = getCapitalData(args), administrative = getAdministrativeCentreData(args), largest = getLargestCityData(args), labels = getCityLabels(args) } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end local title = nil if city.entity then title = city.entity:getSitelink("gvwiki") end if not title or title == "" then title = normaliseCityName(city.text) end if not title or title == "" then return "" end return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -------------------------------------------------- -- HEADER -------------------------------------------------- do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -------------------------------------------------- -- FLAG / ARMS -------------------------------------------------- do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -------------------------------------------------- -- MOTTO / ANTHEM -------------------------------------------------- do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -------------------------------------------------- -- CAPITAL / ADMINISTRATIVE CENTRE / LARGEST CITY -------------------------------------------------- do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels -- Add one divider before the city section only. if capital or administrative or largest then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '"></td></tr>' ) end -- Capital if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Administrative centre if administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Largest city if largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- do local languageRows = buildLanguageRows(args) if languageRows then table.insert(rows, languageRows) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p ni9ss7l6e2gb0s3bfyfcnlbpfaqj8sk 392891 392889 2026-09-07T01:33:16Z MacTire02 219 prowal red elley 392891 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -- Extract items from an hlist/flatlist/ubl template local function extractHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local items = {} local segments = splitTopLevel(inner, "|") for _, segment in ipairs(segments) do local trimmed = mw.text.trim(segment) -- Skip named parameters (class=, style=, etc.) if trimmed ~= "" and not mw.ustring.find(trimmed, "^[%w_%- ]+=") then -- Extract just the link text if it's a wikilink local linkText = mw.ustring.match(trimmed, "%[%[.-|(.+)%]%]") or mw.ustring.match(trimmed, "%[%[(.+)%]%]") or trimmed table.insert(items, mw.text.trim(linkText)) end end return items end -------------------------------------------------- -- DISAMBIGUATION GUARD -------------------------------------------------- -- Some Wikidata statements resolve to a general/ambiguous -- item rather than the specific thing we want (e.g. a -- country's "most populous urban area" pointing at the -- ambiguous "New York" (Q22654) instead of "New York City" -- (Q60)). Skip anything flagged as a disambiguation page. local function isDisambiguationPage(entity) if not entity then return false end local statements = entity:getBestStatements("P31") if not statements then return false end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" and mainsnak.datavalue.value.id == "Q4167410" then return true end end return false end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity and not isDisambiguationPage(linkedEntity) then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- FLAG BORDER CHECK -------------------------------------------------- -- List of countries with non-rectangular flags (no border needed) local NON_RECTANGULAR_FLAGS = { ["Flag of Nepal.svg"] = true, ["Flag of Ohio.svg"] = true, ["Flag of Switzerland.svg"] = true, } -- Check if a flag needs a border local function needsFlagBorder(flagFile) if not flagFile then return true end if NON_RECTANGULAR_FLAGS[flagFile] then return false end local lowerFile = mw.ustring.lower(flagFile) if mw.ustring.find(lowerFile, "nepal") then return false end return true end -------------------------------------------------- -- MULTI-FLAG SUPPORT -------------------------------------------------- local function getFlagData(args) -- Get primary flag local flag = getManual(args, {"jalloo_brattagh"}) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end -- Get second flag (if any) local flag2 = getManual(args, {"jalloo_brattagh_2", "jalloo_brattagh_elley"}) if flag2 and mw.ustring.lower(flag2) == "none" then flag2 = nil elseif not flag2 then flag2 = getWikidataImage("P163") end -- Get arms local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end -- Get second arms (if any) local arms2 = getManual(args, { "jalloo_armys_2", "jalloo_cleinney_2" }) if arms2 and mw.ustring.lower(arms2) == "none" then arms2 = nil elseif not arms2 then arms2 = getWikidataImage("P237") end if not flag and not flag2 and not arms and not arms2 then return nil end local name = getCountryGenitive(args) or "" local data = { flags = {}, armses = {} } -- Primary flag if flag then local flagWidth = getManual(args, {"lheead_brattagh"}) or "125px" local hasBorder = needsFlagBorder(flag) table.insert(data.flags, { image = flag, width = flagWidth, hasBorder = hasBorder, link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh"}) or "Brattagh", isPrimary = true }) end -- Second flag if flag2 then local flag2Width = getManual(args, {"lheead_brattagh_2", "lheead_brattagh"}) or "100px" local hasBorder2 = needsFlagBorder(flag2) table.insert(data.flags, { image = flag2, width = flag2Width, hasBorder = hasBorder2, link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh_2"}) or "Brattagh elley", isPrimary = false }) end -- Primary arms if arms then local kind = getManual(args, {"art_sorçh_cowrey"}) or getManual(args, {"sorçh_cowrey"}) or "Armys" table.insert(data.armses, { image = arms, width = getManual(args, {"lheead_armys", "lheead_cleinney", "lheead_cowrey"}) or "85px", link = kind .. " " .. name, label = getManual(args, {"sorçh_cowrey"}) or "Armys", isPrimary = true }) end -- Second arms if arms2 then table.insert(data.armses, { image = arms2, width = getManual(args, {"lheead_armys_2", "lheead_cleinney_2"}) or "85px", link = "Armys " .. name, label = getManual(args, {"sorçh_cowrey_2"}) or "Armys", isPrimary = false }) end return data end -------------------------------------------------- -- UPDATED getFlagArmsData (replaces old function) -------------------------------------------------- local function getFlagArmsData(args) return getFlagData(args) end -------------------------------------------------- -- FLAG / ARMS BLOCK (UPDATED) -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} local hasFlags = #data.flags > 0 local hasArms = #data.armses > 0 -- Build flag column if hasFlags then local flagContent = {} for i, flagData in ipairs(data.flags) do local borderStyle = "" if flagData.hasBorder then borderStyle = '|style="border:1px solid #a2a9b1;"' end local flagImage = '[[Coadan:' .. flagData.image .. '|' .. flagData.width .. borderStyle .. ']]' table.insert(flagContent, flagImage) end local combinedFlags = table.concat(flagContent, '<br/>') table.insert(imageCells, '<td align="center" style="' .. (hasArms and "width:58%; " or "width:100%; ") .. 'vertical-align:middle;">' .. combinedFlags .. '</td>' ) local flagCaptions = {} for i, flagData in ipairs(data.flags) do table.insert(flagCaptions, '<small>[[' .. flagData.link .. '|' .. flagData.label .. ']]</small>' ) end table.insert(captionCells, '<td align="center">' .. table.concat(flagCaptions, '<br/>') .. '</td>' ) end -- Build arms column if hasArms then local armsContent = {} for i, armsData in ipairs(data.armses) do local armsImage = '[[Coadan:' .. armsData.image .. '|' .. armsData.width .. ']]' table.insert(armsContent, armsImage) end local combinedArms = table.concat(armsContent, '<br/>') table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">' .. combinedArms .. '</td>' ) local armsCaptions = {} for i, armsData in ipairs(data.armses) do table.insert(armsCaptions, '<small>[[' .. armsData.link .. '|' .. armsData.label .. ']]</small>' ) end table.insert(captionCells, '<td align="center">' .. table.concat(armsCaptions, '<br/>') .. '</td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = '"' .. motto .. '"', reference = reference and "<ref>" .. reference .. "</ref>" or nil } end local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = '"' .. value.text .. '"', reference = getWikidataReference(statement) } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, {"arrane_ashoonagh"}) local royal = getManual(args, {"arrane_reeoil"}) local other = getManual(args, {"arrane"}) local nationalReference = getManual(args, {"imraa_arrane_ashoonagh"}) local royalReference = getManual(args, {"imraa_arrane_reeoil"}) local otherReference = getManual(args, {"imraa_arrane"}) -- New audio parameters mapping local nationalAudio = getManual(args, {"coadan_arrane_ashoonagh"}) local royalAudio = getManual(args, {"coadan_arrane_reeoil"}) local otherAudio = getManual(args, {"coadan_arrane"}) local result = { national = nil, royal = nil, other = nil } -- Process National Anthem manually if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and ("<ref>" .. nationalReference .. "</ref>") or nil, audio = nationalAudio } end -- Process Royal Anthem manually if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and ("<ref>" .. royalReference .. "</ref>") or nil, audio = royalAudio } end -- Process Other Anthem manually if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and ("<ref>" .. otherReference .. "</ref>") or nil, audio = otherAudio } end -- Fall back to Wikidata ONLY if absolutely no manual fields are declared if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text) end -- Helper to format anthem rows safely local function formatAnthemRow(label, anthemObj) if not anthemObj or not anthemObj.text then return nil end -- Safely clean quotation marks without breaking wikilinks local cleanText = anthemObj.text cleanText = mw.ustring.gsub(cleanText, '^"+', '') cleanText = mw.ustring.gsub(cleanText, '"+$', '') -- If it isn't already wikilinked, wrap it safely if not mw.ustring.find(cleanText, "%[%[") then cleanText = '[[' .. cleanText .. '|' .. cleanText .. ']]' end local display = '"' .. cleanText .. '"' if anthemObj.reference then display = display .. anthemObj.reference end if anthemObj.audio and anthemObj.audio ~= "" then display = display .. '<br/><div style="text-align:center; margin-top:0.2em;">[[Coadan:' .. anthemObj.audio .. '|center]]</div>' end -- CORRECTED LINE: Cleaned up and restored back to proper formatting logic return "'''" .. label .. ":&nbsp;'''" .. display end -- Run each anthem dynamically; multiple players can render in parallel local nationalRow = formatAnthemRow("[[Arrane ashoonagh]]", anthems.national) if nationalRow then table.insert(rows, nationalRow) end local otherRow = formatAnthemRow("Anthym", anthems.other) if otherRow then table.insert(rows, otherRow) end local royalRow = formatAnthemRow("[[Arrane reeoil]]", anthems.royal) if royalRow then table.insert(rows, royalRow) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- local function getLanguagesFromWikidata() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P37") if not statements or #statements == 0 then return {} end local languages = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local langEntity = mw.wikibase.getEntity(id) if langEntity then local label = langEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(languages, { text = label, role = role, reference = getWikidataReference(statement) }) end end end end return languages end local function classifyLanguages(languages) local result = { official = {}, regional = {}, minority = {} } for _, language in ipairs(languages) do local role = language.role or "" local lowerRole = mw.ustring.lower(role) if mw.ustring.find(lowerRole, "minority") then table.insert(result.minority, language) elseif mw.ustring.find(lowerRole, "regional") then table.insert(result.regional, language) else table.insert(result.official, language) end end return result end -- Manx-specific collation: çh sorts as ch local function manxSort(a, b) local function normalize(text) -- Replace çh with ch for sorting purposes text = mw.ustring.lower(text) text = mw.ustring.gsub(text, "çh", "ch") return text end return normalize(a) < normalize(b) end local function joinLanguageList(languages) if not languages or #languages == 0 then return nil end -- Sort languages alphabetically with Manx collation table.sort(languages, function(a, b) return manxSort(a.text, b.text) end) local parts = {} for _, language in ipairs(languages) do local text = language.text -- Wrap language name in a wikilink (even if redlinked) text = '[[' .. text .. '|' .. text .. ']]' if language.reference then text = text .. language.reference end table.insert(parts, text) end if #parts == 0 then return nil end -- Return as hlist format return '<div class="hlist">' .. table.concat(parts, '&nbsp;· ') .. '</div>' end -- Splits text on a top-level separator character, without -- splitting inside {{...}} or [[...]] (so a piped wikilink -- like [[Country|Display]], or a nested template, doesn't -- get miscounted as two items). local function splitTopLevel(text, sep) local parts = {} local current = {} local depthCurly = 0 local depthSquare = 0 local len = mw.ustring.len(text) local i = 1 while i <= len do local two = mw.ustring.sub(text, i, i + 1) local one = mw.ustring.sub(text, i, i) if two == "{{" then depthCurly = depthCurly + 1 table.insert(current, two) i = i + 2 elseif two == "}}" and depthCurly > 0 then depthCurly = depthCurly - 1 table.insert(current, two) i = i + 2 elseif two == "[[" then depthSquare = depthSquare + 1 table.insert(current, two) i = i + 2 elseif two == "]]" and depthSquare > 0 then depthSquare = depthSquare - 1 table.insert(current, two) i = i + 2 elseif one == sep and depthCurly == 0 and depthSquare == 0 then table.insert(parts, table.concat(current)) current = {} i = i + 1 else table.insert(current, one) i = i + 1 end end table.insert(parts, table.concat(current)) return parts end -- Counts the items inside a {{hlist|...}}/{{flatlist|...}}/ -- {{ubl|...}}/{{unbulleted list|...}} template call (the -- convention most legacy articles already use for this -- field). Returns nil if the text isn't one of these, so -- the caller can fall back to a plain heuristic. -- Finds the first call to a template matching namePattern -- anywhere in text (not just at the start/whole-string), -- respecting nested {{...}} so a template argument that -- itself contains braces doesn't break the search. Returns -- the inner content (everything after the first "|") or nil -- if no such template call is found. local function findTemplateCall(text, namePattern) local searchPattern = "{{%s*" .. namePattern .. "%s*|" local matchStart, matchEnd = mw.ustring.find(text, searchPattern) if not matchStart then return nil end local contentStart = matchEnd + 1 local depth = 1 local i = contentStart local len = mw.ustring.len(text) while i <= len do local two = mw.ustring.sub(text, i, i + 1) if two == "{{" then depth = depth + 1 i = i + 2 elseif two == "}}" then depth = depth - 1 i = i + 2 if depth == 0 then local contentEnd = i - 3 return mw.ustring.sub(text, contentStart, contentEnd) end else i = i + 1 end end return nil end -- Pulls any <ref>...</ref> (or self-closing <ref .../>) tags -- out of text, returning the text with them removed plus the -- extracted ref markup (already-valid <ref> tags, ready to -- use as-is - not to be re-wrapped). Returns (text, nil) if -- none are found. local function extractReferences(text) if not text then return text, nil end local refs = {} local cleaned = mw.ustring.gsub(text, "<ref[^>]*>.-</ref>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.ustring.gsub(cleaned, "<ref[^>]*/>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.text.trim(cleaned) if #refs == 0 then return cleaned, nil end return cleaned, table.concat(refs) end local function countHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local segments = splitTopLevel(inner, "|") local count = 0 for _, segment in ipairs(segments) do local trimmedSegment = mw.text.trim(segment) -- Skip named parameters (class=, style=, indent=, etc.) -- rather than counting them as list items. if trimmedSegment ~= "" and not mw.ustring.find(trimmedSegment, "^[%w_%- ]+=") then count = count + 1 end end return count end -- Count of items in a manually-entered language/list field, -- used to decide between a singular ("çhengey") and plural -- ("çhengaghyn") label. Wikidata-derived lists are counted -- exactly (see getLanguageData). Handles the {{hlist}} family -- (searched for anywhere in the text, not just as the entire -- value, since editors often append a trailing <ref> after -- the closing "}}") most legacy articles already use; -- otherwise falls back to a plain comma-count heuristic. local function countListItems(text) if not text or text == "" then return 0 end local hlistCount = countHlistItems(text) if hlistCount then return hlistCount end local count = 0 for _ in mw.text.gsplit(text, ",", true) do count = count + 1 end return count end -- Resolves one language tier from its raw manual parameter: -- strips out any inline <ref> tags (used as-is, since they're -- already valid markup), counts the list on the ref-stripped -- text, then re-appends the extracted ref(s) and/or a manual -- imraa_ reference (which - unlike an inline <ref> - is raw -- citation text that still needs wrapping) to the display value. local function wrapInWikilink(text) -- If already has wikilink syntax, don't double-wrap if mw.ustring.find(text, "%[%[") then return text end -- Otherwise wrap in wikilink return '[[' .. text .. '|' .. text .. ']]' end local function buildLanguageValue(raw, manualReference) if not raw or mw.ustring.lower(mw.text.trim(raw)) == "none" then return nil, 0 end local cleaned, inlineRefs = extractReferences(raw) local count = countListItems(cleaned) -- Try to extract from hlist template first local languageNames = extractHlistItems(cleaned) -- If not in hlist format, split by comma if not languageNames then languageNames = {} for part in mw.text.gsplit(cleaned, ",", true) do local trimmed = mw.text.trim(part) if trimmed ~= "" then table.insert(languageNames, trimmed) end end end -- Sort alphabetically with Manx collation table.sort(languageNames, manxSort) -- Wrap each in wikilink and build hlist local parts = {} for _, name in ipairs(languageNames) do table.insert(parts, '[[' .. name .. '|' .. name .. ']]') end local display = '<div class="hlist">' .. table.concat(parts, '&nbsp;· ') .. '</div>' if inlineRefs then display = display .. inlineRefs end if manualReference then display = display .. "<ref>" .. manualReference .. "</ref>" end return display, count end local function getLanguageData(args) local officialRaw = getManual(args, { "çhengaghyn_oikoil", "çhengey_oikoil" }) local officialReference = getManual(args, { "imraa_çhengaghyn_oikoil", "imraa_çhengey_oikoil" }) local regionalRaw = getManual(args, { "çhengaghyn_ardjynagh", "çhengey_ardjynagh" }) local regionalReference = getManual(args, { "imraa_çhengaghyn_ardjynagh", "imraa_çhengey_ardjynagh" }) local minorityRaw = getManual(args, { "mynçhengaghyn", "mynçhengey" }) local minorityReference = getManual(args, { "imraa_mynçhengaghyn", "imraa_mynçhengey" }) local otherRaw = getManual(args, { "çhengaghyn", "çhengey" }) local otherReference = getManual(args, { "imraa_çhengaghyn", "imraa_çhengey" }) local otherLabel = getManual(args, { "sorçh_çhengaghyn" }) local result = { otherLabel = otherLabel } result.official, result.officialCount = buildLanguageValue(officialRaw, officialReference) result.regional, result.regionalCount = buildLanguageValue(regionalRaw, regionalReference) result.minority, result.minorityCount = buildLanguageValue(minorityRaw, minorityReference) result.other, result.otherCount = buildLanguageValue(otherRaw, otherReference) -- Only reach for Wikidata if none of the three tiers -- were set manually - a manual "none" or partial set -- of overrides always wins over the auto-fetch. if not result.official and not result.regional and not result.minority then local classified = classifyLanguages(getLanguagesFromWikidata()) result.official = joinLanguageList(classified.official) result.officialCount = #classified.official result.regional = joinLanguageList(classified.regional) result.regionalCount = #classified.regional result.minority = joinLanguageList(classified.minority) result.minorityCount = #classified.minority end return result end local function buildLanguageRows(args) local data = getLanguageData(args) local rows = {} if data.official then local officialLabel = data.officialCount > 1 and "[[Çhengey oikoil|Çhengaghyn oikoil]]" or "[[Çhengey oikoil]]" local officialRow = '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. officialLabel .. '</th><td style="vertical-align:top;">' .. data.official .. '</td></tr>' if data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn&nbsp;ardjynagh er&nbsp;enney" or "Çhengey&nbsp;ardjynagh er&nbsp;enney" officialRow = officialRow .. '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:normal;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th>' .. '<td style="vertical-align:top;">' .. data.regional .. '</td></tr>' end table.insert(rows, officialRow) elseif data.regional then -- Regional recognised even without a separate -- official-language statement. local regionalLabel = data.regionalCount > 1 and "Çhengaghyn ardjynagh er enney" or "Çhengey ardjynagh er enney" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th><td style="vertical-align:top;">' .. data.regional .. '</td></tr>' ) end if data.minority then local minorityLabel = data.minorityCount > 1 and "[[Mynçhengey|Mynçhengaghyn]]" or "[[Mynçhengey]]" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. minorityLabel .. '</th><td style="vertical-align:top;">' .. data.minority .. '</td></tr>' ) end if data.other then local otherLabel = data.otherLabel or (data.otherCount > 1 and "Çhengaghyn" or "Çhengey") table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. otherLabel .. '</th><td style="vertical-align:top;">' .. data.other .. '</td></tr>' ) end if #rows == 0 then return nil end return table.concat(rows) end function p.languages(frame) local args = getArgs(frame) return buildLanguageRows(args) end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCityEntityFromTitle(value) local title = normaliseCityName(value) if title == "" then return nil end local entityId = mw.wikibase.getEntityIdForTitle(title) if not entityId then return nil end return mw.wikibase.getEntity(entityId) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then return { text = capital, entity = getCityEntityFromTitle(capital), reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or entity:getLabel(), entity = entity, reference = getWikidataReference(statement) } end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then return { text = city, entity = getCityEntityFromTitle(city), reference = nil } end local country = mw.wikibase.getEntityObject() if not country then return nil end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id local target = mw.wikibase.getEntity(targetId) if target and not isDisambiguationPage(target) then local sitelink = target:getSitelink("gvwiki") return { text = sitelink or target:getLabel(), entity = target, reference = getWikidataReference(statement) } end end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) return { capital = getCapitalData(args), administrative = getAdministrativeCentreData(args), largest = getLargestCityData(args), labels = getCityLabels(args) } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end local title = nil if city.entity then title = city.entity:getSitelink("gvwiki") end if not title or title == "" then title = normaliseCityName(city.text) end if not title or title == "" then return "" end return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -------------------------------------------------- -- HEADER -------------------------------------------------- do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -------------------------------------------------- -- FLAG / ARMS -------------------------------------------------- do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -------------------------------------------------- -- MOTTO / ANTHEM -------------------------------------------------- do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -------------------------------------------------- -- CAPITAL / ADMINISTRATIVE CENTRE / LARGEST CITY -------------------------------------------------- do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels -- Add one divider before the city section only. if capital or administrative or largest then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '"></td></tr>' ) end -- Capital if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Administrative centre if administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Largest city if largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- do local languageRows = buildLanguageRows(args) if languageRows then table.insert(rows, languageRows) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p egjta2679kdxa42j4tqnu2z0ofebgs0 392892 392891 2026-09-07T01:46:17Z MacTire02 219 ++ 392892 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -- Extract items from an hlist/flatlist/ubl template local function extractHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local items = {} local segments = splitTopLevel(inner, "|") for _, segment in ipairs(segments) do local trimmed = mw.text.trim(segment) -- Skip named parameters (class=, style=, etc.) if trimmed ~= "" and not mw.ustring.find(trimmed, "^[%w_%- ]+=") then -- Extract just the link text if it's a wikilink local linkText = mw.ustring.match(trimmed, "%[%[.-|(.+)%]%]") or mw.ustring.match(trimmed, "%[%[(.+)%]%]") or trimmed table.insert(items, mw.text.trim(linkText)) end end return items end -------------------------------------------------- -- DISAMBIGUATION GUARD -------------------------------------------------- -- Some Wikidata statements resolve to a general/ambiguous -- item rather than the specific thing we want (e.g. a -- country's "most populous urban area" pointing at the -- ambiguous "New York" (Q22654) instead of "New York City" -- (Q60)). Skip anything flagged as a disambiguation page. local function isDisambiguationPage(entity) if not entity then return false end local statements = entity:getBestStatements("P31") if not statements then return false end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" and mainsnak.datavalue.value.id == "Q4167410" then return true end end return false end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity and not isDisambiguationPage(linkedEntity) then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- FLAG BORDER CHECK -------------------------------------------------- -- List of countries with non-rectangular flags (no border needed) local NON_RECTANGULAR_FLAGS = { ["Flag of Nepal.svg"] = true, ["Flag of Ohio.svg"] = true, ["Flag of Switzerland.svg"] = true, } -- Check if a flag needs a border local function needsFlagBorder(flagFile) if not flagFile then return true end if NON_RECTANGULAR_FLAGS[flagFile] then return false end local lowerFile = mw.ustring.lower(flagFile) if mw.ustring.find(lowerFile, "nepal") then return false end return true end -------------------------------------------------- -- MULTI-FLAG SUPPORT -------------------------------------------------- local function getFlagData(args) -- Get primary flag local flag = getManual(args, {"jalloo_brattagh"}) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end -- Get second flag (if any) local flag2 = getManual(args, {"jalloo_brattagh_2", "jalloo_brattagh_elley"}) if flag2 and mw.ustring.lower(flag2) == "none" then flag2 = nil elseif not flag2 then flag2 = getWikidataImage("P163") end -- Get arms local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end -- Get second arms (if any) local arms2 = getManual(args, { "jalloo_armys_2", "jalloo_cleinney_2" }) if arms2 and mw.ustring.lower(arms2) == "none" then arms2 = nil elseif not arms2 then arms2 = getWikidataImage("P237") end if not flag and not flag2 and not arms and not arms2 then return nil end local name = getCountryGenitive(args) or "" local data = { flags = {}, armses = {} } -- Primary flag if flag then local flagWidth = getManual(args, {"lheead_brattagh"}) or "125px" local hasBorder = needsFlagBorder(flag) table.insert(data.flags, { image = flag, width = flagWidth, hasBorder = hasBorder, link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh"}) or "Brattagh", isPrimary = true }) end -- Second flag if flag2 then local flag2Width = getManual(args, {"lheead_brattagh_2", "lheead_brattagh"}) or "100px" local hasBorder2 = needsFlagBorder(flag2) table.insert(data.flags, { image = flag2, width = flag2Width, hasBorder = hasBorder2, link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh_2"}) or "Brattagh elley", isPrimary = false }) end -- Primary arms if arms then local kind = getManual(args, {"art_sorçh_cowrey"}) or getManual(args, {"sorçh_cowrey"}) or "Armys" table.insert(data.armses, { image = arms, width = getManual(args, {"lheead_armys", "lheead_cleinney", "lheead_cowrey"}) or "85px", link = kind .. " " .. name, label = getManual(args, {"sorçh_cowrey"}) or "Armys", isPrimary = true }) end -- Second arms if arms2 then table.insert(data.armses, { image = arms2, width = getManual(args, {"lheead_armys_2", "lheead_cleinney_2"}) or "85px", link = "Armys " .. name, label = getManual(args, {"sorçh_cowrey_2"}) or "Armys", isPrimary = false }) end return data end -------------------------------------------------- -- UPDATED getFlagArmsData (replaces old function) -------------------------------------------------- local function getFlagArmsData(args) return getFlagData(args) end -------------------------------------------------- -- FLAG / ARMS BLOCK (UPDATED) -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} local hasFlags = #data.flags > 0 local hasArms = #data.armses > 0 -- Build flag column if hasFlags then local flagContent = {} for i, flagData in ipairs(data.flags) do local borderStyle = "" if flagData.hasBorder then borderStyle = '|style="border:1px solid #a2a9b1;"' end local flagImage = '[[Coadan:' .. flagData.image .. '|' .. flagData.width .. borderStyle .. ']]' table.insert(flagContent, flagImage) end local combinedFlags = table.concat(flagContent, '<br/>') table.insert(imageCells, '<td align="center" style="' .. (hasArms and "width:58%; " or "width:100%; ") .. 'vertical-align:middle;">' .. combinedFlags .. '</td>' ) local flagCaptions = {} for i, flagData in ipairs(data.flags) do table.insert(flagCaptions, '<small>[[' .. flagData.link .. '|' .. flagData.label .. ']]</small>' ) end table.insert(captionCells, '<td align="center">' .. table.concat(flagCaptions, '<br/>') .. '</td>' ) end -- Build arms column if hasArms then local armsContent = {} for i, armsData in ipairs(data.armses) do local armsImage = '[[Coadan:' .. armsData.image .. '|' .. armsData.width .. ']]' table.insert(armsContent, armsImage) end local combinedArms = table.concat(armsContent, '<br/>') table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">' .. combinedArms .. '</td>' ) local armsCaptions = {} for i, armsData in ipairs(data.armses) do table.insert(armsCaptions, '<small>[[' .. armsData.link .. '|' .. armsData.label .. ']]</small>' ) end table.insert(captionCells, '<td align="center">' .. table.concat(armsCaptions, '<br/>') .. '</td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = '"' .. motto .. '"', reference = reference and "<ref>" .. reference .. "</ref>" or nil } end local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = '"' .. value.text .. '"', reference = getWikidataReference(statement) } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, {"arrane_ashoonagh"}) local royal = getManual(args, {"arrane_reeoil"}) local other = getManual(args, {"arrane"}) local nationalReference = getManual(args, {"imraa_arrane_ashoonagh"}) local royalReference = getManual(args, {"imraa_arrane_reeoil"}) local otherReference = getManual(args, {"imraa_arrane"}) -- Updated to your preferred parameter nomenclature local nationalAudio = getManual(args, {"coadan_arrane_ashoonagh"}) local royalAudio = getManual(args, {"coadan_arrane_reeoil"}) local otherAudio = getManual(args, {"coadan_arrane"}) -- Updated to match the requested noteyn_ prefix pattern local nationalNote = getManual(args, {"noteyn_arrane_ashoonagh"}) local royalNote = getManual(args, {"noteyn_arrane_reeoil"}) local otherNote = getManual(args, {"noteyn_arrane"}) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and ("<ref>" .. nationalReference .. "</ref>") or nil, audio = nationalAudio, note = nationalNote } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and ("<ref>" .. royalReference .. "</ref>") or nil, audio = royalAudio, note = royalNote } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and ("<ref>" .. otherReference .. "</ref>") or nil, audio = otherAudio, note = otherNote } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text) end -- Helper to format anthem rows safely local function formatAnthemRow(label, anthemObj) if not anthemObj or not anthemObj.text then return nil end local cleanText = anthemObj.text cleanText = mw.ustring.gsub(cleanText, '^"+', '') cleanText = mw.ustring.gsub(cleanText, '"+$', '') if not mw.ustring.find(cleanText, "%[%[") then cleanText = '[[' .. cleanText .. '|' .. cleanText .. ']]' end local display = '"' .. cleanText .. '"' -- Append the efn note directly after the text string if anthemObj.note and anthemObj.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { anthemObj.note } } display = display .. efnOut end -- Append any manual citation strings right after the footnote marker if anthemObj.reference then display = display .. anthemObj.reference end if anthemObj.audio and anthemObj.audio ~= "" then display = display .. '<br/><div style="text-align:center; margin-top:0.2em;">[[Coadan:' .. anthemObj.audio .. '|center]]</div>' end return "'''" .. label .. ":&nbsp;'''" .. display end local nationalRow = formatAnthemRow("[[Arrane ashoonagh]]", anthems.national) if nationalRow then table.insert(rows, nationalRow) end local otherRow = formatAnthemRow("Anthym", anthems.other) if otherRow then table.insert(rows, otherRow) end local royalRow = formatAnthemRow("[[Arrane reeoil]]", anthems.royal) if royalRow then table.insert(rows, royalRow) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- local function getLanguagesFromWikidata() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P37") if not statements or #statements == 0 then return {} end local languages = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local langEntity = mw.wikibase.getEntity(id) if langEntity then local label = langEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(languages, { text = label, role = role, reference = getWikidataReference(statement) }) end end end end return languages end local function classifyLanguages(languages) local result = { official = {}, regional = {}, minority = {} } for _, language in ipairs(languages) do local role = language.role or "" local lowerRole = mw.ustring.lower(role) if mw.ustring.find(lowerRole, "minority") then table.insert(result.minority, language) elseif mw.ustring.find(lowerRole, "regional") then table.insert(result.regional, language) else table.insert(result.official, language) end end return result end -- Manx-specific collation: çh sorts as ch local function manxSort(a, b) local function normalize(text) -- Replace çh with ch for sorting purposes text = mw.ustring.lower(text) text = mw.ustring.gsub(text, "çh", "ch") return text end return normalize(a) < normalize(b) end local function joinLanguageList(languages) if not languages or #languages == 0 then return nil end -- Sort languages alphabetically with Manx collation table.sort(languages, function(a, b) return manxSort(a.text, b.text) end) local parts = {} for _, language in ipairs(languages) do local text = language.text -- Wrap language name in a wikilink (even if redlinked) text = '[[' .. text .. '|' .. text .. ']]' if language.reference then text = text .. language.reference end table.insert(parts, text) end if #parts == 0 then return nil end -- Return as hlist format return '<div class="hlist">' .. table.concat(parts, '&nbsp;· ') .. '</div>' end -- Splits text on a top-level separator character, without -- splitting inside {{...}} or [[...]] (so a piped wikilink -- like [[Country|Display]], or a nested template, doesn't -- get miscounted as two items). local function splitTopLevel(text, sep) local parts = {} local current = {} local depthCurly = 0 local depthSquare = 0 local len = mw.ustring.len(text) local i = 1 while i <= len do local two = mw.ustring.sub(text, i, i + 1) local one = mw.ustring.sub(text, i, i) if two == "{{" then depthCurly = depthCurly + 1 table.insert(current, two) i = i + 2 elseif two == "}}" and depthCurly > 0 then depthCurly = depthCurly - 1 table.insert(current, two) i = i + 2 elseif two == "[[" then depthSquare = depthSquare + 1 table.insert(current, two) i = i + 2 elseif two == "]]" and depthSquare > 0 then depthSquare = depthSquare - 1 table.insert(current, two) i = i + 2 elseif one == sep and depthCurly == 0 and depthSquare == 0 then table.insert(parts, table.concat(current)) current = {} i = i + 1 else table.insert(current, one) i = i + 1 end end table.insert(parts, table.concat(current)) return parts end -- Counts the items inside a {{hlist|...}}/{{flatlist|...}}/ -- {{ubl|...}}/{{unbulleted list|...}} template call (the -- convention most legacy articles already use for this -- field). Returns nil if the text isn't one of these, so -- the caller can fall back to a plain heuristic. -- Finds the first call to a template matching namePattern -- anywhere in text (not just at the start/whole-string), -- respecting nested {{...}} so a template argument that -- itself contains braces doesn't break the search. Returns -- the inner content (everything after the first "|") or nil -- if no such template call is found. local function findTemplateCall(text, namePattern) local searchPattern = "{{%s*" .. namePattern .. "%s*|" local matchStart, matchEnd = mw.ustring.find(text, searchPattern) if not matchStart then return nil end local contentStart = matchEnd + 1 local depth = 1 local i = contentStart local len = mw.ustring.len(text) while i <= len do local two = mw.ustring.sub(text, i, i + 1) if two == "{{" then depth = depth + 1 i = i + 2 elseif two == "}}" then depth = depth - 1 i = i + 2 if depth == 0 then local contentEnd = i - 3 return mw.ustring.sub(text, contentStart, contentEnd) end else i = i + 1 end end return nil end -- Pulls any <ref>...</ref> (or self-closing <ref .../>) tags -- out of text, returning the text with them removed plus the -- extracted ref markup (already-valid <ref> tags, ready to -- use as-is - not to be re-wrapped). Returns (text, nil) if -- none are found. local function extractReferences(text) if not text then return text, nil end local refs = {} local cleaned = mw.ustring.gsub(text, "<ref[^>]*>.-</ref>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.ustring.gsub(cleaned, "<ref[^>]*/>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.text.trim(cleaned) if #refs == 0 then return cleaned, nil end return cleaned, table.concat(refs) end local function countHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local segments = splitTopLevel(inner, "|") local count = 0 for _, segment in ipairs(segments) do local trimmedSegment = mw.text.trim(segment) -- Skip named parameters (class=, style=, indent=, etc.) -- rather than counting them as list items. if trimmedSegment ~= "" and not mw.ustring.find(trimmedSegment, "^[%w_%- ]+=") then count = count + 1 end end return count end -- Count of items in a manually-entered language/list field, -- used to decide between a singular ("çhengey") and plural -- ("çhengaghyn") label. Wikidata-derived lists are counted -- exactly (see getLanguageData). Handles the {{hlist}} family -- (searched for anywhere in the text, not just as the entire -- value, since editors often append a trailing <ref> after -- the closing "}}") most legacy articles already use; -- otherwise falls back to a plain comma-count heuristic. local function countListItems(text) if not text or text == "" then return 0 end local hlistCount = countHlistItems(text) if hlistCount then return hlistCount end local count = 0 for _ in mw.text.gsplit(text, ",", true) do count = count + 1 end return count end -- Resolves one language tier from its raw manual parameter: -- strips out any inline <ref> tags (used as-is, since they're -- already valid markup), counts the list on the ref-stripped -- text, then re-appends the extracted ref(s) and/or a manual -- imraa_ reference (which - unlike an inline <ref> - is raw -- citation text that still needs wrapping) to the display value. local function wrapInWikilink(text) -- If already has wikilink syntax, don't double-wrap if mw.ustring.find(text, "%[%[") then return text end -- Otherwise wrap in wikilink return '[[' .. text .. '|' .. text .. ']]' end local function buildLanguageValue(raw, manualReference) if not raw or mw.ustring.lower(mw.text.trim(raw)) == "none" then return nil, 0 end local cleaned, inlineRefs = extractReferences(raw) local count = countListItems(cleaned) -- Try to extract from hlist template first local languageNames = extractHlistItems(cleaned) -- If not in hlist format, split by comma if not languageNames then languageNames = {} for part in mw.text.gsplit(cleaned, ",", true) do local trimmed = mw.text.trim(part) if trimmed ~= "" then table.insert(languageNames, trimmed) end end end -- Sort alphabetically with Manx collation table.sort(languageNames, manxSort) -- Wrap each in wikilink and build hlist local parts = {} for _, name in ipairs(languageNames) do table.insert(parts, '[[' .. name .. '|' .. name .. ']]') end local display = '<div class="hlist">' .. table.concat(parts, '&nbsp;· ') .. '</div>' if inlineRefs then display = display .. inlineRefs end if manualReference then display = display .. "<ref>" .. manualReference .. "</ref>" end return display, count end local function getLanguageData(args) local officialRaw = getManual(args, { "çhengaghyn_oikoil", "çhengey_oikoil" }) local officialReference = getManual(args, { "imraa_çhengaghyn_oikoil", "imraa_çhengey_oikoil" }) local regionalRaw = getManual(args, { "çhengaghyn_ardjynagh", "çhengey_ardjynagh" }) local regionalReference = getManual(args, { "imraa_çhengaghyn_ardjynagh", "imraa_çhengey_ardjynagh" }) local minorityRaw = getManual(args, { "mynçhengaghyn", "mynçhengey" }) local minorityReference = getManual(args, { "imraa_mynçhengaghyn", "imraa_mynçhengey" }) local otherRaw = getManual(args, { "çhengaghyn", "çhengey" }) local otherReference = getManual(args, { "imraa_çhengaghyn", "imraa_çhengey" }) local otherLabel = getManual(args, { "sorçh_çhengaghyn" }) local result = { otherLabel = otherLabel } result.official, result.officialCount = buildLanguageValue(officialRaw, officialReference) result.regional, result.regionalCount = buildLanguageValue(regionalRaw, regionalReference) result.minority, result.minorityCount = buildLanguageValue(minorityRaw, minorityReference) result.other, result.otherCount = buildLanguageValue(otherRaw, otherReference) -- Only reach for Wikidata if none of the three tiers -- were set manually - a manual "none" or partial set -- of overrides always wins over the auto-fetch. if not result.official and not result.regional and not result.minority then local classified = classifyLanguages(getLanguagesFromWikidata()) result.official = joinLanguageList(classified.official) result.officialCount = #classified.official result.regional = joinLanguageList(classified.regional) result.regionalCount = #classified.regional result.minority = joinLanguageList(classified.minority) result.minorityCount = #classified.minority end return result end local function buildLanguageRows(args) local data = getLanguageData(args) local rows = {} if data.official then local officialLabel = data.officialCount > 1 and "[[Çhengey oikoil|Çhengaghyn oikoil]]" or "[[Çhengey oikoil]]" local officialRow = '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. officialLabel .. '</th><td style="vertical-align:top;">' .. data.official .. '</td></tr>' if data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn&nbsp;ardjynagh er&nbsp;enney" or "Çhengey&nbsp;ardjynagh er&nbsp;enney" officialRow = officialRow .. '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:normal;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th>' .. '<td style="vertical-align:top;">' .. data.regional .. '</td></tr>' end table.insert(rows, officialRow) elseif data.regional then -- Regional recognised even without a separate -- official-language statement. local regionalLabel = data.regionalCount > 1 and "Çhengaghyn ardjynagh er enney" or "Çhengey ardjynagh er enney" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th><td style="vertical-align:top;">' .. data.regional .. '</td></tr>' ) end if data.minority then local minorityLabel = data.minorityCount > 1 and "[[Mynçhengey|Mynçhengaghyn]]" or "[[Mynçhengey]]" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. minorityLabel .. '</th><td style="vertical-align:top;">' .. data.minority .. '</td></tr>' ) end if data.other then local otherLabel = data.otherLabel or (data.otherCount > 1 and "Çhengaghyn" or "Çhengey") table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. otherLabel .. '</th><td style="vertical-align:top;">' .. data.other .. '</td></tr>' ) end if #rows == 0 then return nil end return table.concat(rows) end function p.languages(frame) local args = getArgs(frame) return buildLanguageRows(args) end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCityEntityFromTitle(value) local title = normaliseCityName(value) if title == "" then return nil end local entityId = mw.wikibase.getEntityIdForTitle(title) if not entityId then return nil end return mw.wikibase.getEntity(entityId) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end if capital then return { text = capital, entity = getCityEntityFromTitle(capital), reference = nil } end local entity, statement = getWikidataItem("P36") if entity then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or entity:getLabel(), entity = entity, reference = getWikidataReference(statement) } end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then return { text = city, entity = getCityEntityFromTitle(city), reference = nil } end local country = mw.wikibase.getEntityObject() if not country then return nil end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id local target = mw.wikibase.getEntity(targetId) if target and not isDisambiguationPage(target) then local sitelink = target:getSitelink("gvwiki") return { text = sitelink or target:getLabel(), entity = target, reference = getWikidataReference(statement) } end end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) return { capital = getCapitalData(args), administrative = getAdministrativeCentreData(args), largest = getLargestCityData(args), labels = getCityLabels(args) } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end local title = nil if city.entity then title = city.entity:getSitelink("gvwiki") end if not title or title == "" then title = normaliseCityName(city.text) end if not title or title == "" then return "" end return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest if capital then local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end return text elseif administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text elseif largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end return text end return nil end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -------------------------------------------------- -- HEADER -------------------------------------------------- do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -------------------------------------------------- -- FLAG / ARMS -------------------------------------------------- do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -------------------------------------------------- -- MOTTO / ANTHEM -------------------------------------------------- do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -------------------------------------------------- -- CAPITAL / ADMINISTRATIVE CENTRE / LARGEST CITY -------------------------------------------------- do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels -- Add one divider before the city section only. if capital or administrative or largest then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '"></td></tr>' ) end -- Capital if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Administrative centre if administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Largest city if largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- do local languageRows = buildLanguageRows(args) if languageRows then table.insert(rows, languageRows) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p c9row051zjvd6pp13518hi4ejy0qypl 392893 392892 2026-09-07T01:49:19Z MacTire02 219 +noteyn da ny h-ard-valjyn 392893 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -- Extract items from an hlist/flatlist/ubl template local function extractHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local items = {} local segments = splitTopLevel(inner, "|") for _, segment in ipairs(segments) do local trimmed = mw.text.trim(segment) -- Skip named parameters (class=, style=, etc.) if trimmed ~= "" and not mw.ustring.find(trimmed, "^[%w_%- ]+=") then -- Extract just the link text if it's a wikilink local linkText = mw.ustring.match(trimmed, "%[%[.-|(.+)%]%]") or mw.ustring.match(trimmed, "%[%[(.+)%]%]") or trimmed table.insert(items, mw.text.trim(linkText)) end end return items end -------------------------------------------------- -- DISAMBIGUATION GUARD -------------------------------------------------- -- Some Wikidata statements resolve to a general/ambiguous -- item rather than the specific thing we want (e.g. a -- country's "most populous urban area" pointing at the -- ambiguous "New York" (Q22654) instead of "New York City" -- (Q60)). Skip anything flagged as a disambiguation page. local function isDisambiguationPage(entity) if not entity then return false end local statements = entity:getBestStatements("P31") if not statements then return false end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" and mainsnak.datavalue.value.id == "Q4167410" then return true end end return false end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity and not isDisambiguationPage(linkedEntity) then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- FLAG BORDER CHECK -------------------------------------------------- -- List of countries with non-rectangular flags (no border needed) local NON_RECTANGULAR_FLAGS = { ["Flag of Nepal.svg"] = true, ["Flag of Ohio.svg"] = true, ["Flag of Switzerland.svg"] = true, } -- Check if a flag needs a border local function needsFlagBorder(flagFile) if not flagFile then return true end if NON_RECTANGULAR_FLAGS[flagFile] then return false end local lowerFile = mw.ustring.lower(flagFile) if mw.ustring.find(lowerFile, "nepal") then return false end return true end -------------------------------------------------- -- MULTI-FLAG SUPPORT -------------------------------------------------- local function getFlagData(args) -- Get primary flag local flag = getManual(args, {"jalloo_brattagh"}) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end -- Get second flag (if any) local flag2 = getManual(args, {"jalloo_brattagh_2", "jalloo_brattagh_elley"}) if flag2 and mw.ustring.lower(flag2) == "none" then flag2 = nil elseif not flag2 then flag2 = getWikidataImage("P163") end -- Get arms local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end -- Get second arms (if any) local arms2 = getManual(args, { "jalloo_armys_2", "jalloo_cleinney_2" }) if arms2 and mw.ustring.lower(arms2) == "none" then arms2 = nil elseif not arms2 then arms2 = getWikidataImage("P237") end if not flag and not flag2 and not arms and not arms2 then return nil end local name = getCountryGenitive(args) or "" local data = { flags = {}, armses = {} } -- Primary flag if flag then local flagWidth = getManual(args, {"lheead_brattagh"}) or "125px" local hasBorder = needsFlagBorder(flag) table.insert(data.flags, { image = flag, width = flagWidth, hasBorder = hasBorder, link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh"}) or "Brattagh", isPrimary = true }) end -- Second flag if flag2 then local flag2Width = getManual(args, {"lheead_brattagh_2", "lheead_brattagh"}) or "100px" local hasBorder2 = needsFlagBorder(flag2) table.insert(data.flags, { image = flag2, width = flag2Width, hasBorder = hasBorder2, link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh_2"}) or "Brattagh elley", isPrimary = false }) end -- Primary arms if arms then local kind = getManual(args, {"art_sorçh_cowrey"}) or getManual(args, {"sorçh_cowrey"}) or "Armys" table.insert(data.armses, { image = arms, width = getManual(args, {"lheead_armys", "lheead_cleinney", "lheead_cowrey"}) or "85px", link = kind .. " " .. name, label = getManual(args, {"sorçh_cowrey"}) or "Armys", isPrimary = true }) end -- Second arms if arms2 then table.insert(data.armses, { image = arms2, width = getManual(args, {"lheead_armys_2", "lheead_cleinney_2"}) or "85px", link = "Armys " .. name, label = getManual(args, {"sorçh_cowrey_2"}) or "Armys", isPrimary = false }) end return data end -------------------------------------------------- -- UPDATED getFlagArmsData (replaces old function) -------------------------------------------------- local function getFlagArmsData(args) return getFlagData(args) end -------------------------------------------------- -- FLAG / ARMS BLOCK (UPDATED) -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} local hasFlags = #data.flags > 0 local hasArms = #data.armses > 0 -- Build flag column if hasFlags then local flagContent = {} for i, flagData in ipairs(data.flags) do local borderStyle = "" if flagData.hasBorder then borderStyle = '|style="border:1px solid #a2a9b1;"' end local flagImage = '[[Coadan:' .. flagData.image .. '|' .. flagData.width .. borderStyle .. ']]' table.insert(flagContent, flagImage) end local combinedFlags = table.concat(flagContent, '<br/>') table.insert(imageCells, '<td align="center" style="' .. (hasArms and "width:58%; " or "width:100%; ") .. 'vertical-align:middle;">' .. combinedFlags .. '</td>' ) local flagCaptions = {} for i, flagData in ipairs(data.flags) do table.insert(flagCaptions, '<small>[[' .. flagData.link .. '|' .. flagData.label .. ']]</small>' ) end table.insert(captionCells, '<td align="center">' .. table.concat(flagCaptions, '<br/>') .. '</td>' ) end -- Build arms column if hasArms then local armsContent = {} for i, armsData in ipairs(data.armses) do local armsImage = '[[Coadan:' .. armsData.image .. '|' .. armsData.width .. ']]' table.insert(armsContent, armsImage) end local combinedArms = table.concat(armsContent, '<br/>') table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">' .. combinedArms .. '</td>' ) local armsCaptions = {} for i, armsData in ipairs(data.armses) do table.insert(armsCaptions, '<small>[[' .. armsData.link .. '|' .. armsData.label .. ']]</small>' ) end table.insert(captionCells, '<td align="center">' .. table.concat(armsCaptions, '<br/>') .. '</td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = '"' .. motto .. '"', reference = reference and "<ref>" .. reference .. "</ref>" or nil } end local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = '"' .. value.text .. '"', reference = getWikidataReference(statement) } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, {"arrane_ashoonagh"}) local royal = getManual(args, {"arrane_reeoil"}) local other = getManual(args, {"arrane"}) local nationalReference = getManual(args, {"imraa_arrane_ashoonagh"}) local royalReference = getManual(args, {"imraa_arrane_reeoil"}) local otherReference = getManual(args, {"imraa_arrane"}) -- Updated to your preferred parameter nomenclature local nationalAudio = getManual(args, {"coadan_arrane_ashoonagh"}) local royalAudio = getManual(args, {"coadan_arrane_reeoil"}) local otherAudio = getManual(args, {"coadan_arrane"}) -- Updated to match the requested noteyn_ prefix pattern local nationalNote = getManual(args, {"noteyn_arrane_ashoonagh"}) local royalNote = getManual(args, {"noteyn_arrane_reeoil"}) local otherNote = getManual(args, {"noteyn_arrane"}) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and ("<ref>" .. nationalReference .. "</ref>") or nil, audio = nationalAudio, note = nationalNote } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and ("<ref>" .. royalReference .. "</ref>") or nil, audio = royalAudio, note = royalNote } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and ("<ref>" .. otherReference .. "</ref>") or nil, audio = otherAudio, note = otherNote } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text) end -- Helper to format anthem rows safely local function formatAnthemRow(label, anthemObj) if not anthemObj or not anthemObj.text then return nil end local cleanText = anthemObj.text cleanText = mw.ustring.gsub(cleanText, '^"+', '') cleanText = mw.ustring.gsub(cleanText, '"+$', '') if not mw.ustring.find(cleanText, "%[%[") then cleanText = '[[' .. cleanText .. '|' .. cleanText .. ']]' end local display = '"' .. cleanText .. '"' -- Append the efn note directly after the text string if anthemObj.note and anthemObj.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { anthemObj.note } } display = display .. efnOut end -- Append any manual citation strings right after the footnote marker if anthemObj.reference then display = display .. anthemObj.reference end if anthemObj.audio and anthemObj.audio ~= "" then display = display .. '<br/><div style="text-align:center; margin-top:0.2em;">[[Coadan:' .. anthemObj.audio .. '|center]]</div>' end return "'''" .. label .. ":&nbsp;'''" .. display end local nationalRow = formatAnthemRow("[[Arrane ashoonagh]]", anthems.national) if nationalRow then table.insert(rows, nationalRow) end local otherRow = formatAnthemRow("Anthym", anthems.other) if otherRow then table.insert(rows, otherRow) end local royalRow = formatAnthemRow("[[Arrane reeoil]]", anthems.royal) if royalRow then table.insert(rows, royalRow) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- local function getLanguagesFromWikidata() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P37") if not statements or #statements == 0 then return {} end local languages = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local langEntity = mw.wikibase.getEntity(id) if langEntity then local label = langEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(languages, { text = label, role = role, reference = getWikidataReference(statement) }) end end end end return languages end local function classifyLanguages(languages) local result = { official = {}, regional = {}, minority = {} } for _, language in ipairs(languages) do local role = language.role or "" local lowerRole = mw.ustring.lower(role) if mw.ustring.find(lowerRole, "minority") then table.insert(result.minority, language) elseif mw.ustring.find(lowerRole, "regional") then table.insert(result.regional, language) else table.insert(result.official, language) end end return result end -- Manx-specific collation: çh sorts as ch local function manxSort(a, b) local function normalize(text) -- Replace çh with ch for sorting purposes text = mw.ustring.lower(text) text = mw.ustring.gsub(text, "çh", "ch") return text end return normalize(a) < normalize(b) end local function joinLanguageList(languages) if not languages or #languages == 0 then return nil end -- Sort languages alphabetically with Manx collation table.sort(languages, function(a, b) return manxSort(a.text, b.text) end) local parts = {} for _, language in ipairs(languages) do local text = language.text -- Wrap language name in a wikilink (even if redlinked) text = '[[' .. text .. '|' .. text .. ']]' if language.reference then text = text .. language.reference end table.insert(parts, text) end if #parts == 0 then return nil end -- Return as hlist format return '<div class="hlist">' .. table.concat(parts, '&nbsp;· ') .. '</div>' end -- Splits text on a top-level separator character, without -- splitting inside {{...}} or [[...]] (so a piped wikilink -- like [[Country|Display]], or a nested template, doesn't -- get miscounted as two items). local function splitTopLevel(text, sep) local parts = {} local current = {} local depthCurly = 0 local depthSquare = 0 local len = mw.ustring.len(text) local i = 1 while i <= len do local two = mw.ustring.sub(text, i, i + 1) local one = mw.ustring.sub(text, i, i) if two == "{{" then depthCurly = depthCurly + 1 table.insert(current, two) i = i + 2 elseif two == "}}" and depthCurly > 0 then depthCurly = depthCurly - 1 table.insert(current, two) i = i + 2 elseif two == "[[" then depthSquare = depthSquare + 1 table.insert(current, two) i = i + 2 elseif two == "]]" and depthSquare > 0 then depthSquare = depthSquare - 1 table.insert(current, two) i = i + 2 elseif one == sep and depthCurly == 0 and depthSquare == 0 then table.insert(parts, table.concat(current)) current = {} i = i + 1 else table.insert(current, one) i = i + 1 end end table.insert(parts, table.concat(current)) return parts end -- Counts the items inside a {{hlist|...}}/{{flatlist|...}}/ -- {{ubl|...}}/{{unbulleted list|...}} template call (the -- convention most legacy articles already use for this -- field). Returns nil if the text isn't one of these, so -- the caller can fall back to a plain heuristic. -- Finds the first call to a template matching namePattern -- anywhere in text (not just at the start/whole-string), -- respecting nested {{...}} so a template argument that -- itself contains braces doesn't break the search. Returns -- the inner content (everything after the first "|") or nil -- if no such template call is found. local function findTemplateCall(text, namePattern) local searchPattern = "{{%s*" .. namePattern .. "%s*|" local matchStart, matchEnd = mw.ustring.find(text, searchPattern) if not matchStart then return nil end local contentStart = matchEnd + 1 local depth = 1 local i = contentStart local len = mw.ustring.len(text) while i <= len do local two = mw.ustring.sub(text, i, i + 1) if two == "{{" then depth = depth + 1 i = i + 2 elseif two == "}}" then depth = depth - 1 i = i + 2 if depth == 0 then local contentEnd = i - 3 return mw.ustring.sub(text, contentStart, contentEnd) end else i = i + 1 end end return nil end -- Pulls any <ref>...</ref> (or self-closing <ref .../>) tags -- out of text, returning the text with them removed plus the -- extracted ref markup (already-valid <ref> tags, ready to -- use as-is - not to be re-wrapped). Returns (text, nil) if -- none are found. local function extractReferences(text) if not text then return text, nil end local refs = {} local cleaned = mw.ustring.gsub(text, "<ref[^>]*>.-</ref>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.ustring.gsub(cleaned, "<ref[^>]*/>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.text.trim(cleaned) if #refs == 0 then return cleaned, nil end return cleaned, table.concat(refs) end local function countHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local segments = splitTopLevel(inner, "|") local count = 0 for _, segment in ipairs(segments) do local trimmedSegment = mw.text.trim(segment) -- Skip named parameters (class=, style=, indent=, etc.) -- rather than counting them as list items. if trimmedSegment ~= "" and not mw.ustring.find(trimmedSegment, "^[%w_%- ]+=") then count = count + 1 end end return count end -- Count of items in a manually-entered language/list field, -- used to decide between a singular ("çhengey") and plural -- ("çhengaghyn") label. Wikidata-derived lists are counted -- exactly (see getLanguageData). Handles the {{hlist}} family -- (searched for anywhere in the text, not just as the entire -- value, since editors often append a trailing <ref> after -- the closing "}}") most legacy articles already use; -- otherwise falls back to a plain comma-count heuristic. local function countListItems(text) if not text or text == "" then return 0 end local hlistCount = countHlistItems(text) if hlistCount then return hlistCount end local count = 0 for _ in mw.text.gsplit(text, ",", true) do count = count + 1 end return count end -- Resolves one language tier from its raw manual parameter: -- strips out any inline <ref> tags (used as-is, since they're -- already valid markup), counts the list on the ref-stripped -- text, then re-appends the extracted ref(s) and/or a manual -- imraa_ reference (which - unlike an inline <ref> - is raw -- citation text that still needs wrapping) to the display value. local function wrapInWikilink(text) -- If already has wikilink syntax, don't double-wrap if mw.ustring.find(text, "%[%[") then return text end -- Otherwise wrap in wikilink return '[[' .. text .. '|' .. text .. ']]' end local function buildLanguageValue(raw, manualReference) if not raw or mw.ustring.lower(mw.text.trim(raw)) == "none" then return nil, 0 end local cleaned, inlineRefs = extractReferences(raw) local count = countListItems(cleaned) -- Try to extract from hlist template first local languageNames = extractHlistItems(cleaned) -- If not in hlist format, split by comma if not languageNames then languageNames = {} for part in mw.text.gsplit(cleaned, ",", true) do local trimmed = mw.text.trim(part) if trimmed ~= "" then table.insert(languageNames, trimmed) end end end -- Sort alphabetically with Manx collation table.sort(languageNames, manxSort) -- Wrap each in wikilink and build hlist local parts = {} for _, name in ipairs(languageNames) do table.insert(parts, '[[' .. name .. '|' .. name .. ']]') end local display = '<div class="hlist">' .. table.concat(parts, '&nbsp;· ') .. '</div>' if inlineRefs then display = display .. inlineRefs end if manualReference then display = display .. "<ref>" .. manualReference .. "</ref>" end return display, count end local function getLanguageData(args) local officialRaw = getManual(args, { "çhengaghyn_oikoil", "çhengey_oikoil" }) local officialReference = getManual(args, { "imraa_çhengaghyn_oikoil", "imraa_çhengey_oikoil" }) local regionalRaw = getManual(args, { "çhengaghyn_ardjynagh", "çhengey_ardjynagh" }) local regionalReference = getManual(args, { "imraa_çhengaghyn_ardjynagh", "imraa_çhengey_ardjynagh" }) local minorityRaw = getManual(args, { "mynçhengaghyn", "mynçhengey" }) local minorityReference = getManual(args, { "imraa_mynçhengaghyn", "imraa_mynçhengey" }) local otherRaw = getManual(args, { "çhengaghyn", "çhengey" }) local otherReference = getManual(args, { "imraa_çhengaghyn", "imraa_çhengey" }) local otherLabel = getManual(args, { "sorçh_çhengaghyn" }) local result = { otherLabel = otherLabel } result.official, result.officialCount = buildLanguageValue(officialRaw, officialReference) result.regional, result.regionalCount = buildLanguageValue(regionalRaw, regionalReference) result.minority, result.minorityCount = buildLanguageValue(minorityRaw, minorityReference) result.other, result.otherCount = buildLanguageValue(otherRaw, otherReference) -- Only reach for Wikidata if none of the three tiers -- were set manually - a manual "none" or partial set -- of overrides always wins over the auto-fetch. if not result.official and not result.regional and not result.minority then local classified = classifyLanguages(getLanguagesFromWikidata()) result.official = joinLanguageList(classified.official) result.officialCount = #classified.official result.regional = joinLanguageList(classified.regional) result.regionalCount = #classified.regional result.minority = joinLanguageList(classified.minority) result.minorityCount = #classified.minority end return result end local function buildLanguageRows(args) local data = getLanguageData(args) local rows = {} if data.official then local officialLabel = data.officialCount > 1 and "[[Çhengey oikoil|Çhengaghyn oikoil]]" or "[[Çhengey oikoil]]" local officialRow = '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. officialLabel .. '</th><td style="vertical-align:top;">' .. data.official .. '</td></tr>' if data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn&nbsp;ardjynagh er&nbsp;enney" or "Çhengey&nbsp;ardjynagh er&nbsp;enney" officialRow = officialRow .. '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:normal;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th>' .. '<td style="vertical-align:top;">' .. data.regional .. '</td></tr>' end table.insert(rows, officialRow) elseif data.regional then -- Regional recognised even without a separate -- official-language statement. local regionalLabel = data.regionalCount > 1 and "Çhengaghyn ardjynagh er enney" or "Çhengey ardjynagh er enney" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th><td style="vertical-align:top;">' .. data.regional .. '</td></tr>' ) end if data.minority then local minorityLabel = data.minorityCount > 1 and "[[Mynçhengey|Mynçhengaghyn]]" or "[[Mynçhengey]]" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. minorityLabel .. '</th><td style="vertical-align:top;">' .. data.minority .. '</td></tr>' ) end if data.other then local otherLabel = data.otherLabel or (data.otherCount > 1 and "Çhengaghyn" or "Çhengey") table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. otherLabel .. '</th><td style="vertical-align:top;">' .. data.other .. '</td></tr>' ) end if #rows == 0 then return nil end return table.concat(rows) end function p.languages(frame) local args = getArgs(frame) return buildLanguageRows(args) end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCityEntityFromTitle(value) local title = normaliseCityName(value) if title == "" then return nil end local entityId = mw.wikibase.getEntityIdForTitle(title) if not entityId then return nil end return mw.wikibase.getEntity(entityId) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end -- Extract custom note parameter local note = getManual(args, {"noteyn_preeu-valley"}) if capital then return { text = capital, entity = getCityEntityFromTitle(capital), reference = nil, note = note } end local entity, statement = getWikidataItem("P36") if entity then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or entity:getLabel(), entity = entity, reference = getWikidataReference(statement), note = nil -- Wikidata items don't have manual wiki notes } end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end -- Extract custom note parameter local note = getManual(args, {"noteyn_ynnyd_reiragh"}) if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil, note = note } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end -- Extract custom note parameter local note = getManual(args, {"noteyn_balley_smoo"}) if city then return { text = city, entity = getCityEntityFromTitle(city), reference = nil, note = note } end local country = mw.wikibase.getEntityObject() if not country then return nil end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id local target = mw.wikibase.getEntity(targetId) if target and not isDisambiguationPage(target) then local sitelink = target:getSitelink("gvwiki") return { text = sitelink or target:getLabel(), entity = target, reference = getWikidataReference(statement), note = nil } end end end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then return { text = city, entity = getCityEntityFromTitle(city), reference = nil } end local country = mw.wikibase.getEntityObject() if not country then return nil end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id local target = mw.wikibase.getEntity(targetId) if target and not isDisambiguationPage(target) then local sitelink = target:getSitelink("gvwiki") return { text = sitelink or target:getLabel(), entity = target, reference = getWikidataReference(statement) } end end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) return { capital = getCapitalData(args), administrative = getAdministrativeCentreData(args), largest = getLargestCityData(args), labels = getCityLabels(args) } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end local title = nil if city.entity then title = city.entity:getSitelink("gvwiki") end if not title or title == "" then title = normaliseCityName(city.text) end if not title or title == "" then return "" end return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest -- Helper function to render the data chunk cleanly local function renderCityCell(cityObj) local text = makeCityLink(cityObj) -- Append the efn footnote tag if it exists if cityObj.note and cityObj.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { cityObj.note } } text = text .. efnOut end -- Append standard reference citations if cityObj.reference then text = text .. cityObj.reference end -- Append coordinates block on a new line below the name if cityObj.entity then local coordinates = makeCoordinates(cityObj.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text end if capital then return renderCityCell(capital) elseif administrative then return renderCityCell(administrative) elseif largest then return renderCityCell(largest) end return nil end function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} local function formatLegacyRow(label, cityObj) local text = makeCityLink(cityObj) if cityObj.note and cityObj.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { cityObj.note } } text = text .. efnOut end if cityObj.reference then text = text .. cityObj.reference end if cityObj.entity then local coordinates = makeCoordinates(cityObj.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end return "'''" .. label .. "''': " .. text end if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end table.insert(rows, formatLegacyRow(label, capital)) end if administrative then local label = labels.administrative or "Ynnyd reiragh" table.insert(rows, formatLegacyRow(label, administrative)) end if largest then table.insert(rows, formatLegacyRow("Balley smoo", largest)) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -------------------------------------------------- -- HEADER -------------------------------------------------- do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -------------------------------------------------- -- FLAG / ARMS -------------------------------------------------- do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -------------------------------------------------- -- MOTTO / ANTHEM -------------------------------------------------- do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -------------------------------------------------- -- CAPITAL / ADMINISTRATIVE CENTRE / LARGEST CITY -------------------------------------------------- do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels -- Add one divider before the city section only. if capital or administrative or largest then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '"></td></tr>' ) end -- Capital if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Administrative centre if administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Largest city if largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- do local languageRows = buildLanguageRows(args) if languageRows then table.insert(rows, languageRows) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p ogeunq82hfkk8vtxip76u78xqypfsyc 392894 392893 2026-09-07T01:52:15Z MacTire02 219 +noteyn da ny chengaghyn 392894 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -- Extract items from an hlist/flatlist/ubl template local function extractHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local items = {} local segments = splitTopLevel(inner, "|") for _, segment in ipairs(segments) do local trimmed = mw.text.trim(segment) -- Skip named parameters (class=, style=, etc.) if trimmed ~= "" and not mw.ustring.find(trimmed, "^[%w_%- ]+=") then -- Extract just the link text if it's a wikilink local linkText = mw.ustring.match(trimmed, "%[%[.-|(.+)%]%]") or mw.ustring.match(trimmed, "%[%[(.+)%]%]") or trimmed table.insert(items, mw.text.trim(linkText)) end end return items end -------------------------------------------------- -- DISAMBIGUATION GUARD -------------------------------------------------- -- Some Wikidata statements resolve to a general/ambiguous -- item rather than the specific thing we want (e.g. a -- country's "most populous urban area" pointing at the -- ambiguous "New York" (Q22654) instead of "New York City" -- (Q60)). Skip anything flagged as a disambiguation page. local function isDisambiguationPage(entity) if not entity then return false end local statements = entity:getBestStatements("P31") if not statements then return false end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" and mainsnak.datavalue.value.id == "Q4167410" then return true end end return false end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity and not isDisambiguationPage(linkedEntity) then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- FLAG BORDER CHECK -------------------------------------------------- -- List of countries with non-rectangular flags (no border needed) local NON_RECTANGULAR_FLAGS = { ["Flag of Nepal.svg"] = true, ["Flag of Ohio.svg"] = true, ["Flag of Switzerland.svg"] = true, } -- Check if a flag needs a border local function needsFlagBorder(flagFile) if not flagFile then return true end if NON_RECTANGULAR_FLAGS[flagFile] then return false end local lowerFile = mw.ustring.lower(flagFile) if mw.ustring.find(lowerFile, "nepal") then return false end return true end -------------------------------------------------- -- MULTI-FLAG SUPPORT -------------------------------------------------- local function getFlagData(args) -- Get primary flag local flag = getManual(args, {"jalloo_brattagh"}) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end -- Get second flag (if any) local flag2 = getManual(args, {"jalloo_brattagh_2", "jalloo_brattagh_elley"}) if flag2 and mw.ustring.lower(flag2) == "none" then flag2 = nil elseif not flag2 then flag2 = getWikidataImage("P163") end -- Get arms local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end -- Get second arms (if any) local arms2 = getManual(args, { "jalloo_armys_2", "jalloo_cleinney_2" }) if arms2 and mw.ustring.lower(arms2) == "none" then arms2 = nil elseif not arms2 then arms2 = getWikidataImage("P237") end if not flag and not flag2 and not arms and not arms2 then return nil end local name = getCountryGenitive(args) or "" local data = { flags = {}, armses = {} } -- Primary flag if flag then local flagWidth = getManual(args, {"lheead_brattagh"}) or "125px" local hasBorder = needsFlagBorder(flag) table.insert(data.flags, { image = flag, width = flagWidth, hasBorder = hasBorder, link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh"}) or "Brattagh", isPrimary = true }) end -- Second flag if flag2 then local flag2Width = getManual(args, {"lheead_brattagh_2", "lheead_brattagh"}) or "100px" local hasBorder2 = needsFlagBorder(flag2) table.insert(data.flags, { image = flag2, width = flag2Width, hasBorder = hasBorder2, link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh_2"}) or "Brattagh elley", isPrimary = false }) end -- Primary arms if arms then local kind = getManual(args, {"art_sorçh_cowrey"}) or getManual(args, {"sorçh_cowrey"}) or "Armys" table.insert(data.armses, { image = arms, width = getManual(args, {"lheead_armys", "lheead_cleinney", "lheead_cowrey"}) or "85px", link = kind .. " " .. name, label = getManual(args, {"sorçh_cowrey"}) or "Armys", isPrimary = true }) end -- Second arms if arms2 then table.insert(data.armses, { image = arms2, width = getManual(args, {"lheead_armys_2", "lheead_cleinney_2"}) or "85px", link = "Armys " .. name, label = getManual(args, {"sorçh_cowrey_2"}) or "Armys", isPrimary = false }) end return data end -------------------------------------------------- -- UPDATED getFlagArmsData (replaces old function) -------------------------------------------------- local function getFlagArmsData(args) return getFlagData(args) end -------------------------------------------------- -- FLAG / ARMS BLOCK (UPDATED) -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} local hasFlags = #data.flags > 0 local hasArms = #data.armses > 0 -- Build flag column if hasFlags then local flagContent = {} for i, flagData in ipairs(data.flags) do local borderStyle = "" if flagData.hasBorder then borderStyle = '|style="border:1px solid #a2a9b1;"' end local flagImage = '[[Coadan:' .. flagData.image .. '|' .. flagData.width .. borderStyle .. ']]' table.insert(flagContent, flagImage) end local combinedFlags = table.concat(flagContent, '<br/>') table.insert(imageCells, '<td align="center" style="' .. (hasArms and "width:58%; " or "width:100%; ") .. 'vertical-align:middle;">' .. combinedFlags .. '</td>' ) local flagCaptions = {} for i, flagData in ipairs(data.flags) do table.insert(flagCaptions, '<small>[[' .. flagData.link .. '|' .. flagData.label .. ']]</small>' ) end table.insert(captionCells, '<td align="center">' .. table.concat(flagCaptions, '<br/>') .. '</td>' ) end -- Build arms column if hasArms then local armsContent = {} for i, armsData in ipairs(data.armses) do local armsImage = '[[Coadan:' .. armsData.image .. '|' .. armsData.width .. ']]' table.insert(armsContent, armsImage) end local combinedArms = table.concat(armsContent, '<br/>') table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">' .. combinedArms .. '</td>' ) local armsCaptions = {} for i, armsData in ipairs(data.armses) do table.insert(armsCaptions, '<small>[[' .. armsData.link .. '|' .. armsData.label .. ']]</small>' ) end table.insert(captionCells, '<td align="center">' .. table.concat(armsCaptions, '<br/>') .. '</td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = '"' .. motto .. '"', reference = reference and "<ref>" .. reference .. "</ref>" or nil } end local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = '"' .. value.text .. '"', reference = getWikidataReference(statement) } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, {"arrane_ashoonagh"}) local royal = getManual(args, {"arrane_reeoil"}) local other = getManual(args, {"arrane"}) local nationalReference = getManual(args, {"imraa_arrane_ashoonagh"}) local royalReference = getManual(args, {"imraa_arrane_reeoil"}) local otherReference = getManual(args, {"imraa_arrane"}) -- Updated to your preferred parameter nomenclature local nationalAudio = getManual(args, {"coadan_arrane_ashoonagh"}) local royalAudio = getManual(args, {"coadan_arrane_reeoil"}) local otherAudio = getManual(args, {"coadan_arrane"}) -- Updated to match the requested noteyn_ prefix pattern local nationalNote = getManual(args, {"noteyn_arrane_ashoonagh"}) local royalNote = getManual(args, {"noteyn_arrane_reeoil"}) local otherNote = getManual(args, {"noteyn_arrane"}) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and ("<ref>" .. nationalReference .. "</ref>") or nil, audio = nationalAudio, note = nationalNote } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and ("<ref>" .. royalReference .. "</ref>") or nil, audio = royalAudio, note = royalNote } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and ("<ref>" .. otherReference .. "</ref>") or nil, audio = otherAudio, note = otherNote } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local text = motto.text if motto.reference then text = text .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. text) end -- Helper to format anthem rows safely local function formatAnthemRow(label, anthemObj) if not anthemObj or not anthemObj.text then return nil end local cleanText = anthemObj.text cleanText = mw.ustring.gsub(cleanText, '^"+', '') cleanText = mw.ustring.gsub(cleanText, '"+$', '') if not mw.ustring.find(cleanText, "%[%[") then cleanText = '[[' .. cleanText .. '|' .. cleanText .. ']]' end local display = '"' .. cleanText .. '"' -- Append the efn note directly after the text string if anthemObj.note and anthemObj.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { anthemObj.note } } display = display .. efnOut end -- Append any manual citation strings right after the footnote marker if anthemObj.reference then display = display .. anthemObj.reference end if anthemObj.audio and anthemObj.audio ~= "" then display = display .. '<br/><div style="text-align:center; margin-top:0.2em;">[[Coadan:' .. anthemObj.audio .. '|center]]</div>' end return "'''" .. label .. ":&nbsp;'''" .. display end local nationalRow = formatAnthemRow("[[Arrane ashoonagh]]", anthems.national) if nationalRow then table.insert(rows, nationalRow) end local otherRow = formatAnthemRow("Anthym", anthems.other) if otherRow then table.insert(rows, otherRow) end local royalRow = formatAnthemRow("[[Arrane reeoil]]", anthems.royal) if royalRow then table.insert(rows, royalRow) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- local function getLanguagesFromWikidata() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P37") if not statements or #statements == 0 then return {} end local languages = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local langEntity = mw.wikibase.getEntity(id) if langEntity then local label = langEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(languages, { text = label, role = role, reference = getWikidataReference(statement) }) end end end end return languages end local function classifyLanguages(languages) local result = { official = {}, regional = {}, minority = {} } for _, language in ipairs(languages) do local role = language.role or "" local lowerRole = mw.ustring.lower(role) if mw.ustring.find(lowerRole, "minority") then table.insert(result.minority, language) elseif mw.ustring.find(lowerRole, "regional") then table.insert(result.regional, language) else table.insert(result.official, language) end end return result end -- Manx-specific collation: çh sorts as ch local function manxSort(a, b) local function normalize(text) -- Replace çh with ch for sorting purposes text = mw.ustring.lower(text) text = mw.ustring.gsub(text, "çh", "ch") return text end return normalize(a) < normalize(b) end local function joinLanguageList(languages) if not languages or #languages == 0 then return nil end -- Sort languages alphabetically with Manx collation table.sort(languages, function(a, b) return manxSort(a.text, b.text) end) local parts = {} for _, language in ipairs(languages) do local text = language.text -- Wrap language name in a wikilink (even if redlinked) text = '[[' .. text .. '|' .. text .. ']]' if language.reference then text = text .. language.reference end table.insert(parts, text) end if #parts == 0 then return nil end -- Return as hlist format return '<div class="hlist">' .. table.concat(parts, '&nbsp;· ') .. '</div>' end -- Splits text on a top-level separator character, without -- splitting inside {{...}} or [[...]] (so a piped wikilink -- like [[Country|Display]], or a nested template, doesn't -- get miscounted as two items). local function splitTopLevel(text, sep) local parts = {} local current = {} local depthCurly = 0 local depthSquare = 0 local len = mw.ustring.len(text) local i = 1 while i <= len do local two = mw.ustring.sub(text, i, i + 1) local one = mw.ustring.sub(text, i, i) if two == "{{" then depthCurly = depthCurly + 1 table.insert(current, two) i = i + 2 elseif two == "}}" and depthCurly > 0 then depthCurly = depthCurly - 1 table.insert(current, two) i = i + 2 elseif two == "[[" then depthSquare = depthSquare + 1 table.insert(current, two) i = i + 2 elseif two == "]]" and depthSquare > 0 then depthSquare = depthSquare - 1 table.insert(current, two) i = i + 2 elseif one == sep and depthCurly == 0 and depthSquare == 0 then table.insert(parts, table.concat(current)) current = {} i = i + 1 else table.insert(current, one) i = i + 1 end end table.insert(parts, table.concat(current)) return parts end -- Counts the items inside a {{hlist|...}}/{{flatlist|...}}/ -- {{ubl|...}}/{{unbulleted list|...}} template call (the -- convention most legacy articles already use for this -- field). Returns nil if the text isn't one of these, so -- the caller can fall back to a plain heuristic. -- Finds the first call to a template matching namePattern -- anywhere in text (not just at the start/whole-string), -- respecting nested {{...}} so a template argument that -- itself contains braces doesn't break the search. Returns -- the inner content (everything after the first "|") or nil -- if no such template call is found. local function findTemplateCall(text, namePattern) local searchPattern = "{{%s*" .. namePattern .. "%s*|" local matchStart, matchEnd = mw.ustring.find(text, searchPattern) if not matchStart then return nil end local contentStart = matchEnd + 1 local depth = 1 local i = contentStart local len = mw.ustring.len(text) while i <= len do local two = mw.ustring.sub(text, i, i + 1) if two == "{{" then depth = depth + 1 i = i + 2 elseif two == "}}" then depth = depth - 1 i = i + 2 if depth == 0 then local contentEnd = i - 3 return mw.ustring.sub(text, contentStart, contentEnd) end else i = i + 1 end end return nil end -- Pulls any <ref>...</ref> (or self-closing <ref .../>) tags -- out of text, returning the text with them removed plus the -- extracted ref markup (already-valid <ref> tags, ready to -- use as-is - not to be re-wrapped). Returns (text, nil) if -- none are found. local function extractReferences(text) if not text then return text, nil end local refs = {} local cleaned = mw.ustring.gsub(text, "<ref[^>]*>.-</ref>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.ustring.gsub(cleaned, "<ref[^>]*/>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.text.trim(cleaned) if #refs == 0 then return cleaned, nil end return cleaned, table.concat(refs) end local function countHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local segments = splitTopLevel(inner, "|") local count = 0 for _, segment in ipairs(segments) do local trimmedSegment = mw.text.trim(segment) -- Skip named parameters (class=, style=, indent=, etc.) -- rather than counting them as list items. if trimmedSegment ~= "" and not mw.ustring.find(trimmedSegment, "^[%w_%- ]+=") then count = count + 1 end end return count end -- Count of items in a manually-entered language/list field, -- used to decide between a singular ("çhengey") and plural -- ("çhengaghyn") label. Wikidata-derived lists are counted -- exactly (see getLanguageData). Handles the {{hlist}} family -- (searched for anywhere in the text, not just as the entire -- value, since editors often append a trailing <ref> after -- the closing "}}") most legacy articles already use; -- otherwise falls back to a plain comma-count heuristic. local function countListItems(text) if not text or text == "" then return 0 end local hlistCount = countHlistItems(text) if hlistCount then return hlistCount end local count = 0 for _ in mw.text.gsplit(text, ",", true) do count = count + 1 end return count end -- Resolves one language tier from its raw manual parameter: -- strips out any inline <ref> tags (used as-is, since they're -- already valid markup), counts the list on the ref-stripped -- text, then re-appends the extracted ref(s) and/or a manual -- imraa_ reference (which - unlike an inline <ref> - is raw -- citation text that still needs wrapping) to the display value. local function wrapInWikilink(text) -- If already has wikilink syntax, don't double-wrap if mw.ustring.find(text, "%[%[") then return text end -- Otherwise wrap in wikilink return '[[' .. text .. '|' .. text .. ']]' end -- Resolves one language tier from its raw manual parameter: -- strips out any inline <ref> tags, extracts/sorts the items, -- expands an {{efn}} note if provided, and appends reference strings. local function buildLanguageValue(raw, manualReference, manualNote, frame) if not raw or mw.ustring.lower(mw.text.trim(raw)) == "none" then return nil, 0 end local cleaned, inlineRefs = extractReferences(raw) local count = countListItems(cleaned) -- Try to extract from hlist template first local languageNames = extractHlistItems(cleaned) -- If not in hlist format, split by comma if not languageNames then languageNames = {} for part in mw.text.gsplit(cleaned, ",", true) do local trimmed = mw.text.trim(part) if trimmed ~= "" then table.insert(languageNames, trimmed) end end end -- Sort alphabetically with Manx collation table.sort(languageNames, manxSort) -- Wrap each in a wikilink and build hlist layout local parts = {} for _, name in ipairs(languageNames) do table.insert(parts, '[[' .. name .. '|' .. name .. ']]') end local display = '<div class="hlist">' .. table.concat(parts, '&nbsp;· ') .. '</div>' -- 1. Append the efn note directly after the language hlist block if provided if manualNote and manualNote ~= "" and frame then local efnOut = frame:expandTemplate{ title = "efn", args = { manualNote } } display = display .. efnOut end -- 2. Append standard citation references if inlineRefs then display = display .. inlineRefs end if manualReference then display = display .. "<ref>" .. manualReference .. "</ref>" end return display, count end local function getLanguageData(args, frame) local officialRaw = getManual(args, { "çhengaghyn_oikoil", "çhengey_oikoil" }) local officialReference = getManual(args, { "imraa_çhengaghyn_oikoil", "imraa_çhengey_oikoil" }) local regionalRaw = getManual(args, { "çhengaghyn_ardjynagh", "çhengey_ardjynagh" }) local regionalReference = getManual(args, { "imraa_çhengaghyn_ardjynagh", "imraa_çhengey_ardjynagh" }) local minorityRaw = getManual(args, { "mynçhengaghyn", "mynçhengey" }) local minorityReference = getManual(args, { "imraa_mynçhengaghyn", "imraa_mynçhengey" }) local otherRaw = getManual(args, { "çhengaghyn", "çhengey" }) local otherReference = getManual(args, { "imraa_çhengaghyn", "imraa_çhengey" }) local otherLabel = getManual(args, { "sorçh_çhengaghyn" }) -- Extract the new custom noteyn_ parameters local officialNote = getManual(args, {"noteyn_çhengaghyn_oikoil", "noteyn_çhengey_oikoil"}) local regionalNote = getManual(args, {"noteyn_çhengaghyn_ardjynagh", "noteyn_çhengey_ardjynagh"}) local minorityNote = getManual(args, {"noteyn_mynçhengaghyn", "noteyn_mynçhengey"}) local otherNote = getManual(args, {"noteyn_çhengaghyn", "noteyn_çhengey"}) local result = { otherLabel = otherLabel } -- Pass parameters down to buildLanguageValue along with frame context result.official, result.officialCount = buildLanguageValue(officialRaw, officialReference, officialNote, frame) result.regional, result.regionalCount = buildLanguageValue(regionalRaw, regionalReference, regionalNote, frame) result.minority, result.minorityCount = buildLanguageValue(minorityRaw, minorityReference, minorityNote, frame) result.other, result.otherCount = buildLanguageValue(otherRaw, otherReference, otherNote, frame) -- Only reach for Wikidata if none of the three primary tiers were set manually if not result.official and not result.regional and not result.minority then local classified = classifyLanguages(getLanguagesFromWikidata()) result.official = joinLanguageList(classified.official) result.officialCount = #classified.official result.regional = joinLanguageList(classified.regional) result.regionalCount = #classified.regional result.minority = joinLanguageList(classified.minority) result.minorityCount = #classified.minority end return result end local function buildLanguageRows(args, frame) -- Pass the frame execution reference through local data = getLanguageData(args, frame) local rows = {} if data.official then local officialLabel = data.officialCount > 1 and "[[Çhengey oikoil|Çhengaghyn oikoil]]" or "[[Çhengey oikoil]]" local officialRow = '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. officialLabel .. '</th><td style="vertical-align:top;">' .. data.official .. '</td></tr>' if data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn&nbsp;ardjynagh er&nbsp;enney" or "Çhengey&nbsp;ardjynagh er&nbsp;enney" officialRow = officialRow .. '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:normal;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th>' .. '<td style="vertical-align:top;">' .. data.regional .. '</td></tr>' end table.insert(rows, officialRow) elseif data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn ardjynagh er enney" or "Çhengey ardjynagh er enney" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th><td style="vertical-align:top;">' .. data.regional .. '</td></tr>' ) end if data.minority then local minorityLabel = data.minorityCount > 1 and "[[Mynçhengey|Mynçhengaghyn]]" or "[[Mynçhengey]]" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. minorityLabel .. '</th><td style="vertical-align:top;">' .. data.minority .. '</td></tr>' ) end if data.other then local otherLabel = data.otherLabel or (data.otherCount > 1 and "Çhengaghyn" or "Çhengey") table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. otherLabel .. '</th><td style="vertical-align:top;">' .. data.other .. '</td></tr>' ) end if #rows == 0 then return nil end return table.concat(rows) end function p.languages(frame) local args = getArgs(frame) -- Updated to pass frame context downward cleanly return buildLanguageRows(args, frame) end local function getLanguageData(args) local officialRaw = getManual(args, { "çhengaghyn_oikoil", "çhengey_oikoil" }) local officialReference = getManual(args, { "imraa_çhengaghyn_oikoil", "imraa_çhengey_oikoil" }) local regionalRaw = getManual(args, { "çhengaghyn_ardjynagh", "çhengey_ardjynagh" }) local regionalReference = getManual(args, { "imraa_çhengaghyn_ardjynagh", "imraa_çhengey_ardjynagh" }) local minorityRaw = getManual(args, { "mynçhengaghyn", "mynçhengey" }) local minorityReference = getManual(args, { "imraa_mynçhengaghyn", "imraa_mynçhengey" }) local otherRaw = getManual(args, { "çhengaghyn", "çhengey" }) local otherReference = getManual(args, { "imraa_çhengaghyn", "imraa_çhengey" }) local otherLabel = getManual(args, { "sorçh_çhengaghyn" }) local result = { otherLabel = otherLabel } result.official, result.officialCount = buildLanguageValue(officialRaw, officialReference) result.regional, result.regionalCount = buildLanguageValue(regionalRaw, regionalReference) result.minority, result.minorityCount = buildLanguageValue(minorityRaw, minorityReference) result.other, result.otherCount = buildLanguageValue(otherRaw, otherReference) -- Only reach for Wikidata if none of the three tiers -- were set manually - a manual "none" or partial set -- of overrides always wins over the auto-fetch. if not result.official and not result.regional and not result.minority then local classified = classifyLanguages(getLanguagesFromWikidata()) result.official = joinLanguageList(classified.official) result.officialCount = #classified.official result.regional = joinLanguageList(classified.regional) result.regionalCount = #classified.regional result.minority = joinLanguageList(classified.minority) result.minorityCount = #classified.minority end return result end local function buildLanguageRows(args) local data = getLanguageData(args) local rows = {} if data.official then local officialLabel = data.officialCount > 1 and "[[Çhengey oikoil|Çhengaghyn oikoil]]" or "[[Çhengey oikoil]]" local officialRow = '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. officialLabel .. '</th><td style="vertical-align:top;">' .. data.official .. '</td></tr>' if data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn&nbsp;ardjynagh er&nbsp;enney" or "Çhengey&nbsp;ardjynagh er&nbsp;enney" officialRow = officialRow .. '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:normal;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th>' .. '<td style="vertical-align:top;">' .. data.regional .. '</td></tr>' end table.insert(rows, officialRow) elseif data.regional then -- Regional recognised even without a separate -- official-language statement. local regionalLabel = data.regionalCount > 1 and "Çhengaghyn ardjynagh er enney" or "Çhengey ardjynagh er enney" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th><td style="vertical-align:top;">' .. data.regional .. '</td></tr>' ) end if data.minority then local minorityLabel = data.minorityCount > 1 and "[[Mynçhengey|Mynçhengaghyn]]" or "[[Mynçhengey]]" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. minorityLabel .. '</th><td style="vertical-align:top;">' .. data.minority .. '</td></tr>' ) end if data.other then local otherLabel = data.otherLabel or (data.otherCount > 1 and "Çhengaghyn" or "Çhengey") table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. otherLabel .. '</th><td style="vertical-align:top;">' .. data.other .. '</td></tr>' ) end if #rows == 0 then return nil end return table.concat(rows) end function p.languages(frame) local args = getArgs(frame) return buildLanguageRows(args) end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCityEntityFromTitle(value) local title = normaliseCityName(value) if title == "" then return nil end local entityId = mw.wikibase.getEntityIdForTitle(title) if not entityId then return nil end return mw.wikibase.getEntity(entityId) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end -- Extract custom note parameter local note = getManual(args, {"noteyn_preeu-valley"}) if capital then return { text = capital, entity = getCityEntityFromTitle(capital), reference = nil, note = note } end local entity, statement = getWikidataItem("P36") if entity then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or entity:getLabel(), entity = entity, reference = getWikidataReference(statement), note = nil -- Wikidata items don't have manual wiki notes } end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end -- Extract custom note parameter local note = getManual(args, {"noteyn_ynnyd_reiragh"}) if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil, note = note } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end -- Extract custom note parameter local note = getManual(args, {"noteyn_balley_smoo"}) if city then return { text = city, entity = getCityEntityFromTitle(city), reference = nil, note = note } end local country = mw.wikibase.getEntityObject() if not country then return nil end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id local target = mw.wikibase.getEntity(targetId) if target and not isDisambiguationPage(target) then local sitelink = target:getSitelink("gvwiki") return { text = sitelink or target:getLabel(), entity = target, reference = getWikidataReference(statement), note = nil } end end end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then return { text = city, entity = getCityEntityFromTitle(city), reference = nil } end local country = mw.wikibase.getEntityObject() if not country then return nil end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id local target = mw.wikibase.getEntity(targetId) if target and not isDisambiguationPage(target) then local sitelink = target:getSitelink("gvwiki") return { text = sitelink or target:getLabel(), entity = target, reference = getWikidataReference(statement) } end end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) return { capital = getCapitalData(args), administrative = getAdministrativeCentreData(args), largest = getLargestCityData(args), labels = getCityLabels(args) } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end local title = nil if city.entity then title = city.entity:getSitelink("gvwiki") end if not title or title == "" then title = normaliseCityName(city.text) end if not title or title == "" then return "" end return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest -- Helper function to render the data chunk cleanly local function renderCityCell(cityObj) local text = makeCityLink(cityObj) -- Append the efn footnote tag if it exists if cityObj.note and cityObj.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { cityObj.note } } text = text .. efnOut end -- Append standard reference citations if cityObj.reference then text = text .. cityObj.reference end -- Append coordinates block on a new line below the name if cityObj.entity then local coordinates = makeCoordinates(cityObj.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text end if capital then return renderCityCell(capital) elseif administrative then return renderCityCell(administrative) elseif largest then return renderCityCell(largest) end return nil end function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} local function formatLegacyRow(label, cityObj) local text = makeCityLink(cityObj) if cityObj.note and cityObj.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { cityObj.note } } text = text .. efnOut end if cityObj.reference then text = text .. cityObj.reference end if cityObj.entity then local coordinates = makeCoordinates(cityObj.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end return "'''" .. label .. "''': " .. text end if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end table.insert(rows, formatLegacyRow(label, capital)) end if administrative then local label = labels.administrative or "Ynnyd reiragh" table.insert(rows, formatLegacyRow(label, administrative)) end if largest then table.insert(rows, formatLegacyRow("Balley smoo", largest)) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -------------------------------------------------- -- HEADER -------------------------------------------------- do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -------------------------------------------------- -- FLAG / ARMS -------------------------------------------------- do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -------------------------------------------------- -- MOTTO / ANTHEM -------------------------------------------------- do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -------------------------------------------------- -- CAPITAL / ADMINISTRATIVE CENTRE / LARGEST CITY -------------------------------------------------- do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels -- Add one divider before the city section only. if capital or administrative or largest then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '"></td></tr>' ) end -- Capital if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Administrative centre if administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Largest city if largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- do local languageRows = buildLanguageRows(args) if languageRows then table.insert(rows, languageRows) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p ar173ytbmddpptd2ydb553toulspakq 392895 392894 2026-09-07T02:04:15Z MacTire02 219 +chyndaaghyn as tessen-lettyraghey 392895 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -- Extract items from an hlist/flatlist/ubl template local function extractHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local items = {} local segments = splitTopLevel(inner, "|") for _, segment in ipairs(segments) do local trimmed = mw.text.trim(segment) -- Skip named parameters (class=, style=, etc.) if trimmed ~= "" and not mw.ustring.find(trimmed, "^[%w_%- ]+=") then -- Extract just the link text if it's a wikilink local linkText = mw.ustring.match(trimmed, "%[%[.-|(.+)%]%]") or mw.ustring.match(trimmed, "%[%[(.+)%]%]") or trimmed table.insert(items, mw.text.trim(linkText)) end end return items end -------------------------------------------------- -- DISAMBIGUATION GUARD -------------------------------------------------- -- Some Wikidata statements resolve to a general/ambiguous -- item rather than the specific thing we want (e.g. a -- country's "most populous urban area" pointing at the -- ambiguous "New York" (Q22654) instead of "New York City" -- (Q60)). Skip anything flagged as a disambiguation page. local function isDisambiguationPage(entity) if not entity then return false end local statements = entity:getBestStatements("P31") if not statements then return false end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" and mainsnak.datavalue.value.id == "Q4167410" then return true end end return false end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity and not isDisambiguationPage(linkedEntity) then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- FLAG BORDER CHECK -------------------------------------------------- -- List of countries with non-rectangular flags (no border needed) local NON_RECTANGULAR_FLAGS = { ["Flag of Nepal.svg"] = true, ["Flag of Ohio.svg"] = true, ["Flag of Switzerland.svg"] = true, } -- Check if a flag needs a border local function needsFlagBorder(flagFile) if not flagFile then return true end if NON_RECTANGULAR_FLAGS[flagFile] then return false end local lowerFile = mw.ustring.lower(flagFile) if mw.ustring.find(lowerFile, "nepal") then return false end return true end -------------------------------------------------- -- MULTI-FLAG SUPPORT -------------------------------------------------- local function getFlagData(args) -- Get primary flag local flag = getManual(args, {"jalloo_brattagh"}) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end -- Get second flag (if any) local flag2 = getManual(args, {"jalloo_brattagh_2", "jalloo_brattagh_elley"}) if flag2 and mw.ustring.lower(flag2) == "none" then flag2 = nil elseif not flag2 then flag2 = getWikidataImage("P163") end -- Get arms local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end -- Get second arms (if any) local arms2 = getManual(args, { "jalloo_armys_2", "jalloo_cleinney_2" }) if arms2 and mw.ustring.lower(arms2) == "none" then arms2 = nil elseif not arms2 then arms2 = getWikidataImage("P237") end if not flag and not flag2 and not arms and not arms2 then return nil end local name = getCountryGenitive(args) or "" local data = { flags = {}, armses = {} } -- Primary flag if flag then local flagWidth = getManual(args, {"lheead_brattagh"}) or "125px" local hasBorder = needsFlagBorder(flag) table.insert(data.flags, { image = flag, width = flagWidth, hasBorder = hasBorder, link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh"}) or "Brattagh", isPrimary = true }) end -- Second flag if flag2 then local flag2Width = getManual(args, {"lheead_brattagh_2", "lheead_brattagh"}) or "100px" local hasBorder2 = needsFlagBorder(flag2) table.insert(data.flags, { image = flag2, width = flag2Width, hasBorder = hasBorder2, link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh_2"}) or "Brattagh elley", isPrimary = false }) end -- Primary arms if arms then local kind = getManual(args, {"art_sorçh_cowrey"}) or getManual(args, {"sorçh_cowrey"}) or "Armys" table.insert(data.armses, { image = arms, width = getManual(args, {"lheead_armys", "lheead_cleinney", "lheead_cowrey"}) or "85px", link = kind .. " " .. name, label = getManual(args, {"sorçh_cowrey"}) or "Armys", isPrimary = true }) end -- Second arms if arms2 then table.insert(data.armses, { image = arms2, width = getManual(args, {"lheead_armys_2", "lheead_cleinney_2"}) or "85px", link = "Armys " .. name, label = getManual(args, {"sorçh_cowrey_2"}) or "Armys", isPrimary = false }) end return data end -------------------------------------------------- -- UPDATED getFlagArmsData (replaces old function) -------------------------------------------------- local function getFlagArmsData(args) return getFlagData(args) end -------------------------------------------------- -- FLAG / ARMS BLOCK (UPDATED) -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} local hasFlags = #data.flags > 0 local hasArms = #data.armses > 0 -- Build flag column if hasFlags then local flagContent = {} for i, flagData in ipairs(data.flags) do local borderStyle = "" if flagData.hasBorder then borderStyle = '|style="border:1px solid #a2a9b1;"' end local flagImage = '[[Coadan:' .. flagData.image .. '|' .. flagData.width .. borderStyle .. ']]' table.insert(flagContent, flagImage) end local combinedFlags = table.concat(flagContent, '<br/>') table.insert(imageCells, '<td align="center" style="' .. (hasArms and "width:58%; " or "width:100%; ") .. 'vertical-align:middle;">' .. combinedFlags .. '</td>' ) local flagCaptions = {} for i, flagData in ipairs(data.flags) do table.insert(flagCaptions, '<small>[[' .. flagData.link .. '|' .. flagData.label .. ']]</small>' ) end table.insert(captionCells, '<td align="center">' .. table.concat(flagCaptions, '<br/>') .. '</td>' ) end -- Build arms column if hasArms then local armsContent = {} for i, armsData in ipairs(data.armses) do local armsImage = '[[Coadan:' .. armsData.image .. '|' .. armsData.width .. ']]' table.insert(armsContent, armsImage) end local combinedArms = table.concat(armsContent, '<br/>') table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">' .. combinedArms .. '</td>' ) local armsCaptions = {} for i, armsData in ipairs(data.armses) do table.insert(armsCaptions, '<small>[[' .. armsData.link .. '|' .. armsData.label .. ']]</small>' ) end table.insert(captionCells, '<td align="center">' .. table.concat(armsCaptions, '<br/>') .. '</td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) -- Accepts both variations with ç and c interchangeably local chyndaa = getManual(args, {"çhyndaa_jarroo_raa", "chyndaa_jarroo_raa"}) local tessenLettyraghey = getManual(args, {"tessen-lettyraghey_jarroo_raa"}) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = motto, reference = reference and "<ref>" .. reference .. "</ref>" or nil, chyndaa = chyndaa, tessenLettyraghey = tessenLettyraghey } end local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = value.text, reference = getWikidataReference(statement), chyndaa = nil, tessenLettyraghey = nil } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthemData(args) local national = getManual(args, {"arrane_ashoonagh"}) local royal = getManual(args, {"arrane_reeoil"}) local other = getManual(args, {"arrane"}) local nationalReference = getManual(args, {"imraa_arrane_ashoonagh"}) local royalReference = getManual(args, {"imraa_arrane_reeoil"}) local otherReference = getManual(args, {"imraa_arrane"}) local nationalAudio = getManual(args, {"coadan_arrane_ashoonagh"}) local royalAudio = getManual(args, {"coadan_arrane_reeoil"}) local otherAudio = getManual(args, {"coadan_arrane"}) local nationalNote = getManual(args, {"noteyn_arrane_ashoonagh"}) local royalNote = getManual(args, {"noteyn_arrane_reeoil"}) local otherNote = getManual(args, {"noteyn_arrane"}) -- Translation parsing checks çhyndaa and chyndaa variants simultaneously local nationalChyndaa = getManual(args, {"çhyndaa_arrane_ashoonagh", "chyndaa_arrane_ashoonagh"}) local royalChyndaa = getManual(args, {"çhyndaa_arrane_reeoil", "chyndaa_arrane_reeoil"}) local otherChyndaa = getManual(args, {"çhyndaa_arrane", "chyndaa_arrane"}) -- Corrected transliteration term mappings local nationalTessen = getManual(args, {"tessen-lettyraghey_arrane_ashoonagh"}) local royalTessen = getManual(args, {"tessen-lettyraghey_arrane_reeoil"}) local otherTessen = getManual(args, {"tessen-lettyraghey_arrane"}) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and ("<ref>" .. nationalReference .. "</ref>") or nil, audio = nationalAudio, note = nationalNote, chyndaa = nationalChyndaa, tessenLettyraghey = nationalTessen } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and ("<ref>" .. royalReference .. "</ref>") or nil, audio = royalAudio, note = royalNote, chyndaa = royalChyndaa, tessenLettyraghey = royalTessen } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and ("<ref>" .. otherReference .. "</ref>") or nil, audio = otherAudio, note = otherNote, chyndaa = otherChyndaa, tessenLettyraghey = otherTessen } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, {"arrane_ashoonagh"}) local royal = getManual(args, {"arrane_reeoil"}) local other = getManual(args, {"arrane"}) local nationalReference = getManual(args, {"imraa_arrane_ashoonagh"}) local royalReference = getManual(args, {"imraa_arrane_reeoil"}) local otherReference = getManual(args, {"imraa_arrane"}) -- Updated to your preferred parameter nomenclature local nationalAudio = getManual(args, {"coadan_arrane_ashoonagh"}) local royalAudio = getManual(args, {"coadan_arrane_reeoil"}) local otherAudio = getManual(args, {"coadan_arrane"}) -- Updated to match the requested noteyn_ prefix pattern local nationalNote = getManual(args, {"noteyn_arrane_ashoonagh"}) local royalNote = getManual(args, {"noteyn_arrane_reeoil"}) local otherNote = getManual(args, {"noteyn_arrane"}) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and ("<ref>" .. nationalReference .. "</ref>") or nil, audio = nationalAudio, note = nationalNote } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and ("<ref>" .. royalReference .. "</ref>") or nil, audio = royalAudio, note = royalNote } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and ("<ref>" .. otherReference .. "</ref>") or nil, audio = otherAudio, note = otherNote } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS OUTPUT -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} -- 1. Format Motto Row if motto then local baseText = motto.text baseText = mw.ustring.gsub(baseText, '^"+', ''):gsub('"+$', ''):gsub('^“', ''):gsub('”$', '') if not mw.ustring.find(baseText, "%[%[") then baseText = "''" .. baseText .. "''" end -- Corrected to use tessenLettyraghey (transliteration) formatting if motto.tessenLettyraghey and motto.tessenLettyraghey ~= "" then baseText = baseText .. " (''" .. motto.tessenLettyraghey .. "'')" end if motto.chyndaa and motto.chyndaa ~= "" then baseText = baseText .. " <br/><small>“" .. motto.chyndaa .. "”</small>" end if motto.reference then baseText = baseText .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. baseText) end -- 2. Helper to format Anthem rows safely local function formatAnthemRow(label, anthemObj) if not anthemObj or not anthemObj.text then return nil end local cleanText = anthemObj.text cleanText = mw.ustring.gsub(cleanText, '^"+', ''):gsub('"+$', ''):gsub('^“', ''):gsub('”$', '') if not mw.ustring.find(cleanText, "%[%[") then cleanText = '[[' .. cleanText .. '|' .. cleanText .. ']]' end local display = '“' .. cleanText .. '”' -- Parse the tessenLettyraghey variable if anthemObj.tessenLettyraghey and anthemObj.tessenLettyraghey ~= "" then display = display .. " (''" .. anthemObj.tessenLettyraghey .. "'')" end if anthemObj.chyndaa and anthemObj.chyndaa ~= "" then display = display .. " <br/><small>“" .. anthemObj.chyndaa .. "”</small>" end if anthemObj.note and anthemObj.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { anthemObj.note } } display = display .. efnOut end if anthemObj.reference then display = display .. anthemObj.reference end if anthemObj.audio and anthemObj.audio ~= "" then display = display .. '<br/><div style="text-align:center; margin-top:0.3em;">[[Coadan:' .. anthemObj.audio .. '|center]]</div>' end return "'''" .. label .. ":&nbsp;'''" .. display end local nationalRow = formatAnthemRow("[[Arrane ashoonagh]]", anthems.national) if nationalRow then table.insert(rows, nationalRow) end local otherRow = formatAnthemRow("Anthym", anthems.other) if otherRow then table.insert(rows, otherRow) end local royalRow = formatAnthemRow("[[Arrane reeoil]]", anthems.royal) if royalRow then table.insert(rows, royalRow) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- local function getLanguagesFromWikidata() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P37") if not statements or #statements == 0 then return {} end local languages = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local langEntity = mw.wikibase.getEntity(id) if langEntity then local label = langEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(languages, { text = label, role = role, reference = getWikidataReference(statement) }) end end end end return languages end local function classifyLanguages(languages) local result = { official = {}, regional = {}, minority = {} } for _, language in ipairs(languages) do local role = language.role or "" local lowerRole = mw.ustring.lower(role) if mw.ustring.find(lowerRole, "minority") then table.insert(result.minority, language) elseif mw.ustring.find(lowerRole, "regional") then table.insert(result.regional, language) else table.insert(result.official, language) end end return result end -- Manx-specific collation: çh sorts as ch local function manxSort(a, b) local function normalize(text) -- Replace çh with ch for sorting purposes text = mw.ustring.lower(text) text = mw.ustring.gsub(text, "çh", "ch") return text end return normalize(a) < normalize(b) end local function joinLanguageList(languages) if not languages or #languages == 0 then return nil end -- Sort languages alphabetically with Manx collation table.sort(languages, function(a, b) return manxSort(a.text, b.text) end) local parts = {} for _, language in ipairs(languages) do local text = language.text -- Wrap language name in a wikilink (even if redlinked) text = '[[' .. text .. '|' .. text .. ']]' if language.reference then text = text .. language.reference end table.insert(parts, text) end if #parts == 0 then return nil end -- Return as hlist format return '<div class="hlist">' .. table.concat(parts, '&nbsp;· ') .. '</div>' end -- Splits text on a top-level separator character, without -- splitting inside {{...}} or [[...]] (so a piped wikilink -- like [[Country|Display]], or a nested template, doesn't -- get miscounted as two items). local function splitTopLevel(text, sep) local parts = {} local current = {} local depthCurly = 0 local depthSquare = 0 local len = mw.ustring.len(text) local i = 1 while i <= len do local two = mw.ustring.sub(text, i, i + 1) local one = mw.ustring.sub(text, i, i) if two == "{{" then depthCurly = depthCurly + 1 table.insert(current, two) i = i + 2 elseif two == "}}" and depthCurly > 0 then depthCurly = depthCurly - 1 table.insert(current, two) i = i + 2 elseif two == "[[" then depthSquare = depthSquare + 1 table.insert(current, two) i = i + 2 elseif two == "]]" and depthSquare > 0 then depthSquare = depthSquare - 1 table.insert(current, two) i = i + 2 elseif one == sep and depthCurly == 0 and depthSquare == 0 then table.insert(parts, table.concat(current)) current = {} i = i + 1 else table.insert(current, one) i = i + 1 end end table.insert(parts, table.concat(current)) return parts end -- Counts the items inside a {{hlist|...}}/{{flatlist|...}}/ -- {{ubl|...}}/{{unbulleted list|...}} template call (the -- convention most legacy articles already use for this -- field). Returns nil if the text isn't one of these, so -- the caller can fall back to a plain heuristic. -- Finds the first call to a template matching namePattern -- anywhere in text (not just at the start/whole-string), -- respecting nested {{...}} so a template argument that -- itself contains braces doesn't break the search. Returns -- the inner content (everything after the first "|") or nil -- if no such template call is found. local function findTemplateCall(text, namePattern) local searchPattern = "{{%s*" .. namePattern .. "%s*|" local matchStart, matchEnd = mw.ustring.find(text, searchPattern) if not matchStart then return nil end local contentStart = matchEnd + 1 local depth = 1 local i = contentStart local len = mw.ustring.len(text) while i <= len do local two = mw.ustring.sub(text, i, i + 1) if two == "{{" then depth = depth + 1 i = i + 2 elseif two == "}}" then depth = depth - 1 i = i + 2 if depth == 0 then local contentEnd = i - 3 return mw.ustring.sub(text, contentStart, contentEnd) end else i = i + 1 end end return nil end -- Pulls any <ref>...</ref> (or self-closing <ref .../>) tags -- out of text, returning the text with them removed plus the -- extracted ref markup (already-valid <ref> tags, ready to -- use as-is - not to be re-wrapped). Returns (text, nil) if -- none are found. local function extractReferences(text) if not text then return text, nil end local refs = {} local cleaned = mw.ustring.gsub(text, "<ref[^>]*>.-</ref>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.ustring.gsub(cleaned, "<ref[^>]*/>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.text.trim(cleaned) if #refs == 0 then return cleaned, nil end return cleaned, table.concat(refs) end local function countHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local segments = splitTopLevel(inner, "|") local count = 0 for _, segment in ipairs(segments) do local trimmedSegment = mw.text.trim(segment) -- Skip named parameters (class=, style=, indent=, etc.) -- rather than counting them as list items. if trimmedSegment ~= "" and not mw.ustring.find(trimmedSegment, "^[%w_%- ]+=") then count = count + 1 end end return count end -- Count of items in a manually-entered language/list field, -- used to decide between a singular ("çhengey") and plural -- ("çhengaghyn") label. Wikidata-derived lists are counted -- exactly (see getLanguageData). Handles the {{hlist}} family -- (searched for anywhere in the text, not just as the entire -- value, since editors often append a trailing <ref> after -- the closing "}}") most legacy articles already use; -- otherwise falls back to a plain comma-count heuristic. local function countListItems(text) if not text or text == "" then return 0 end local hlistCount = countHlistItems(text) if hlistCount then return hlistCount end local count = 0 for _ in mw.text.gsplit(text, ",", true) do count = count + 1 end return count end -- Resolves one language tier from its raw manual parameter: -- strips out any inline <ref> tags (used as-is, since they're -- already valid markup), counts the list on the ref-stripped -- text, then re-appends the extracted ref(s) and/or a manual -- imraa_ reference (which - unlike an inline <ref> - is raw -- citation text that still needs wrapping) to the display value. local function wrapInWikilink(text) -- If already has wikilink syntax, don't double-wrap if mw.ustring.find(text, "%[%[") then return text end -- Otherwise wrap in wikilink return '[[' .. text .. '|' .. text .. ']]' end -- Resolves one language tier from its raw manual parameter: -- strips out any inline <ref> tags, extracts/sorts the items, -- expands an {{efn}} note if provided, and appends reference strings. local function buildLanguageValue(raw, manualReference, manualNote, frame) if not raw or mw.ustring.lower(mw.text.trim(raw)) == "none" then return nil, 0 end local cleaned, inlineRefs = extractReferences(raw) local count = countListItems(cleaned) -- Try to extract from hlist template first local languageNames = extractHlistItems(cleaned) -- If not in hlist format, split by comma if not languageNames then languageNames = {} for part in mw.text.gsplit(cleaned, ",", true) do local trimmed = mw.text.trim(part) if trimmed ~= "" then table.insert(languageNames, trimmed) end end end -- Sort alphabetically with Manx collation table.sort(languageNames, manxSort) -- Wrap each in a wikilink and build hlist layout local parts = {} for _, name in ipairs(languageNames) do table.insert(parts, '[[' .. name .. '|' .. name .. ']]') end local display = '<div class="hlist">' .. table.concat(parts, '&nbsp;· ') .. '</div>' -- 1. Append the efn note directly after the language hlist block if provided if manualNote and manualNote ~= "" and frame then local efnOut = frame:expandTemplate{ title = "efn", args = { manualNote } } display = display .. efnOut end -- 2. Append standard citation references if inlineRefs then display = display .. inlineRefs end if manualReference then display = display .. "<ref>" .. manualReference .. "</ref>" end return display, count end local function getLanguageData(args, frame) local officialRaw = getManual(args, { "çhengaghyn_oikoil", "çhengey_oikoil" }) local officialReference = getManual(args, { "imraa_çhengaghyn_oikoil", "imraa_çhengey_oikoil" }) local regionalRaw = getManual(args, { "çhengaghyn_ardjynagh", "çhengey_ardjynagh" }) local regionalReference = getManual(args, { "imraa_çhengaghyn_ardjynagh", "imraa_çhengey_ardjynagh" }) local minorityRaw = getManual(args, { "mynçhengaghyn", "mynçhengey" }) local minorityReference = getManual(args, { "imraa_mynçhengaghyn", "imraa_mynçhengey" }) local otherRaw = getManual(args, { "çhengaghyn", "çhengey" }) local otherReference = getManual(args, { "imraa_çhengaghyn", "imraa_çhengey" }) local otherLabel = getManual(args, { "sorçh_çhengaghyn" }) -- Extract the new custom noteyn_ parameters local officialNote = getManual(args, {"noteyn_çhengaghyn_oikoil", "noteyn_çhengey_oikoil"}) local regionalNote = getManual(args, {"noteyn_çhengaghyn_ardjynagh", "noteyn_çhengey_ardjynagh"}) local minorityNote = getManual(args, {"noteyn_mynçhengaghyn", "noteyn_mynçhengey"}) local otherNote = getManual(args, {"noteyn_çhengaghyn", "noteyn_çhengey"}) local result = { otherLabel = otherLabel } -- Pass parameters down to buildLanguageValue along with frame context result.official, result.officialCount = buildLanguageValue(officialRaw, officialReference, officialNote, frame) result.regional, result.regionalCount = buildLanguageValue(regionalRaw, regionalReference, regionalNote, frame) result.minority, result.minorityCount = buildLanguageValue(minorityRaw, minorityReference, minorityNote, frame) result.other, result.otherCount = buildLanguageValue(otherRaw, otherReference, otherNote, frame) -- Only reach for Wikidata if none of the three primary tiers were set manually if not result.official and not result.regional and not result.minority then local classified = classifyLanguages(getLanguagesFromWikidata()) result.official = joinLanguageList(classified.official) result.officialCount = #classified.official result.regional = joinLanguageList(classified.regional) result.regionalCount = #classified.regional result.minority = joinLanguageList(classified.minority) result.minorityCount = #classified.minority end return result end local function buildLanguageRows(args, frame) -- Pass the frame execution reference through local data = getLanguageData(args, frame) local rows = {} if data.official then local officialLabel = data.officialCount > 1 and "[[Çhengey oikoil|Çhengaghyn oikoil]]" or "[[Çhengey oikoil]]" local officialRow = '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. officialLabel .. '</th><td style="vertical-align:top;">' .. data.official .. '</td></tr>' if data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn&nbsp;ardjynagh er&nbsp;enney" or "Çhengey&nbsp;ardjynagh er&nbsp;enney" officialRow = officialRow .. '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:normal;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th>' .. '<td style="vertical-align:top;">' .. data.regional .. '</td></tr>' end table.insert(rows, officialRow) elseif data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn ardjynagh er enney" or "Çhengey ardjynagh er enney" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th><td style="vertical-align:top;">' .. data.regional .. '</td></tr>' ) end if data.minority then local minorityLabel = data.minorityCount > 1 and "[[Mynçhengey|Mynçhengaghyn]]" or "[[Mynçhengey]]" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. minorityLabel .. '</th><td style="vertical-align:top;">' .. data.minority .. '</td></tr>' ) end if data.other then local otherLabel = data.otherLabel or (data.otherCount > 1 and "Çhengaghyn" or "Çhengey") table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. otherLabel .. '</th><td style="vertical-align:top;">' .. data.other .. '</td></tr>' ) end if #rows == 0 then return nil end return table.concat(rows) end function p.languages(frame) local args = getArgs(frame) -- Updated to pass frame context downward cleanly return buildLanguageRows(args, frame) end local function getLanguageData(args) local officialRaw = getManual(args, { "çhengaghyn_oikoil", "çhengey_oikoil" }) local officialReference = getManual(args, { "imraa_çhengaghyn_oikoil", "imraa_çhengey_oikoil" }) local regionalRaw = getManual(args, { "çhengaghyn_ardjynagh", "çhengey_ardjynagh" }) local regionalReference = getManual(args, { "imraa_çhengaghyn_ardjynagh", "imraa_çhengey_ardjynagh" }) local minorityRaw = getManual(args, { "mynçhengaghyn", "mynçhengey" }) local minorityReference = getManual(args, { "imraa_mynçhengaghyn", "imraa_mynçhengey" }) local otherRaw = getManual(args, { "çhengaghyn", "çhengey" }) local otherReference = getManual(args, { "imraa_çhengaghyn", "imraa_çhengey" }) local otherLabel = getManual(args, { "sorçh_çhengaghyn" }) local result = { otherLabel = otherLabel } result.official, result.officialCount = buildLanguageValue(officialRaw, officialReference) result.regional, result.regionalCount = buildLanguageValue(regionalRaw, regionalReference) result.minority, result.minorityCount = buildLanguageValue(minorityRaw, minorityReference) result.other, result.otherCount = buildLanguageValue(otherRaw, otherReference) -- Only reach for Wikidata if none of the three tiers -- were set manually - a manual "none" or partial set -- of overrides always wins over the auto-fetch. if not result.official and not result.regional and not result.minority then local classified = classifyLanguages(getLanguagesFromWikidata()) result.official = joinLanguageList(classified.official) result.officialCount = #classified.official result.regional = joinLanguageList(classified.regional) result.regionalCount = #classified.regional result.minority = joinLanguageList(classified.minority) result.minorityCount = #classified.minority end return result end local function buildLanguageRows(args) local data = getLanguageData(args) local rows = {} if data.official then local officialLabel = data.officialCount > 1 and "[[Çhengey oikoil|Çhengaghyn oikoil]]" or "[[Çhengey oikoil]]" local officialRow = '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. officialLabel .. '</th><td style="vertical-align:top;">' .. data.official .. '</td></tr>' if data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn&nbsp;ardjynagh er&nbsp;enney" or "Çhengey&nbsp;ardjynagh er&nbsp;enney" officialRow = officialRow .. '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:normal;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th>' .. '<td style="vertical-align:top;">' .. data.regional .. '</td></tr>' end table.insert(rows, officialRow) elseif data.regional then -- Regional recognised even without a separate -- official-language statement. local regionalLabel = data.regionalCount > 1 and "Çhengaghyn ardjynagh er enney" or "Çhengey ardjynagh er enney" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th><td style="vertical-align:top;">' .. data.regional .. '</td></tr>' ) end if data.minority then local minorityLabel = data.minorityCount > 1 and "[[Mynçhengey|Mynçhengaghyn]]" or "[[Mynçhengey]]" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. minorityLabel .. '</th><td style="vertical-align:top;">' .. data.minority .. '</td></tr>' ) end if data.other then local otherLabel = data.otherLabel or (data.otherCount > 1 and "Çhengaghyn" or "Çhengey") table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. otherLabel .. '</th><td style="vertical-align:top;">' .. data.other .. '</td></tr>' ) end if #rows == 0 then return nil end return table.concat(rows) end function p.languages(frame) local args = getArgs(frame) return buildLanguageRows(args) end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCityEntityFromTitle(value) local title = normaliseCityName(value) if title == "" then return nil end local entityId = mw.wikibase.getEntityIdForTitle(title) if not entityId then return nil end return mw.wikibase.getEntity(entityId) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end -- Extract custom note parameter local note = getManual(args, {"noteyn_preeu-valley"}) if capital then return { text = capital, entity = getCityEntityFromTitle(capital), reference = nil, note = note } end local entity, statement = getWikidataItem("P36") if entity then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or entity:getLabel(), entity = entity, reference = getWikidataReference(statement), note = nil -- Wikidata items don't have manual wiki notes } end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end -- Extract custom note parameter local note = getManual(args, {"noteyn_ynnyd_reiragh"}) if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil, note = note } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end -- Extract custom note parameter local note = getManual(args, {"noteyn_balley_smoo"}) if city then return { text = city, entity = getCityEntityFromTitle(city), reference = nil, note = note } end local country = mw.wikibase.getEntityObject() if not country then return nil end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id local target = mw.wikibase.getEntity(targetId) if target and not isDisambiguationPage(target) then local sitelink = target:getSitelink("gvwiki") return { text = sitelink or target:getLabel(), entity = target, reference = getWikidataReference(statement), note = nil } end end end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then return { text = city, entity = getCityEntityFromTitle(city), reference = nil } end local country = mw.wikibase.getEntityObject() if not country then return nil end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id local target = mw.wikibase.getEntity(targetId) if target and not isDisambiguationPage(target) then local sitelink = target:getSitelink("gvwiki") return { text = sitelink or target:getLabel(), entity = target, reference = getWikidataReference(statement) } end end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) return { capital = getCapitalData(args), administrative = getAdministrativeCentreData(args), largest = getLargestCityData(args), labels = getCityLabels(args) } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end local title = nil if city.entity then title = city.entity:getSitelink("gvwiki") end if not title or title == "" then title = normaliseCityName(city.text) end if not title or title == "" then return "" end return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest -- Helper function to render the data chunk cleanly local function renderCityCell(cityObj) local text = makeCityLink(cityObj) -- Append the efn footnote tag if it exists if cityObj.note and cityObj.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { cityObj.note } } text = text .. efnOut end -- Append standard reference citations if cityObj.reference then text = text .. cityObj.reference end -- Append coordinates block on a new line below the name if cityObj.entity then local coordinates = makeCoordinates(cityObj.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text end if capital then return renderCityCell(capital) elseif administrative then return renderCityCell(administrative) elseif largest then return renderCityCell(largest) end return nil end function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} local function formatLegacyRow(label, cityObj) local text = makeCityLink(cityObj) if cityObj.note and cityObj.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { cityObj.note } } text = text .. efnOut end if cityObj.reference then text = text .. cityObj.reference end if cityObj.entity then local coordinates = makeCoordinates(cityObj.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end return "'''" .. label .. "''': " .. text end if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end table.insert(rows, formatLegacyRow(label, capital)) end if administrative then local label = labels.administrative or "Ynnyd reiragh" table.insert(rows, formatLegacyRow(label, administrative)) end if largest then table.insert(rows, formatLegacyRow("Balley smoo", largest)) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -------------------------------------------------- -- HEADER -------------------------------------------------- do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -------------------------------------------------- -- FLAG / ARMS -------------------------------------------------- do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -------------------------------------------------- -- MOTTO / ANTHEM -------------------------------------------------- do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -------------------------------------------------- -- CAPITAL / ADMINISTRATIVE CENTRE / LARGEST CITY -------------------------------------------------- do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels -- Add one divider before the city section only. if capital or administrative or largest then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '"></td></tr>' ) end -- Capital if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Administrative centre if administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Largest city if largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- do local languageRows = buildLanguageRows(args) if languageRows then table.insert(rows, languageRows) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p 3egr95qzwthqo8jyr7aw5nfxgunr0wq 392896 392895 2026-09-07T02:08:50Z MacTire02 219 ++ 392896 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -- Extract items from an hlist/flatlist/ubl template local function extractHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local items = {} local segments = splitTopLevel(inner, "|") for _, segment in ipairs(segments) do local trimmed = mw.text.trim(segment) -- Skip named parameters (class=, style=, etc.) if trimmed ~= "" and not mw.ustring.find(trimmed, "^[%w_%- ]+=") then -- Extract just the link text if it's a wikilink local linkText = mw.ustring.match(trimmed, "%[%[.-|(.+)%]%]") or mw.ustring.match(trimmed, "%[%[(.+)%]%]") or trimmed table.insert(items, mw.text.trim(linkText)) end end return items end -------------------------------------------------- -- DISAMBIGUATION GUARD -------------------------------------------------- -- Some Wikidata statements resolve to a general/ambiguous -- item rather than the specific thing we want (e.g. a -- country's "most populous urban area" pointing at the -- ambiguous "New York" (Q22654) instead of "New York City" -- (Q60)). Skip anything flagged as a disambiguation page. local function isDisambiguationPage(entity) if not entity then return false end local statements = entity:getBestStatements("P31") if not statements then return false end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" and mainsnak.datavalue.value.id == "Q4167410" then return true end end return false end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity and not isDisambiguationPage(linkedEntity) then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- FLAG BORDER CHECK -------------------------------------------------- -- List of countries with non-rectangular flags (no border needed) local NON_RECTANGULAR_FLAGS = { ["Flag of Nepal.svg"] = true, ["Flag of Ohio.svg"] = true, ["Flag of Switzerland.svg"] = true, } -- Check if a flag needs a border local function needsFlagBorder(flagFile) if not flagFile then return true end if NON_RECTANGULAR_FLAGS[flagFile] then return false end local lowerFile = mw.ustring.lower(flagFile) if mw.ustring.find(lowerFile, "nepal") then return false end return true end -------------------------------------------------- -- MULTI-FLAG SUPPORT -------------------------------------------------- local function getFlagData(args) -- Get primary flag local flag = getManual(args, {"jalloo_brattagh"}) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end -- Get second flag (if any) local flag2 = getManual(args, {"jalloo_brattagh_2", "jalloo_brattagh_elley"}) if flag2 and mw.ustring.lower(flag2) == "none" then flag2 = nil elseif not flag2 then flag2 = getWikidataImage("P163") end -- Get arms local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end -- Get second arms (if any) local arms2 = getManual(args, { "jalloo_armys_2", "jalloo_cleinney_2" }) if arms2 and mw.ustring.lower(arms2) == "none" then arms2 = nil elseif not arms2 then arms2 = getWikidataImage("P237") end if not flag and not flag2 and not arms and not arms2 then return nil end local name = getCountryGenitive(args) or "" local data = { flags = {}, armses = {} } -- Primary flag if flag then local flagWidth = getManual(args, {"lheead_brattagh"}) or "125px" local hasBorder = needsFlagBorder(flag) table.insert(data.flags, { image = flag, width = flagWidth, hasBorder = hasBorder, link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh"}) or "Brattagh", isPrimary = true }) end -- Second flag if flag2 then local flag2Width = getManual(args, {"lheead_brattagh_2", "lheead_brattagh"}) or "100px" local hasBorder2 = needsFlagBorder(flag2) table.insert(data.flags, { image = flag2, width = flag2Width, hasBorder = hasBorder2, link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh_2"}) or "Brattagh elley", isPrimary = false }) end -- Primary arms if arms then local kind = getManual(args, {"art_sorçh_cowrey"}) or getManual(args, {"sorçh_cowrey"}) or "Armys" table.insert(data.armses, { image = arms, width = getManual(args, {"lheead_armys", "lheead_cleinney", "lheead_cowrey"}) or "85px", link = kind .. " " .. name, label = getManual(args, {"sorçh_cowrey"}) or "Armys", isPrimary = true }) end -- Second arms if arms2 then table.insert(data.armses, { image = arms2, width = getManual(args, {"lheead_armys_2", "lheead_cleinney_2"}) or "85px", link = "Armys " .. name, label = getManual(args, {"sorçh_cowrey_2"}) or "Armys", isPrimary = false }) end return data end -------------------------------------------------- -- UPDATED getFlagArmsData (replaces old function) -------------------------------------------------- local function getFlagArmsData(args) return getFlagData(args) end -------------------------------------------------- -- FLAG / ARMS BLOCK (UPDATED) -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} local hasFlags = #data.flags > 0 local hasArms = #data.armses > 0 -- Build flag column if hasFlags then local flagContent = {} for i, flagData in ipairs(data.flags) do local borderStyle = "" if flagData.hasBorder then borderStyle = '|style="border:1px solid #a2a9b1;"' end local flagImage = '[[Coadan:' .. flagData.image .. '|' .. flagData.width .. borderStyle .. ']]' table.insert(flagContent, flagImage) end local combinedFlags = table.concat(flagContent, '<br/>') table.insert(imageCells, '<td align="center" style="' .. (hasArms and "width:58%; " or "width:100%; ") .. 'vertical-align:middle;">' .. combinedFlags .. '</td>' ) local flagCaptions = {} for i, flagData in ipairs(data.flags) do table.insert(flagCaptions, '<small>[[' .. flagData.link .. '|' .. flagData.label .. ']]</small>' ) end table.insert(captionCells, '<td align="center">' .. table.concat(flagCaptions, '<br/>') .. '</td>' ) end -- Build arms column if hasArms then local armsContent = {} for i, armsData in ipairs(data.armses) do local armsImage = '[[Coadan:' .. armsData.image .. '|' .. armsData.width .. ']]' table.insert(armsContent, armsImage) end local combinedArms = table.concat(armsContent, '<br/>') table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">' .. combinedArms .. '</td>' ) local armsCaptions = {} for i, armsData in ipairs(data.armses) do table.insert(armsCaptions, '<small>[[' .. armsData.link .. '|' .. armsData.label .. ']]</small>' ) end table.insert(captionCells, '<td align="center">' .. table.concat(armsCaptions, '<br/>') .. '</td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) -- FIXED: First check with ç, second check with plain c local chyndaa = getManual(args, {"çhyndaa_jarroo_raa", "chyndaa_jarroo_raa"}) local tessenLettyraghey = getManual(args, {"tessen-lettyraghey_jarroo_raa"}) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = motto, reference = reference and "<ref>" .. reference .. "</ref>" or nil, chyndaa = chyndaa, tessenLettyraghey = tessenLettyraghey } end local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = value.text, reference = getWikidataReference(statement), chyndaa = nil, tessenLettyraghey = nil } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthemData(args) local national = getManual(args, {"arrane_ashoonagh"}) local royal = getManual(args, {"arrane_reeoil"}) local other = getManual(args, {"arrane"}) local nationalReference = getManual(args, {"imraa_arrane_ashoonagh"}) local royalReference = getManual(args, {"imraa_arrane_reeoil"}) local otherReference = getManual(args, {"imraa_arrane"}) local nationalAudio = getManual(args, {"coadan_arrane_ashoonagh"}) local royalAudio = getManual(args, {"coadan_arrane_reeoil"}) local otherAudio = getManual(args, {"coadan_arrane"}) local nationalNote = getManual(args, {"noteyn_arrane_ashoonagh"}) local royalNote = getManual(args, {"noteyn_arrane_reeoil"}) local otherNote = getManual(args, {"noteyn_arrane"}) -- FIXED: The second strings are now correctly mapped to standard 'c' variations! local nationalChyndaa = getManual(args, {"çhyndaa_arrane_ashoonagh", "chyndaa_arrane_ashoonagh"}) local royalChyndaa = getManual(args, {"çhyndaa_arrane_reeoil", "chyndaa_arrane_reeoil"}) local otherChyndaa = getManual(args, {"çhyndaa_arrane", "chyndaa_arrane"}) local nationalTessen = getManual(args, {"tessen-lettyraghey_arrane_ashoonagh"}) local royalTessen = getManual(args, {"tessen-lettyraghey_arrane_reeoil"}) local otherTessen = getManual(args, {"tessen-lettyraghey_arrane"}) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and ("<ref>" .. nationalReference .. "</ref>") or nil, audio = nationalAudio, note = nationalNote, chyndaa = nationalChyndaa, tessenLettyraghey = nationalTessen } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and ("<ref>" .. royalReference .. "</ref>") or nil, audio = royalAudio, note = royalNote, chyndaa = royalChyndaa, tessenLettyraghey = royalTessen } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and ("<ref>" .. otherReference .. "</ref>") or nil, audio = otherAudio, note = otherNote, chyndaa = otherChyndaa, tessenLettyraghey = otherTessen } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, {"arrane_ashoonagh"}) local royal = getManual(args, {"arrane_reeoil"}) local other = getManual(args, {"arrane"}) local nationalReference = getManual(args, {"imraa_arrane_ashoonagh"}) local royalReference = getManual(args, {"imraa_arrane_reeoil"}) local otherReference = getManual(args, {"imraa_arrane"}) -- Updated to your preferred parameter nomenclature local nationalAudio = getManual(args, {"coadan_arrane_ashoonagh"}) local royalAudio = getManual(args, {"coadan_arrane_reeoil"}) local otherAudio = getManual(args, {"coadan_arrane"}) -- Updated to match the requested noteyn_ prefix pattern local nationalNote = getManual(args, {"noteyn_arrane_ashoonagh"}) local royalNote = getManual(args, {"noteyn_arrane_reeoil"}) local otherNote = getManual(args, {"noteyn_arrane"}) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and ("<ref>" .. nationalReference .. "</ref>") or nil, audio = nationalAudio, note = nationalNote } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and ("<ref>" .. royalReference .. "</ref>") or nil, audio = royalAudio, note = royalNote } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and ("<ref>" .. otherReference .. "</ref>") or nil, audio = otherAudio, note = otherNote } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS OUTPUT -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} -- 1. Format Motto Row if motto then local baseText = motto.text baseText = mw.ustring.gsub(baseText, '^"+', ''):gsub('"+$', ''):gsub('^“', ''):gsub('”$', '') if not mw.ustring.find(baseText, "%[%[") then baseText = "''" .. baseText .. "''" end -- Corrected to use tessenLettyraghey (transliteration) formatting if motto.tessenLettyraghey and motto.tessenLettyraghey ~= "" then baseText = baseText .. " (''" .. motto.tessenLettyraghey .. "'')" end if motto.chyndaa and motto.chyndaa ~= "" then baseText = baseText .. " <br/><small>“" .. motto.chyndaa .. "”</small>" end if motto.reference then baseText = baseText .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. baseText) end -- 2. Helper to format Anthem rows safely local function formatAnthemRow(label, anthemObj) if not anthemObj or not anthemObj.text then return nil end local cleanText = anthemObj.text cleanText = mw.ustring.gsub(cleanText, '^"+', ''):gsub('"+$', ''):gsub('^“', ''):gsub('”$', '') if not mw.ustring.find(cleanText, "%[%[") then cleanText = '[[' .. cleanText .. '|' .. cleanText .. ']]' end local display = '“' .. cleanText .. '”' -- Parse the tessenLettyraghey variable if anthemObj.tessenLettyraghey and anthemObj.tessenLettyraghey ~= "" then display = display .. " (''" .. anthemObj.tessenLettyraghey .. "'')" end if anthemObj.chyndaa and anthemObj.chyndaa ~= "" then display = display .. " <br/><small>“" .. anthemObj.chyndaa .. "”</small>" end if anthemObj.note and anthemObj.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { anthemObj.note } } display = display .. efnOut end if anthemObj.reference then display = display .. anthemObj.reference end if anthemObj.audio and anthemObj.audio ~= "" then display = display .. '<br/><div style="text-align:center; margin-top:0.3em;">[[Coadan:' .. anthemObj.audio .. '|center]]</div>' end return "'''" .. label .. ":&nbsp;'''" .. display end local nationalRow = formatAnthemRow("[[Arrane ashoonagh]]", anthems.national) if nationalRow then table.insert(rows, nationalRow) end local otherRow = formatAnthemRow("Anthym", anthems.other) if otherRow then table.insert(rows, otherRow) end local royalRow = formatAnthemRow("[[Arrane reeoil]]", anthems.royal) if royalRow then table.insert(rows, royalRow) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- local function getLanguagesFromWikidata() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P37") if not statements or #statements == 0 then return {} end local languages = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local langEntity = mw.wikibase.getEntity(id) if langEntity then local label = langEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(languages, { text = label, role = role, reference = getWikidataReference(statement) }) end end end end return languages end local function classifyLanguages(languages) local result = { official = {}, regional = {}, minority = {} } for _, language in ipairs(languages) do local role = language.role or "" local lowerRole = mw.ustring.lower(role) if mw.ustring.find(lowerRole, "minority") then table.insert(result.minority, language) elseif mw.ustring.find(lowerRole, "regional") then table.insert(result.regional, language) else table.insert(result.official, language) end end return result end -- Manx-specific collation: çh sorts as ch local function manxSort(a, b) local function normalize(text) -- Replace çh with ch for sorting purposes text = mw.ustring.lower(text) text = mw.ustring.gsub(text, "çh", "ch") return text end return normalize(a) < normalize(b) end local function joinLanguageList(languages) if not languages or #languages == 0 then return nil end -- Sort languages alphabetically with Manx collation table.sort(languages, function(a, b) return manxSort(a.text, b.text) end) local parts = {} for _, language in ipairs(languages) do local text = language.text -- Wrap language name in a wikilink (even if redlinked) text = '[[' .. text .. '|' .. text .. ']]' if language.reference then text = text .. language.reference end table.insert(parts, text) end if #parts == 0 then return nil end -- Return as hlist format return '<div class="hlist">' .. table.concat(parts, '&nbsp;· ') .. '</div>' end -- Splits text on a top-level separator character, without -- splitting inside {{...}} or [[...]] (so a piped wikilink -- like [[Country|Display]], or a nested template, doesn't -- get miscounted as two items). local function splitTopLevel(text, sep) local parts = {} local current = {} local depthCurly = 0 local depthSquare = 0 local len = mw.ustring.len(text) local i = 1 while i <= len do local two = mw.ustring.sub(text, i, i + 1) local one = mw.ustring.sub(text, i, i) if two == "{{" then depthCurly = depthCurly + 1 table.insert(current, two) i = i + 2 elseif two == "}}" and depthCurly > 0 then depthCurly = depthCurly - 1 table.insert(current, two) i = i + 2 elseif two == "[[" then depthSquare = depthSquare + 1 table.insert(current, two) i = i + 2 elseif two == "]]" and depthSquare > 0 then depthSquare = depthSquare - 1 table.insert(current, two) i = i + 2 elseif one == sep and depthCurly == 0 and depthSquare == 0 then table.insert(parts, table.concat(current)) current = {} i = i + 1 else table.insert(current, one) i = i + 1 end end table.insert(parts, table.concat(current)) return parts end -- Counts the items inside a {{hlist|...}}/{{flatlist|...}}/ -- {{ubl|...}}/{{unbulleted list|...}} template call (the -- convention most legacy articles already use for this -- field). Returns nil if the text isn't one of these, so -- the caller can fall back to a plain heuristic. -- Finds the first call to a template matching namePattern -- anywhere in text (not just at the start/whole-string), -- respecting nested {{...}} so a template argument that -- itself contains braces doesn't break the search. Returns -- the inner content (everything after the first "|") or nil -- if no such template call is found. local function findTemplateCall(text, namePattern) local searchPattern = "{{%s*" .. namePattern .. "%s*|" local matchStart, matchEnd = mw.ustring.find(text, searchPattern) if not matchStart then return nil end local contentStart = matchEnd + 1 local depth = 1 local i = contentStart local len = mw.ustring.len(text) while i <= len do local two = mw.ustring.sub(text, i, i + 1) if two == "{{" then depth = depth + 1 i = i + 2 elseif two == "}}" then depth = depth - 1 i = i + 2 if depth == 0 then local contentEnd = i - 3 return mw.ustring.sub(text, contentStart, contentEnd) end else i = i + 1 end end return nil end -- Pulls any <ref>...</ref> (or self-closing <ref .../>) tags -- out of text, returning the text with them removed plus the -- extracted ref markup (already-valid <ref> tags, ready to -- use as-is - not to be re-wrapped). Returns (text, nil) if -- none are found. local function extractReferences(text) if not text then return text, nil end local refs = {} local cleaned = mw.ustring.gsub(text, "<ref[^>]*>.-</ref>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.ustring.gsub(cleaned, "<ref[^>]*/>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.text.trim(cleaned) if #refs == 0 then return cleaned, nil end return cleaned, table.concat(refs) end local function countHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local segments = splitTopLevel(inner, "|") local count = 0 for _, segment in ipairs(segments) do local trimmedSegment = mw.text.trim(segment) -- Skip named parameters (class=, style=, indent=, etc.) -- rather than counting them as list items. if trimmedSegment ~= "" and not mw.ustring.find(trimmedSegment, "^[%w_%- ]+=") then count = count + 1 end end return count end -- Count of items in a manually-entered language/list field, -- used to decide between a singular ("çhengey") and plural -- ("çhengaghyn") label. Wikidata-derived lists are counted -- exactly (see getLanguageData). Handles the {{hlist}} family -- (searched for anywhere in the text, not just as the entire -- value, since editors often append a trailing <ref> after -- the closing "}}") most legacy articles already use; -- otherwise falls back to a plain comma-count heuristic. local function countListItems(text) if not text or text == "" then return 0 end local hlistCount = countHlistItems(text) if hlistCount then return hlistCount end local count = 0 for _ in mw.text.gsplit(text, ",", true) do count = count + 1 end return count end -- Resolves one language tier from its raw manual parameter: -- strips out any inline <ref> tags (used as-is, since they're -- already valid markup), counts the list on the ref-stripped -- text, then re-appends the extracted ref(s) and/or a manual -- imraa_ reference (which - unlike an inline <ref> - is raw -- citation text that still needs wrapping) to the display value. local function wrapInWikilink(text) -- If already has wikilink syntax, don't double-wrap if mw.ustring.find(text, "%[%[") then return text end -- Otherwise wrap in wikilink return '[[' .. text .. '|' .. text .. ']]' end -- Resolves one language tier from its raw manual parameter: -- strips out any inline <ref> tags, extracts/sorts the items, -- expands an {{efn}} note if provided, and appends reference strings. local function buildLanguageValue(raw, manualReference, manualNote, frame) if not raw or mw.ustring.lower(mw.text.trim(raw)) == "none" then return nil, 0 end local cleaned, inlineRefs = extractReferences(raw) local count = countListItems(cleaned) -- Try to extract from hlist template first local languageNames = extractHlistItems(cleaned) -- If not in hlist format, split by comma if not languageNames then languageNames = {} for part in mw.text.gsplit(cleaned, ",", true) do local trimmed = mw.text.trim(part) if trimmed ~= "" then table.insert(languageNames, trimmed) end end end -- Sort alphabetically with Manx collation table.sort(languageNames, manxSort) -- Wrap each in a wikilink and build hlist layout local parts = {} for _, name in ipairs(languageNames) do table.insert(parts, '[[' .. name .. '|' .. name .. ']]') end local display = '<div class="hlist">' .. table.concat(parts, '&nbsp;· ') .. '</div>' -- 1. Append the efn note directly after the language hlist block if provided if manualNote and manualNote ~= "" and frame then local efnOut = frame:expandTemplate{ title = "efn", args = { manualNote } } display = display .. efnOut end -- 2. Append standard citation references if inlineRefs then display = display .. inlineRefs end if manualReference then display = display .. "<ref>" .. manualReference .. "</ref>" end return display, count end local function getLanguageData(args, frame) local officialRaw = getManual(args, { "çhengaghyn_oikoil", "çhengey_oikoil" }) local officialReference = getManual(args, { "imraa_çhengaghyn_oikoil", "imraa_çhengey_oikoil" }) local regionalRaw = getManual(args, { "çhengaghyn_ardjynagh", "çhengey_ardjynagh" }) local regionalReference = getManual(args, { "imraa_çhengaghyn_ardjynagh", "imraa_çhengey_ardjynagh" }) local minorityRaw = getManual(args, { "mynçhengaghyn", "mynçhengey" }) local minorityReference = getManual(args, { "imraa_mynçhengaghyn", "imraa_mynçhengey" }) local otherRaw = getManual(args, { "çhengaghyn", "çhengey" }) local otherReference = getManual(args, { "imraa_çhengaghyn", "imraa_çhengey" }) local otherLabel = getManual(args, { "sorçh_çhengaghyn" }) -- Extract the new custom noteyn_ parameters local officialNote = getManual(args, {"noteyn_çhengaghyn_oikoil", "noteyn_çhengey_oikoil"}) local regionalNote = getManual(args, {"noteyn_çhengaghyn_ardjynagh", "noteyn_çhengey_ardjynagh"}) local minorityNote = getManual(args, {"noteyn_mynçhengaghyn", "noteyn_mynçhengey"}) local otherNote = getManual(args, {"noteyn_çhengaghyn", "noteyn_çhengey"}) local result = { otherLabel = otherLabel } -- Pass parameters down to buildLanguageValue along with frame context result.official, result.officialCount = buildLanguageValue(officialRaw, officialReference, officialNote, frame) result.regional, result.regionalCount = buildLanguageValue(regionalRaw, regionalReference, regionalNote, frame) result.minority, result.minorityCount = buildLanguageValue(minorityRaw, minorityReference, minorityNote, frame) result.other, result.otherCount = buildLanguageValue(otherRaw, otherReference, otherNote, frame) -- Only reach for Wikidata if none of the three primary tiers were set manually if not result.official and not result.regional and not result.minority then local classified = classifyLanguages(getLanguagesFromWikidata()) result.official = joinLanguageList(classified.official) result.officialCount = #classified.official result.regional = joinLanguageList(classified.regional) result.regionalCount = #classified.regional result.minority = joinLanguageList(classified.minority) result.minorityCount = #classified.minority end return result end local function buildLanguageRows(args, frame) -- Pass the frame execution reference through local data = getLanguageData(args, frame) local rows = {} if data.official then local officialLabel = data.officialCount > 1 and "[[Çhengey oikoil|Çhengaghyn oikoil]]" or "[[Çhengey oikoil]]" local officialRow = '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. officialLabel .. '</th><td style="vertical-align:top;">' .. data.official .. '</td></tr>' if data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn&nbsp;ardjynagh er&nbsp;enney" or "Çhengey&nbsp;ardjynagh er&nbsp;enney" officialRow = officialRow .. '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:normal;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th>' .. '<td style="vertical-align:top;">' .. data.regional .. '</td></tr>' end table.insert(rows, officialRow) elseif data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn ardjynagh er enney" or "Çhengey ardjynagh er enney" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th><td style="vertical-align:top;">' .. data.regional .. '</td></tr>' ) end if data.minority then local minorityLabel = data.minorityCount > 1 and "[[Mynçhengey|Mynçhengaghyn]]" or "[[Mynçhengey]]" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. minorityLabel .. '</th><td style="vertical-align:top;">' .. data.minority .. '</td></tr>' ) end if data.other then local otherLabel = data.otherLabel or (data.otherCount > 1 and "Çhengaghyn" or "Çhengey") table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. otherLabel .. '</th><td style="vertical-align:top;">' .. data.other .. '</td></tr>' ) end if #rows == 0 then return nil end return table.concat(rows) end function p.languages(frame) local args = getArgs(frame) -- Updated to pass frame context downward cleanly return buildLanguageRows(args, frame) end local function getLanguageData(args) local officialRaw = getManual(args, { "çhengaghyn_oikoil", "çhengey_oikoil" }) local officialReference = getManual(args, { "imraa_çhengaghyn_oikoil", "imraa_çhengey_oikoil" }) local regionalRaw = getManual(args, { "çhengaghyn_ardjynagh", "çhengey_ardjynagh" }) local regionalReference = getManual(args, { "imraa_çhengaghyn_ardjynagh", "imraa_çhengey_ardjynagh" }) local minorityRaw = getManual(args, { "mynçhengaghyn", "mynçhengey" }) local minorityReference = getManual(args, { "imraa_mynçhengaghyn", "imraa_mynçhengey" }) local otherRaw = getManual(args, { "çhengaghyn", "çhengey" }) local otherReference = getManual(args, { "imraa_çhengaghyn", "imraa_çhengey" }) local otherLabel = getManual(args, { "sorçh_çhengaghyn" }) local result = { otherLabel = otherLabel } result.official, result.officialCount = buildLanguageValue(officialRaw, officialReference) result.regional, result.regionalCount = buildLanguageValue(regionalRaw, regionalReference) result.minority, result.minorityCount = buildLanguageValue(minorityRaw, minorityReference) result.other, result.otherCount = buildLanguageValue(otherRaw, otherReference) -- Only reach for Wikidata if none of the three tiers -- were set manually - a manual "none" or partial set -- of overrides always wins over the auto-fetch. if not result.official and not result.regional and not result.minority then local classified = classifyLanguages(getLanguagesFromWikidata()) result.official = joinLanguageList(classified.official) result.officialCount = #classified.official result.regional = joinLanguageList(classified.regional) result.regionalCount = #classified.regional result.minority = joinLanguageList(classified.minority) result.minorityCount = #classified.minority end return result end local function buildLanguageRows(args) local data = getLanguageData(args) local rows = {} if data.official then local officialLabel = data.officialCount > 1 and "[[Çhengey oikoil|Çhengaghyn oikoil]]" or "[[Çhengey oikoil]]" local officialRow = '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. officialLabel .. '</th><td style="vertical-align:top;">' .. data.official .. '</td></tr>' if data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn&nbsp;ardjynagh er&nbsp;enney" or "Çhengey&nbsp;ardjynagh er&nbsp;enney" officialRow = officialRow .. '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:normal;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th>' .. '<td style="vertical-align:top;">' .. data.regional .. '</td></tr>' end table.insert(rows, officialRow) elseif data.regional then -- Regional recognised even without a separate -- official-language statement. local regionalLabel = data.regionalCount > 1 and "Çhengaghyn ardjynagh er enney" or "Çhengey ardjynagh er enney" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th><td style="vertical-align:top;">' .. data.regional .. '</td></tr>' ) end if data.minority then local minorityLabel = data.minorityCount > 1 and "[[Mynçhengey|Mynçhengaghyn]]" or "[[Mynçhengey]]" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. minorityLabel .. '</th><td style="vertical-align:top;">' .. data.minority .. '</td></tr>' ) end if data.other then local otherLabel = data.otherLabel or (data.otherCount > 1 and "Çhengaghyn" or "Çhengey") table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. otherLabel .. '</th><td style="vertical-align:top;">' .. data.other .. '</td></tr>' ) end if #rows == 0 then return nil end return table.concat(rows) end function p.languages(frame) local args = getArgs(frame) return buildLanguageRows(args) end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCityEntityFromTitle(value) local title = normaliseCityName(value) if title == "" then return nil end local entityId = mw.wikibase.getEntityIdForTitle(title) if not entityId then return nil end return mw.wikibase.getEntity(entityId) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end -- Extract custom note parameter local note = getManual(args, {"noteyn_preeu-valley"}) if capital then return { text = capital, entity = getCityEntityFromTitle(capital), reference = nil, note = note } end local entity, statement = getWikidataItem("P36") if entity then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or entity:getLabel(), entity = entity, reference = getWikidataReference(statement), note = nil -- Wikidata items don't have manual wiki notes } end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end -- Extract custom note parameter local note = getManual(args, {"noteyn_ynnyd_reiragh"}) if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil, note = note } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end -- Extract custom note parameter local note = getManual(args, {"noteyn_balley_smoo"}) if city then return { text = city, entity = getCityEntityFromTitle(city), reference = nil, note = note } end local country = mw.wikibase.getEntityObject() if not country then return nil end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id local target = mw.wikibase.getEntity(targetId) if target and not isDisambiguationPage(target) then local sitelink = target:getSitelink("gvwiki") return { text = sitelink or target:getLabel(), entity = target, reference = getWikidataReference(statement), note = nil } end end end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then return { text = city, entity = getCityEntityFromTitle(city), reference = nil } end local country = mw.wikibase.getEntityObject() if not country then return nil end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id local target = mw.wikibase.getEntity(targetId) if target and not isDisambiguationPage(target) then local sitelink = target:getSitelink("gvwiki") return { text = sitelink or target:getLabel(), entity = target, reference = getWikidataReference(statement) } end end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) return { capital = getCapitalData(args), administrative = getAdministrativeCentreData(args), largest = getLargestCityData(args), labels = getCityLabels(args) } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end local title = nil if city.entity then title = city.entity:getSitelink("gvwiki") end if not title or title == "" then title = normaliseCityName(city.text) end if not title or title == "" then return "" end return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest -- Helper function to render the data chunk cleanly local function renderCityCell(cityObj) local text = makeCityLink(cityObj) -- Append the efn footnote tag if it exists if cityObj.note and cityObj.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { cityObj.note } } text = text .. efnOut end -- Append standard reference citations if cityObj.reference then text = text .. cityObj.reference end -- Append coordinates block on a new line below the name if cityObj.entity then local coordinates = makeCoordinates(cityObj.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text end if capital then return renderCityCell(capital) elseif administrative then return renderCityCell(administrative) elseif largest then return renderCityCell(largest) end return nil end function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} local function formatLegacyRow(label, cityObj) local text = makeCityLink(cityObj) if cityObj.note and cityObj.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { cityObj.note } } text = text .. efnOut end if cityObj.reference then text = text .. cityObj.reference end if cityObj.entity then local coordinates = makeCoordinates(cityObj.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end return "'''" .. label .. "''': " .. text end if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end table.insert(rows, formatLegacyRow(label, capital)) end if administrative then local label = labels.administrative or "Ynnyd reiragh" table.insert(rows, formatLegacyRow(label, administrative)) end if largest then table.insert(rows, formatLegacyRow("Balley smoo", largest)) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -------------------------------------------------- -- HEADER -------------------------------------------------- do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -------------------------------------------------- -- FLAG / ARMS -------------------------------------------------- do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -------------------------------------------------- -- MOTTO / ANTHEM -------------------------------------------------- do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -------------------------------------------------- -- CAPITAL / ADMINISTRATIVE CENTRE / LARGEST CITY -------------------------------------------------- do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels -- Add one divider before the city section only. if capital or administrative or largest then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '"></td></tr>' ) end -- Capital if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Administrative centre if administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Largest city if largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- do local languageRows = buildLanguageRows(args) if languageRows then table.insert(rows, languageRows) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p 3ibcomzy46alw4e8hhi5d01vhcsi7h2 392897 392896 2026-09-07T02:10:00Z MacTire02 219 ++ 392897 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -- Extract items from an hlist/flatlist/ubl template local function extractHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local items = {} local segments = splitTopLevel(inner, "|") for _, segment in ipairs(segments) do local trimmed = mw.text.trim(segment) -- Skip named parameters (class=, style=, etc.) if trimmed ~= "" and not mw.ustring.find(trimmed, "^[%w_%- ]+=") then -- Extract just the link text if it's a wikilink local linkText = mw.ustring.match(trimmed, "%[%[.-|(.+)%]%]") or mw.ustring.match(trimmed, "%[%[(.+)%]%]") or trimmed table.insert(items, mw.text.trim(linkText)) end end return items end -------------------------------------------------- -- DISAMBIGUATION GUARD -------------------------------------------------- -- Some Wikidata statements resolve to a general/ambiguous -- item rather than the specific thing we want (e.g. a -- country's "most populous urban area" pointing at the -- ambiguous "New York" (Q22654) instead of "New York City" -- (Q60)). Skip anything flagged as a disambiguation page. local function isDisambiguationPage(entity) if not entity then return false end local statements = entity:getBestStatements("P31") if not statements then return false end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" and mainsnak.datavalue.value.id == "Q4167410" then return true end end return false end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity and not isDisambiguationPage(linkedEntity) then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- FLAG BORDER CHECK -------------------------------------------------- -- List of countries with non-rectangular flags (no border needed) local NON_RECTANGULAR_FLAGS = { ["Flag of Nepal.svg"] = true, ["Flag of Ohio.svg"] = true, ["Flag of Switzerland.svg"] = true, } -- Check if a flag needs a border local function needsFlagBorder(flagFile) if not flagFile then return true end if NON_RECTANGULAR_FLAGS[flagFile] then return false end local lowerFile = mw.ustring.lower(flagFile) if mw.ustring.find(lowerFile, "nepal") then return false end return true end -------------------------------------------------- -- MULTI-FLAG SUPPORT -------------------------------------------------- local function getFlagData(args) -- Get primary flag local flag = getManual(args, {"jalloo_brattagh"}) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end -- Get second flag (if any) local flag2 = getManual(args, {"jalloo_brattagh_2", "jalloo_brattagh_elley"}) if flag2 and mw.ustring.lower(flag2) == "none" then flag2 = nil elseif not flag2 then flag2 = getWikidataImage("P163") end -- Get arms local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end -- Get second arms (if any) local arms2 = getManual(args, { "jalloo_armys_2", "jalloo_cleinney_2" }) if arms2 and mw.ustring.lower(arms2) == "none" then arms2 = nil elseif not arms2 then arms2 = getWikidataImage("P237") end if not flag and not flag2 and not arms and not arms2 then return nil end local name = getCountryGenitive(args) or "" local data = { flags = {}, armses = {} } -- Primary flag if flag then local flagWidth = getManual(args, {"lheead_brattagh"}) or "125px" local hasBorder = needsFlagBorder(flag) table.insert(data.flags, { image = flag, width = flagWidth, hasBorder = hasBorder, link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh"}) or "Brattagh", isPrimary = true }) end -- Second flag if flag2 then local flag2Width = getManual(args, {"lheead_brattagh_2", "lheead_brattagh"}) or "100px" local hasBorder2 = needsFlagBorder(flag2) table.insert(data.flags, { image = flag2, width = flag2Width, hasBorder = hasBorder2, link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh_2"}) or "Brattagh elley", isPrimary = false }) end -- Primary arms if arms then local kind = getManual(args, {"art_sorçh_cowrey"}) or getManual(args, {"sorçh_cowrey"}) or "Armys" table.insert(data.armses, { image = arms, width = getManual(args, {"lheead_armys", "lheead_cleinney", "lheead_cowrey"}) or "85px", link = kind .. " " .. name, label = getManual(args, {"sorçh_cowrey"}) or "Armys", isPrimary = true }) end -- Second arms if arms2 then table.insert(data.armses, { image = arms2, width = getManual(args, {"lheead_armys_2", "lheead_cleinney_2"}) or "85px", link = "Armys " .. name, label = getManual(args, {"sorçh_cowrey_2"}) or "Armys", isPrimary = false }) end return data end -------------------------------------------------- -- UPDATED getFlagArmsData (replaces old function) -------------------------------------------------- local function getFlagArmsData(args) return getFlagData(args) end -------------------------------------------------- -- FLAG / ARMS BLOCK (UPDATED) -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} local hasFlags = #data.flags > 0 local hasArms = #data.armses > 0 -- Build flag column if hasFlags then local flagContent = {} for i, flagData in ipairs(data.flags) do local borderStyle = "" if flagData.hasBorder then borderStyle = '|style="border:1px solid #a2a9b1;"' end local flagImage = '[[Coadan:' .. flagData.image .. '|' .. flagData.width .. borderStyle .. ']]' table.insert(flagContent, flagImage) end local combinedFlags = table.concat(flagContent, '<br/>') table.insert(imageCells, '<td align="center" style="' .. (hasArms and "width:58%; " or "width:100%; ") .. 'vertical-align:middle;">' .. combinedFlags .. '</td>' ) local flagCaptions = {} for i, flagData in ipairs(data.flags) do table.insert(flagCaptions, '<small>[[' .. flagData.link .. '|' .. flagData.label .. ']]</small>' ) end table.insert(captionCells, '<td align="center">' .. table.concat(flagCaptions, '<br/>') .. '</td>' ) end -- Build arms column if hasArms then local armsContent = {} for i, armsData in ipairs(data.armses) do local armsImage = '[[Coadan:' .. armsData.image .. '|' .. armsData.width .. ']]' table.insert(armsContent, armsImage) end local combinedArms = table.concat(armsContent, '<br/>') table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">' .. combinedArms .. '</td>' ) local armsCaptions = {} for i, armsData in ipairs(data.armses) do table.insert(armsCaptions, '<small>[[' .. armsData.link .. '|' .. armsData.label .. ']]</small>' ) end table.insert(captionCells, '<td align="center">' .. table.concat(armsCaptions, '<br/>') .. '</td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) -- FIXED: First check with ç, second check with plain c local chyndaa = getManual(args, {"çhyndaa_jarroo_raa", "chyndaa_jarroo_raa"}) local tessenLettyraghey = getManual(args, {"tessen-lettyraghey_jarroo_raa"}) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = motto, reference = reference and "<ref>" .. reference .. "</ref>" or nil, chyndaa = chyndaa, tessenLettyraghey = tessenLettyraghey } end local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = value.text, reference = getWikidataReference(statement), chyndaa = nil, tessenLettyraghey = nil } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthemData(args) local national = getManual(args, {"arrane_ashoonagh"}) local royal = getManual(args, {"arrane_reeoil"}) local other = getManual(args, {"arrane"}) local nationalReference = getManual(args, {"imraa_arrane_ashoonagh"}) local royalReference = getManual(args, {"imraa_arrane_reeoil"}) local otherReference = getManual(args, {"imraa_arrane"}) local nationalAudio = getManual(args, {"coadan_arrane_ashoonagh"}) local royalAudio = getManual(args, {"coadan_arrane_reeoil"}) local otherAudio = getManual(args, {"coadan_arrane"}) local nationalNote = getManual(args, {"noteyn_arrane_ashoonagh"}) local royalNote = getManual(args, {"noteyn_arrane_reeoil"}) local otherNote = getManual(args, {"noteyn_arrane"}) -- FIXED: The second strings are now correctly mapped to standard 'c' variations! local nationalChyndaa = getManual(args, {"çhyndaa_arrane_ashoonagh", "chyndaa_arrane_ashoonagh"}) local royalChyndaa = getManual(args, {"çhyndaa_arrane_reeoil", "chyndaa_arrane_reeoil"}) local otherChyndaa = getManual(args, {"çhyndaa_arrane", "chyndaa_arrane"}) local nationalTessen = getManual(args, {"tessen-lettyraghey_arrane_ashoonagh"}) local royalTessen = getManual(args, {"tessen-lettyraghey_arrane_reeoil"}) local otherTessen = getManual(args, {"tessen-lettyraghey_arrane"}) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and ("<ref>" .. nationalReference .. "</ref>") or nil, audio = nationalAudio, note = nationalNote, chyndaa = nationalChyndaa, tessenLettyraghey = nationalTessen } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and ("<ref>" .. royalReference .. "</ref>") or nil, audio = royalAudio, note = royalNote, chyndaa = royalChyndaa, tessenLettyraghey = royalTessen } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and ("<ref>" .. otherReference .. "</ref>") or nil, audio = otherAudio, note = otherNote, chyndaa = otherChyndaa, tessenLettyraghey = otherTessen } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, {"arrane_ashoonagh"}) local royal = getManual(args, {"arrane_reeoil"}) local other = getManual(args, {"arrane"}) local nationalReference = getManual(args, {"imraa_arrane_ashoonagh"}) local royalReference = getManual(args, {"imraa_arrane_reeoil"}) local otherReference = getManual(args, {"imraa_arrane"}) -- Updated to your preferred parameter nomenclature local nationalAudio = getManual(args, {"coadan_arrane_ashoonagh"}) local royalAudio = getManual(args, {"coadan_arrane_reeoil"}) local otherAudio = getManual(args, {"coadan_arrane"}) -- Updated to match the requested noteyn_ prefix pattern local nationalNote = getManual(args, {"noteyn_arrane_ashoonagh"}) local royalNote = getManual(args, {"noteyn_arrane_reeoil"}) local otherNote = getManual(args, {"noteyn_arrane"}) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and ("<ref>" .. nationalReference .. "</ref>") or nil, audio = nationalAudio, note = nationalNote } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and ("<ref>" .. royalReference .. "</ref>") or nil, audio = royalAudio, note = royalNote } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and ("<ref>" .. otherReference .. "</ref>") or nil, audio = otherAudio, note = otherNote } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS OUTPUT -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} -- 1. Format Motto Row if motto then local baseText = motto.text baseText = mw.ustring.gsub(baseText, '^"+', ''):gsub('"+$', ''):gsub('^“', ''):gsub('”$', '') if not mw.ustring.find(baseText, "%[%[") then baseText = "''" .. baseText .. "''" end if motto.tessenLettyraghey and motto.tessenLettyraghey ~= "" then baseText = baseText .. " (''" .. motto.tessenLettyraghey .. "'')" end if motto.chyndaa and motto.chyndaa ~= "" then baseText = baseText .. " <br/><small>“" .. motto.chyndaa .. "”</small>" end if motto.reference then baseText = baseText .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. baseText) end -- 2. Helper to format Anthem rows safely local function formatAnthemRow(label, anthemObj) if not anthemObj or not anthemObj.text then return nil end local cleanText = anthemObj.text cleanText = mw.ustring.gsub(cleanText, '^"+', ''):gsub('"+$', ''):gsub('^...:', ''):gsub('^“', ''):gsub('”$', '') if not mw.ustring.find(cleanText, "%[%[") then cleanText = '[[' .. cleanText .. '|' .. cleanText .. ']]' end local display = '“' .. cleanText .. '”' if anthemObj.tessenLettyraghey and anthemObj.tessenLettyraghey ~= "" then display = display .. " (''" .. anthemObj.tessenLettyraghey .. "'')" end if anthemObj.chyndaa and anthemObj.chyndaa ~= "" then display = display .. " <br/><small>“" .. anthemObj.chyndaa .. "”</small>" end if anthemObj.note and anthemObj.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { anthemObj.note } } display = display .. efnOut end if anthemObj.reference then display = display .. anthemObj.reference end if anthemObj.audio and anthemObj.audio ~= "" then display = display .. '<br/><div style="text-align:center; margin-top:0.3em;">[[Coadan:' .. anthemObj.audio .. '|center]]</div>' end return "'''" .. label .. ":&nbsp;'''" .. display end local nationalRow = formatAnthemRow("[[Arrane ashoonagh]]", anthems.national) if nationalRow then table.insert(rows, nationalRow) end local otherRow = formatAnthemRow("Anthym", anthems.other) if otherRow then table.insert(rows, otherRow) end local royalRow = formatAnthemRow("[[Arrane reeoil]]", anthems.royal) if royalRow then table.insert(rows, royalRow) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- local function getLanguagesFromWikidata() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P37") if not statements or #statements == 0 then return {} end local languages = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local langEntity = mw.wikibase.getEntity(id) if langEntity then local label = langEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(languages, { text = label, role = role, reference = getWikidataReference(statement) }) end end end end return languages end local function classifyLanguages(languages) local result = { official = {}, regional = {}, minority = {} } for _, language in ipairs(languages) do local role = language.role or "" local lowerRole = mw.ustring.lower(role) if mw.ustring.find(lowerRole, "minority") then table.insert(result.minority, language) elseif mw.ustring.find(lowerRole, "regional") then table.insert(result.regional, language) else table.insert(result.official, language) end end return result end -- Manx-specific collation: çh sorts as ch local function manxSort(a, b) local function normalize(text) -- Replace çh with ch for sorting purposes text = mw.ustring.lower(text) text = mw.ustring.gsub(text, "çh", "ch") return text end return normalize(a) < normalize(b) end local function joinLanguageList(languages) if not languages or #languages == 0 then return nil end -- Sort languages alphabetically with Manx collation table.sort(languages, function(a, b) return manxSort(a.text, b.text) end) local parts = {} for _, language in ipairs(languages) do local text = language.text -- Wrap language name in a wikilink (even if redlinked) text = '[[' .. text .. '|' .. text .. ']]' if language.reference then text = text .. language.reference end table.insert(parts, text) end if #parts == 0 then return nil end -- Return as hlist format return '<div class="hlist">' .. table.concat(parts, '&nbsp;· ') .. '</div>' end -- Splits text on a top-level separator character, without -- splitting inside {{...}} or [[...]] (so a piped wikilink -- like [[Country|Display]], or a nested template, doesn't -- get miscounted as two items). local function splitTopLevel(text, sep) local parts = {} local current = {} local depthCurly = 0 local depthSquare = 0 local len = mw.ustring.len(text) local i = 1 while i <= len do local two = mw.ustring.sub(text, i, i + 1) local one = mw.ustring.sub(text, i, i) if two == "{{" then depthCurly = depthCurly + 1 table.insert(current, two) i = i + 2 elseif two == "}}" and depthCurly > 0 then depthCurly = depthCurly - 1 table.insert(current, two) i = i + 2 elseif two == "[[" then depthSquare = depthSquare + 1 table.insert(current, two) i = i + 2 elseif two == "]]" and depthSquare > 0 then depthSquare = depthSquare - 1 table.insert(current, two) i = i + 2 elseif one == sep and depthCurly == 0 and depthSquare == 0 then table.insert(parts, table.concat(current)) current = {} i = i + 1 else table.insert(current, one) i = i + 1 end end table.insert(parts, table.concat(current)) return parts end -- Counts the items inside a {{hlist|...}}/{{flatlist|...}}/ -- {{ubl|...}}/{{unbulleted list|...}} template call (the -- convention most legacy articles already use for this -- field). Returns nil if the text isn't one of these, so -- the caller can fall back to a plain heuristic. -- Finds the first call to a template matching namePattern -- anywhere in text (not just at the start/whole-string), -- respecting nested {{...}} so a template argument that -- itself contains braces doesn't break the search. Returns -- the inner content (everything after the first "|") or nil -- if no such template call is found. local function findTemplateCall(text, namePattern) local searchPattern = "{{%s*" .. namePattern .. "%s*|" local matchStart, matchEnd = mw.ustring.find(text, searchPattern) if not matchStart then return nil end local contentStart = matchEnd + 1 local depth = 1 local i = contentStart local len = mw.ustring.len(text) while i <= len do local two = mw.ustring.sub(text, i, i + 1) if two == "{{" then depth = depth + 1 i = i + 2 elseif two == "}}" then depth = depth - 1 i = i + 2 if depth == 0 then local contentEnd = i - 3 return mw.ustring.sub(text, contentStart, contentEnd) end else i = i + 1 end end return nil end -- Pulls any <ref>...</ref> (or self-closing <ref .../>) tags -- out of text, returning the text with them removed plus the -- extracted ref markup (already-valid <ref> tags, ready to -- use as-is - not to be re-wrapped). Returns (text, nil) if -- none are found. local function extractReferences(text) if not text then return text, nil end local refs = {} local cleaned = mw.ustring.gsub(text, "<ref[^>]*>.-</ref>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.ustring.gsub(cleaned, "<ref[^>]*/>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.text.trim(cleaned) if #refs == 0 then return cleaned, nil end return cleaned, table.concat(refs) end local function countHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local segments = splitTopLevel(inner, "|") local count = 0 for _, segment in ipairs(segments) do local trimmedSegment = mw.text.trim(segment) -- Skip named parameters (class=, style=, indent=, etc.) -- rather than counting them as list items. if trimmedSegment ~= "" and not mw.ustring.find(trimmedSegment, "^[%w_%- ]+=") then count = count + 1 end end return count end -- Count of items in a manually-entered language/list field, -- used to decide between a singular ("çhengey") and plural -- ("çhengaghyn") label. Wikidata-derived lists are counted -- exactly (see getLanguageData). Handles the {{hlist}} family -- (searched for anywhere in the text, not just as the entire -- value, since editors often append a trailing <ref> after -- the closing "}}") most legacy articles already use; -- otherwise falls back to a plain comma-count heuristic. local function countListItems(text) if not text or text == "" then return 0 end local hlistCount = countHlistItems(text) if hlistCount then return hlistCount end local count = 0 for _ in mw.text.gsplit(text, ",", true) do count = count + 1 end return count end -- Resolves one language tier from its raw manual parameter: -- strips out any inline <ref> tags (used as-is, since they're -- already valid markup), counts the list on the ref-stripped -- text, then re-appends the extracted ref(s) and/or a manual -- imraa_ reference (which - unlike an inline <ref> - is raw -- citation text that still needs wrapping) to the display value. local function wrapInWikilink(text) -- If already has wikilink syntax, don't double-wrap if mw.ustring.find(text, "%[%[") then return text end -- Otherwise wrap in wikilink return '[[' .. text .. '|' .. text .. ']]' end -- Resolves one language tier from its raw manual parameter: -- strips out any inline <ref> tags, extracts/sorts the items, -- expands an {{efn}} note if provided, and appends reference strings. local function buildLanguageValue(raw, manualReference, manualNote, frame) if not raw or mw.ustring.lower(mw.text.trim(raw)) == "none" then return nil, 0 end local cleaned, inlineRefs = extractReferences(raw) local count = countListItems(cleaned) -- Try to extract from hlist template first local languageNames = extractHlistItems(cleaned) -- If not in hlist format, split by comma if not languageNames then languageNames = {} for part in mw.text.gsplit(cleaned, ",", true) do local trimmed = mw.text.trim(part) if trimmed ~= "" then table.insert(languageNames, trimmed) end end end -- Sort alphabetically with Manx collation table.sort(languageNames, manxSort) -- Wrap each in a wikilink and build hlist layout local parts = {} for _, name in ipairs(languageNames) do table.insert(parts, '[[' .. name .. '|' .. name .. ']]') end local display = '<div class="hlist">' .. table.concat(parts, '&nbsp;· ') .. '</div>' -- 1. Append the efn note directly after the language hlist block if provided if manualNote and manualNote ~= "" and frame then local efnOut = frame:expandTemplate{ title = "efn", args = { manualNote } } display = display .. efnOut end -- 2. Append standard citation references if inlineRefs then display = display .. inlineRefs end if manualReference then display = display .. "<ref>" .. manualReference .. "</ref>" end return display, count end local function getLanguageData(args, frame) local officialRaw = getManual(args, { "çhengaghyn_oikoil", "çhengey_oikoil" }) local officialReference = getManual(args, { "imraa_çhengaghyn_oikoil", "imraa_çhengey_oikoil" }) local regionalRaw = getManual(args, { "çhengaghyn_ardjynagh", "çhengey_ardjynagh" }) local regionalReference = getManual(args, { "imraa_çhengaghyn_ardjynagh", "imraa_çhengey_ardjynagh" }) local minorityRaw = getManual(args, { "mynçhengaghyn", "mynçhengey" }) local minorityReference = getManual(args, { "imraa_mynçhengaghyn", "imraa_mynçhengey" }) local otherRaw = getManual(args, { "çhengaghyn", "çhengey" }) local otherReference = getManual(args, { "imraa_çhengaghyn", "imraa_çhengey" }) local otherLabel = getManual(args, { "sorçh_çhengaghyn" }) -- Extract the new custom noteyn_ parameters local officialNote = getManual(args, {"noteyn_çhengaghyn_oikoil", "noteyn_çhengey_oikoil"}) local regionalNote = getManual(args, {"noteyn_çhengaghyn_ardjynagh", "noteyn_çhengey_ardjynagh"}) local minorityNote = getManual(args, {"noteyn_mynçhengaghyn", "noteyn_mynçhengey"}) local otherNote = getManual(args, {"noteyn_çhengaghyn", "noteyn_çhengey"}) local result = { otherLabel = otherLabel } -- Pass parameters down to buildLanguageValue along with frame context result.official, result.officialCount = buildLanguageValue(officialRaw, officialReference, officialNote, frame) result.regional, result.regionalCount = buildLanguageValue(regionalRaw, regionalReference, regionalNote, frame) result.minority, result.minorityCount = buildLanguageValue(minorityRaw, minorityReference, minorityNote, frame) result.other, result.otherCount = buildLanguageValue(otherRaw, otherReference, otherNote, frame) -- Only reach for Wikidata if none of the three primary tiers were set manually if not result.official and not result.regional and not result.minority then local classified = classifyLanguages(getLanguagesFromWikidata()) result.official = joinLanguageList(classified.official) result.officialCount = #classified.official result.regional = joinLanguageList(classified.regional) result.regionalCount = #classified.regional result.minority = joinLanguageList(classified.minority) result.minorityCount = #classified.minority end return result end local function buildLanguageRows(args, frame) -- Pass the frame execution reference through local data = getLanguageData(args, frame) local rows = {} if data.official then local officialLabel = data.officialCount > 1 and "[[Çhengey oikoil|Çhengaghyn oikoil]]" or "[[Çhengey oikoil]]" local officialRow = '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. officialLabel .. '</th><td style="vertical-align:top;">' .. data.official .. '</td></tr>' if data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn&nbsp;ardjynagh er&nbsp;enney" or "Çhengey&nbsp;ardjynagh er&nbsp;enney" officialRow = officialRow .. '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:normal;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th>' .. '<td style="vertical-align:top;">' .. data.regional .. '</td></tr>' end table.insert(rows, officialRow) elseif data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn ardjynagh er enney" or "Çhengey ardjynagh er enney" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th><td style="vertical-align:top;">' .. data.regional .. '</td></tr>' ) end if data.minority then local minorityLabel = data.minorityCount > 1 and "[[Mynçhengey|Mynçhengaghyn]]" or "[[Mynçhengey]]" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. minorityLabel .. '</th><td style="vertical-align:top;">' .. data.minority .. '</td></tr>' ) end if data.other then local otherLabel = data.otherLabel or (data.otherCount > 1 and "Çhengaghyn" or "Çhengey") table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. otherLabel .. '</th><td style="vertical-align:top;">' .. data.other .. '</td></tr>' ) end if #rows == 0 then return nil end return table.concat(rows) end function p.languages(frame) local args = getArgs(frame) -- Updated to pass frame context downward cleanly return buildLanguageRows(args, frame) end local function getLanguageData(args) local officialRaw = getManual(args, { "çhengaghyn_oikoil", "çhengey_oikoil" }) local officialReference = getManual(args, { "imraa_çhengaghyn_oikoil", "imraa_çhengey_oikoil" }) local regionalRaw = getManual(args, { "çhengaghyn_ardjynagh", "çhengey_ardjynagh" }) local regionalReference = getManual(args, { "imraa_çhengaghyn_ardjynagh", "imraa_çhengey_ardjynagh" }) local minorityRaw = getManual(args, { "mynçhengaghyn", "mynçhengey" }) local minorityReference = getManual(args, { "imraa_mynçhengaghyn", "imraa_mynçhengey" }) local otherRaw = getManual(args, { "çhengaghyn", "çhengey" }) local otherReference = getManual(args, { "imraa_çhengaghyn", "imraa_çhengey" }) local otherLabel = getManual(args, { "sorçh_çhengaghyn" }) local result = { otherLabel = otherLabel } result.official, result.officialCount = buildLanguageValue(officialRaw, officialReference) result.regional, result.regionalCount = buildLanguageValue(regionalRaw, regionalReference) result.minority, result.minorityCount = buildLanguageValue(minorityRaw, minorityReference) result.other, result.otherCount = buildLanguageValue(otherRaw, otherReference) -- Only reach for Wikidata if none of the three tiers -- were set manually - a manual "none" or partial set -- of overrides always wins over the auto-fetch. if not result.official and not result.regional and not result.minority then local classified = classifyLanguages(getLanguagesFromWikidata()) result.official = joinLanguageList(classified.official) result.officialCount = #classified.official result.regional = joinLanguageList(classified.regional) result.regionalCount = #classified.regional result.minority = joinLanguageList(classified.minority) result.minorityCount = #classified.minority end return result end local function buildLanguageRows(args) local data = getLanguageData(args) local rows = {} if data.official then local officialLabel = data.officialCount > 1 and "[[Çhengey oikoil|Çhengaghyn oikoil]]" or "[[Çhengey oikoil]]" local officialRow = '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. officialLabel .. '</th><td style="vertical-align:top;">' .. data.official .. '</td></tr>' if data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn&nbsp;ardjynagh er&nbsp;enney" or "Çhengey&nbsp;ardjynagh er&nbsp;enney" officialRow = officialRow .. '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:normal;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th>' .. '<td style="vertical-align:top;">' .. data.regional .. '</td></tr>' end table.insert(rows, officialRow) elseif data.regional then -- Regional recognised even without a separate -- official-language statement. local regionalLabel = data.regionalCount > 1 and "Çhengaghyn ardjynagh er enney" or "Çhengey ardjynagh er enney" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th><td style="vertical-align:top;">' .. data.regional .. '</td></tr>' ) end if data.minority then local minorityLabel = data.minorityCount > 1 and "[[Mynçhengey|Mynçhengaghyn]]" or "[[Mynçhengey]]" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. minorityLabel .. '</th><td style="vertical-align:top;">' .. data.minority .. '</td></tr>' ) end if data.other then local otherLabel = data.otherLabel or (data.otherCount > 1 and "Çhengaghyn" or "Çhengey") table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. otherLabel .. '</th><td style="vertical-align:top;">' .. data.other .. '</td></tr>' ) end if #rows == 0 then return nil end return table.concat(rows) end function p.languages(frame) local args = getArgs(frame) return buildLanguageRows(args) end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCityEntityFromTitle(value) local title = normaliseCityName(value) if title == "" then return nil end local entityId = mw.wikibase.getEntityIdForTitle(title) if not entityId then return nil end return mw.wikibase.getEntity(entityId) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end -- Extract custom note parameter local note = getManual(args, {"noteyn_preeu-valley"}) if capital then return { text = capital, entity = getCityEntityFromTitle(capital), reference = nil, note = note } end local entity, statement = getWikidataItem("P36") if entity then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or entity:getLabel(), entity = entity, reference = getWikidataReference(statement), note = nil -- Wikidata items don't have manual wiki notes } end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end -- Extract custom note parameter local note = getManual(args, {"noteyn_ynnyd_reiragh"}) if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil, note = note } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end -- Extract custom note parameter local note = getManual(args, {"noteyn_balley_smoo"}) if city then return { text = city, entity = getCityEntityFromTitle(city), reference = nil, note = note } end local country = mw.wikibase.getEntityObject() if not country then return nil end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id local target = mw.wikibase.getEntity(targetId) if target and not isDisambiguationPage(target) then local sitelink = target:getSitelink("gvwiki") return { text = sitelink or target:getLabel(), entity = target, reference = getWikidataReference(statement), note = nil } end end end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then return { text = city, entity = getCityEntityFromTitle(city), reference = nil } end local country = mw.wikibase.getEntityObject() if not country then return nil end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id local target = mw.wikibase.getEntity(targetId) if target and not isDisambiguationPage(target) then local sitelink = target:getSitelink("gvwiki") return { text = sitelink or target:getLabel(), entity = target, reference = getWikidataReference(statement) } end end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) return { capital = getCapitalData(args), administrative = getAdministrativeCentreData(args), largest = getLargestCityData(args), labels = getCityLabels(args) } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end local title = nil if city.entity then title = city.entity:getSitelink("gvwiki") end if not title or title == "" then title = normaliseCityName(city.text) end if not title or title == "" then return "" end return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest -- Helper function to render the data chunk cleanly local function renderCityCell(cityObj) local text = makeCityLink(cityObj) -- Append the efn footnote tag if it exists if cityObj.note and cityObj.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { cityObj.note } } text = text .. efnOut end -- Append standard reference citations if cityObj.reference then text = text .. cityObj.reference end -- Append coordinates block on a new line below the name if cityObj.entity then local coordinates = makeCoordinates(cityObj.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text end if capital then return renderCityCell(capital) elseif administrative then return renderCityCell(administrative) elseif largest then return renderCityCell(largest) end return nil end function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} local function formatLegacyRow(label, cityObj) local text = makeCityLink(cityObj) if cityObj.note and cityObj.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { cityObj.note } } text = text .. efnOut end if cityObj.reference then text = text .. cityObj.reference end if cityObj.entity then local coordinates = makeCoordinates(cityObj.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end return "'''" .. label .. "''': " .. text end if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end table.insert(rows, formatLegacyRow(label, capital)) end if administrative then local label = labels.administrative or "Ynnyd reiragh" table.insert(rows, formatLegacyRow(label, administrative)) end if largest then table.insert(rows, formatLegacyRow("Balley smoo", largest)) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -------------------------------------------------- -- HEADER -------------------------------------------------- do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -------------------------------------------------- -- FLAG / ARMS -------------------------------------------------- do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -------------------------------------------------- -- MOTTO / ANTHEM -------------------------------------------------- do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -------------------------------------------------- -- CAPITAL / ADMINISTRATIVE CENTRE / LARGEST CITY -------------------------------------------------- do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels -- Add one divider before the city section only. if capital or administrative or largest then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '"></td></tr>' ) end -- Capital if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Administrative centre if administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Largest city if largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- do local languageRows = buildLanguageRows(args) if languageRows then table.insert(rows, languageRows) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p 9g7rs0oxokztj4qtmk9drvono38lh5j 392898 392897 2026-09-07T02:13:07Z MacTire02 219 ++ 392898 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -- Extract items from an hlist/flatlist/ubl template local function extractHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local items = {} local segments = splitTopLevel(inner, "|") for _, segment in ipairs(segments) do local trimmed = mw.text.trim(segment) -- Skip named parameters (class=, style=, etc.) if trimmed ~= "" and not mw.ustring.find(trimmed, "^[%w_%- ]+=") then -- Extract just the link text if it's a wikilink local linkText = mw.ustring.match(trimmed, "%[%[.-|(.+)%]%]") or mw.ustring.match(trimmed, "%[%[(.+)%]%]") or trimmed table.insert(items, mw.text.trim(linkText)) end end return items end -------------------------------------------------- -- DISAMBIGUATION GUARD -------------------------------------------------- -- Some Wikidata statements resolve to a general/ambiguous -- item rather than the specific thing we want (e.g. a -- country's "most populous urban area" pointing at the -- ambiguous "New York" (Q22654) instead of "New York City" -- (Q60)). Skip anything flagged as a disambiguation page. local function isDisambiguationPage(entity) if not entity then return false end local statements = entity:getBestStatements("P31") if not statements then return false end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" and mainsnak.datavalue.value.id == "Q4167410" then return true end end return false end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity and not isDisambiguationPage(linkedEntity) then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- FLAG BORDER CHECK -------------------------------------------------- -- List of countries with non-rectangular flags (no border needed) local NON_RECTANGULAR_FLAGS = { ["Flag of Nepal.svg"] = true, ["Flag of Ohio.svg"] = true, ["Flag of Switzerland.svg"] = true, } -- Check if a flag needs a border local function needsFlagBorder(flagFile) if not flagFile then return true end if NON_RECTANGULAR_FLAGS[flagFile] then return false end local lowerFile = mw.ustring.lower(flagFile) if mw.ustring.find(lowerFile, "nepal") then return false end return true end -------------------------------------------------- -- MULTI-FLAG SUPPORT -------------------------------------------------- local function getFlagData(args) -- Get primary flag local flag = getManual(args, {"jalloo_brattagh"}) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end -- Get second flag (if any) local flag2 = getManual(args, {"jalloo_brattagh_2", "jalloo_brattagh_elley"}) if flag2 and mw.ustring.lower(flag2) == "none" then flag2 = nil elseif not flag2 then flag2 = getWikidataImage("P163") end -- Get arms local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end -- Get second arms (if any) local arms2 = getManual(args, { "jalloo_armys_2", "jalloo_cleinney_2" }) if arms2 and mw.ustring.lower(arms2) == "none" then arms2 = nil elseif not arms2 then arms2 = getWikidataImage("P237") end if not flag and not flag2 and not arms and not arms2 then return nil end local name = getCountryGenitive(args) or "" local data = { flags = {}, armses = {} } -- Primary flag if flag then local flagWidth = getManual(args, {"lheead_brattagh"}) or "125px" local hasBorder = needsFlagBorder(flag) table.insert(data.flags, { image = flag, width = flagWidth, hasBorder = hasBorder, link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh"}) or "Brattagh", isPrimary = true }) end -- Second flag if flag2 then local flag2Width = getManual(args, {"lheead_brattagh_2", "lheead_brattagh"}) or "100px" local hasBorder2 = needsFlagBorder(flag2) table.insert(data.flags, { image = flag2, width = flag2Width, hasBorder = hasBorder2, link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh_2"}) or "Brattagh elley", isPrimary = false }) end -- Primary arms if arms then local kind = getManual(args, {"art_sorçh_cowrey"}) or getManual(args, {"sorçh_cowrey"}) or "Armys" table.insert(data.armses, { image = arms, width = getManual(args, {"lheead_armys", "lheead_cleinney", "lheead_cowrey"}) or "85px", link = kind .. " " .. name, label = getManual(args, {"sorçh_cowrey"}) or "Armys", isPrimary = true }) end -- Second arms if arms2 then table.insert(data.armses, { image = arms2, width = getManual(args, {"lheead_armys_2", "lheead_cleinney_2"}) or "85px", link = "Armys " .. name, label = getManual(args, {"sorçh_cowrey_2"}) or "Armys", isPrimary = false }) end return data end -------------------------------------------------- -- UPDATED getFlagArmsData (replaces old function) -------------------------------------------------- local function getFlagArmsData(args) return getFlagData(args) end -------------------------------------------------- -- FLAG / ARMS BLOCK (UPDATED) -------------------------------------------------- local function buildFlagArmsBlock(args) local data = getFlagArmsData(args) if not data then return nil end local imageCells = {} local captionCells = {} local hasFlags = #data.flags > 0 local hasArms = #data.armses > 0 -- Build flag column if hasFlags then local flagContent = {} for i, flagData in ipairs(data.flags) do local borderStyle = "" if flagData.hasBorder then borderStyle = '|style="border:1px solid #a2a9b1;"' end local flagImage = '[[Coadan:' .. flagData.image .. '|' .. flagData.width .. borderStyle .. ']]' table.insert(flagContent, flagImage) end local combinedFlags = table.concat(flagContent, '<br/>') table.insert(imageCells, '<td align="center" style="' .. (hasArms and "width:58%; " or "width:100%; ") .. 'vertical-align:middle;">' .. combinedFlags .. '</td>' ) local flagCaptions = {} for i, flagData in ipairs(data.flags) do table.insert(flagCaptions, '<small>[[' .. flagData.link .. '|' .. flagData.label .. ']]</small>' ) end table.insert(captionCells, '<td align="center">' .. table.concat(flagCaptions, '<br/>') .. '</td>' ) end -- Build arms column if hasArms then local armsContent = {} for i, armsData in ipairs(data.armses) do local armsImage = '[[Coadan:' .. armsData.image .. '|' .. armsData.width .. ']]' table.insert(armsContent, armsImage) end local combinedArms = table.concat(armsContent, '<br/>') table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">' .. combinedArms .. '</td>' ) local armsCaptions = {} for i, armsData in ipairs(data.armses) do table.insert(armsCaptions, '<small>[[' .. armsData.link .. '|' .. armsData.label .. ']]</small>' ) end table.insert(captionCells, '<td align="center">' .. table.concat(armsCaptions, '<br/>') .. '</td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) -- Fully interchangeable translation parameters local chyndaa = getManual(args, {"çhyndaa_jarroo_raa", "chyndaa_jarroo_raa"}) local tessenLettyraghey = getManual(args, {"tessen-lettyraghey_jarroo_raa"}) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = motto, reference = reference and "<ref>" .. reference .. "</ref>" or nil, chyndaa = chyndaa, tessenLettyraghey = tessenLettyraghey } end local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = value.text, reference = getWikidataReference(statement), chyndaa = nil, tessenLettyraghey = nil } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthemData(args) local national = getManual(args, {"arrane_ashoonagh"}) local royal = getManual(args, {"arrane_reeoil"}) local other = getManual(args, {"arrane"}) local nationalReference = getManual(args, {"imraa_arrane_ashoonagh"}) local royalReference = getManual(args, {"imraa_arrane_reeoil"}) local otherReference = getManual(args, {"imraa_arrane"}) local nationalAudio = getManual(args, {"coadan_arrane_ashoonagh"}) local royalAudio = getManual(args, {"coadan_arrane_reeoil"}) local otherAudio = getManual(args, {"coadan_arrane"}) local nationalNote = getManual(args, {"noteyn_arrane_ashoonagh"}) local royalNote = getManual(args, {"noteyn_arrane_reeoil"}) local otherNote = getManual(args, {"noteyn_arrane"}) -- Synchronized translation mappings (Interchangeable ç and c) local nationalChyndaa = getManual(args, {"çhyndaa_arrane_ashoonagh", "chyndaa_arrane_ashoonagh"}) local royalChyndaa = getManual(args, {"çhyndaa_arrane_reeoil", "chyndaa_arrane_reeoil"}) local otherChyndaa = getManual(args, {"çhyndaa_arrane", "chyndaa_arrane"}) -- Synchronized custom transliteration parameters local nationalTessen = getManual(args, {"tessen-lettyraghey_arrane_ashoonagh"}) local royalTessen = getManual(args, {"tessen-lettyraghey_arrane_reeoil"}) local otherTessen = getManual(args, {"tessen-lettyraghey_arrane"}) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and ("<ref>" .. nationalReference .. "</ref>") or nil, audio = nationalAudio, note = nationalNote, chyndaa = nationalChyndaa, tessenLettyraghey = nationalTessen } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and ("<ref>" .. royalReference .. "</ref>") or nil, audio = royalAudio, note = royalNote, chyndaa = royalChyndaa, tessenLettyraghey = royalTessen } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and ("<ref>" .. otherReference .. "</ref>") or nil, audio = otherAudio, note = otherNote, chyndaa = otherChyndaa, tessenLettyraghey = otherTessen } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- CLASSIFY ANTHEMS -------------------------------------------------- local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, {"arrane_ashoonagh"}) local royal = getManual(args, {"arrane_reeoil"}) local other = getManual(args, {"arrane"}) local nationalReference = getManual(args, {"imraa_arrane_ashoonagh"}) local royalReference = getManual(args, {"imraa_arrane_reeoil"}) local otherReference = getManual(args, {"imraa_arrane"}) -- Updated to your preferred parameter nomenclature local nationalAudio = getManual(args, {"coadan_arrane_ashoonagh"}) local royalAudio = getManual(args, {"coadan_arrane_reeoil"}) local otherAudio = getManual(args, {"coadan_arrane"}) -- Updated to match the requested noteyn_ prefix pattern local nationalNote = getManual(args, {"noteyn_arrane_ashoonagh"}) local royalNote = getManual(args, {"noteyn_arrane_reeoil"}) local otherNote = getManual(args, {"noteyn_arrane"}) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and ("<ref>" .. nationalReference .. "</ref>") or nil, audio = nationalAudio, note = nationalNote } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and ("<ref>" .. royalReference .. "</ref>") or nil, audio = royalAudio, note = royalNote } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and ("<ref>" .. otherReference .. "</ref>") or nil, audio = otherAudio, note = otherNote } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS OUTPUT -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} -- 1. Format Motto Row if motto then local baseText = motto.text -- Safely remove outer quotation marks if they exist natively without breaking non-Latin scripts baseText = mw.text.trim(baseText):gsub('^["“]', ''):gsub('["”]$', '') -- Apply italics for raw text unless it already contains wiki-link markup if not mw.ustring.find(baseText, "%[%[") then baseText = "''" .. baseText .. "''" end if motto.tessenLettyraghey and motto.tessenLettyraghey ~= "" then baseText = baseText .. " (''" .. motto.tessenLettyraghey .. "'')" end if motto.chyndaa and motto.chyndaa ~= "" then baseText = baseText .. " <br/><small>“" .. motto.chyndaa .. "”</small>" end if motto.reference then baseText = baseText .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. baseText) end -- 2. Helper to format Anthem rows safely local function formatAnthemRow(label, anthemObj) if not anthemObj or not anthemObj.text then return nil end local cleanText = anthemObj.text -- FIXED: Stripped out the destructive gsub string-breaking filter pattern cleanText = mw.text.trim(cleanText):gsub('^["“]', ''):gsub('["”]$', '') if not mw.ustring.find(cleanText, "%[%[") then cleanText = '[[' .. cleanText .. '|' .. cleanText .. ']]' end local display = '“' .. cleanText .. '”' if anthemObj.tessenLettyraghey and anthemObj.tessenLettyraghey ~= "" then display = display .. " (''" .. anthemObj.tessenLettyraghey .. "'')" end if anthemObj.chyndaa and anthemObj.chyndaa ~= "" then display = display .. " <br/><small>“" .. anthemObj.chyndaa .. "”</small>" end if anthemObj.note and anthemObj.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { anthemObj.note } } display = display .. efnOut end if anthemObj.reference then display = display .. anthemObj.reference end if anthemObj.audio and anthemObj.audio ~= "" then display = display .. '<br/><div style="text-align:center; margin-top:0.3em;">[[Coadan:' .. anthemObj.audio .. '|center]]</div>' end return "'''" .. label .. ":&nbsp;'''" .. display end local nationalRow = formatAnthemRow("[[Arrane ashoonagh]]", anthems.national) if nationalRow then table.insert(rows, nationalRow) end local otherRow = formatAnthemRow("Anthym", anthems.other) if otherRow then table.insert(rows, otherRow) end local royalRow = formatAnthemRow("[[Arrane reeoil]]", anthems.royal) if royalRow then table.insert(rows, royalRow) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- local function getLanguagesFromWikidata() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P37") if not statements or #statements == 0 then return {} end local languages = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local langEntity = mw.wikibase.getEntity(id) if langEntity then local label = langEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(languages, { text = label, role = role, reference = getWikidataReference(statement) }) end end end end return languages end local function classifyLanguages(languages) local result = { official = {}, regional = {}, minority = {} } for _, language in ipairs(languages) do local role = language.role or "" local lowerRole = mw.ustring.lower(role) if mw.ustring.find(lowerRole, "minority") then table.insert(result.minority, language) elseif mw.ustring.find(lowerRole, "regional") then table.insert(result.regional, language) else table.insert(result.official, language) end end return result end -- Manx-specific collation: çh sorts as ch local function manxSort(a, b) local function normalize(text) -- Replace çh with ch for sorting purposes text = mw.ustring.lower(text) text = mw.ustring.gsub(text, "çh", "ch") return text end return normalize(a) < normalize(b) end local function joinLanguageList(languages) if not languages or #languages == 0 then return nil end -- Sort languages alphabetically with Manx collation table.sort(languages, function(a, b) return manxSort(a.text, b.text) end) local parts = {} for _, language in ipairs(languages) do local text = language.text -- Wrap language name in a wikilink (even if redlinked) text = '[[' .. text .. '|' .. text .. ']]' if language.reference then text = text .. language.reference end table.insert(parts, text) end if #parts == 0 then return nil end -- Return as hlist format return '<div class="hlist">' .. table.concat(parts, '&nbsp;· ') .. '</div>' end -- Splits text on a top-level separator character, without -- splitting inside {{...}} or [[...]] (so a piped wikilink -- like [[Country|Display]], or a nested template, doesn't -- get miscounted as two items). local function splitTopLevel(text, sep) local parts = {} local current = {} local depthCurly = 0 local depthSquare = 0 local len = mw.ustring.len(text) local i = 1 while i <= len do local two = mw.ustring.sub(text, i, i + 1) local one = mw.ustring.sub(text, i, i) if two == "{{" then depthCurly = depthCurly + 1 table.insert(current, two) i = i + 2 elseif two == "}}" and depthCurly > 0 then depthCurly = depthCurly - 1 table.insert(current, two) i = i + 2 elseif two == "[[" then depthSquare = depthSquare + 1 table.insert(current, two) i = i + 2 elseif two == "]]" and depthSquare > 0 then depthSquare = depthSquare - 1 table.insert(current, two) i = i + 2 elseif one == sep and depthCurly == 0 and depthSquare == 0 then table.insert(parts, table.concat(current)) current = {} i = i + 1 else table.insert(current, one) i = i + 1 end end table.insert(parts, table.concat(current)) return parts end -- Counts the items inside a {{hlist|...}}/{{flatlist|...}}/ -- {{ubl|...}}/{{unbulleted list|...}} template call (the -- convention most legacy articles already use for this -- field). Returns nil if the text isn't one of these, so -- the caller can fall back to a plain heuristic. -- Finds the first call to a template matching namePattern -- anywhere in text (not just at the start/whole-string), -- respecting nested {{...}} so a template argument that -- itself contains braces doesn't break the search. Returns -- the inner content (everything after the first "|") or nil -- if no such template call is found. local function findTemplateCall(text, namePattern) local searchPattern = "{{%s*" .. namePattern .. "%s*|" local matchStart, matchEnd = mw.ustring.find(text, searchPattern) if not matchStart then return nil end local contentStart = matchEnd + 1 local depth = 1 local i = contentStart local len = mw.ustring.len(text) while i <= len do local two = mw.ustring.sub(text, i, i + 1) if two == "{{" then depth = depth + 1 i = i + 2 elseif two == "}}" then depth = depth - 1 i = i + 2 if depth == 0 then local contentEnd = i - 3 return mw.ustring.sub(text, contentStart, contentEnd) end else i = i + 1 end end return nil end -- Pulls any <ref>...</ref> (or self-closing <ref .../>) tags -- out of text, returning the text with them removed plus the -- extracted ref markup (already-valid <ref> tags, ready to -- use as-is - not to be re-wrapped). Returns (text, nil) if -- none are found. local function extractReferences(text) if not text then return text, nil end local refs = {} local cleaned = mw.ustring.gsub(text, "<ref[^>]*>.-</ref>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.ustring.gsub(cleaned, "<ref[^>]*/>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.text.trim(cleaned) if #refs == 0 then return cleaned, nil end return cleaned, table.concat(refs) end local function countHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local segments = splitTopLevel(inner, "|") local count = 0 for _, segment in ipairs(segments) do local trimmedSegment = mw.text.trim(segment) -- Skip named parameters (class=, style=, indent=, etc.) -- rather than counting them as list items. if trimmedSegment ~= "" and not mw.ustring.find(trimmedSegment, "^[%w_%- ]+=") then count = count + 1 end end return count end -- Count of items in a manually-entered language/list field, -- used to decide between a singular ("çhengey") and plural -- ("çhengaghyn") label. Wikidata-derived lists are counted -- exactly (see getLanguageData). Handles the {{hlist}} family -- (searched for anywhere in the text, not just as the entire -- value, since editors often append a trailing <ref> after -- the closing "}}") most legacy articles already use; -- otherwise falls back to a plain comma-count heuristic. local function countListItems(text) if not text or text == "" then return 0 end local hlistCount = countHlistItems(text) if hlistCount then return hlistCount end local count = 0 for _ in mw.text.gsplit(text, ",", true) do count = count + 1 end return count end -- Resolves one language tier from its raw manual parameter: -- strips out any inline <ref> tags (used as-is, since they're -- already valid markup), counts the list on the ref-stripped -- text, then re-appends the extracted ref(s) and/or a manual -- imraa_ reference (which - unlike an inline <ref> - is raw -- citation text that still needs wrapping) to the display value. local function wrapInWikilink(text) -- If already has wikilink syntax, don't double-wrap if mw.ustring.find(text, "%[%[") then return text end -- Otherwise wrap in wikilink return '[[' .. text .. '|' .. text .. ']]' end -- Resolves one language tier from its raw manual parameter: -- strips out any inline <ref> tags, extracts/sorts the items, -- expands an {{efn}} note if provided, and appends reference strings. local function buildLanguageValue(raw, manualReference, manualNote, frame) if not raw or mw.ustring.lower(mw.text.trim(raw)) == "none" then return nil, 0 end local cleaned, inlineRefs = extractReferences(raw) local count = countListItems(cleaned) -- Try to extract from hlist template first local languageNames = extractHlistItems(cleaned) -- If not in hlist format, split by comma if not languageNames then languageNames = {} for part in mw.text.gsplit(cleaned, ",", true) do local trimmed = mw.text.trim(part) if trimmed ~= "" then table.insert(languageNames, trimmed) end end end -- Sort alphabetically with Manx collation table.sort(languageNames, manxSort) -- Wrap each in a wikilink and build hlist layout local parts = {} for _, name in ipairs(languageNames) do table.insert(parts, '[[' .. name .. '|' .. name .. ']]') end local display = '<div class="hlist">' .. table.concat(parts, '&nbsp;· ') .. '</div>' -- 1. Append the efn note directly after the language hlist block if provided if manualNote and manualNote ~= "" and frame then local efnOut = frame:expandTemplate{ title = "efn", args = { manualNote } } display = display .. efnOut end -- 2. Append standard citation references if inlineRefs then display = display .. inlineRefs end if manualReference then display = display .. "<ref>" .. manualReference .. "</ref>" end return display, count end local function getLanguageData(args, frame) local officialRaw = getManual(args, { "çhengaghyn_oikoil", "çhengey_oikoil" }) local officialReference = getManual(args, { "imraa_çhengaghyn_oikoil", "imraa_çhengey_oikoil" }) local regionalRaw = getManual(args, { "çhengaghyn_ardjynagh", "çhengey_ardjynagh" }) local regionalReference = getManual(args, { "imraa_çhengaghyn_ardjynagh", "imraa_çhengey_ardjynagh" }) local minorityRaw = getManual(args, { "mynçhengaghyn", "mynçhengey" }) local minorityReference = getManual(args, { "imraa_mynçhengaghyn", "imraa_mynçhengey" }) local otherRaw = getManual(args, { "çhengaghyn", "çhengey" }) local otherReference = getManual(args, { "imraa_çhengaghyn", "imraa_çhengey" }) local otherLabel = getManual(args, { "sorçh_çhengaghyn" }) -- Extract the new custom noteyn_ parameters local officialNote = getManual(args, {"noteyn_çhengaghyn_oikoil", "noteyn_çhengey_oikoil"}) local regionalNote = getManual(args, {"noteyn_çhengaghyn_ardjynagh", "noteyn_çhengey_ardjynagh"}) local minorityNote = getManual(args, {"noteyn_mynçhengaghyn", "noteyn_mynçhengey"}) local otherNote = getManual(args, {"noteyn_çhengaghyn", "noteyn_çhengey"}) local result = { otherLabel = otherLabel } -- Pass parameters down to buildLanguageValue along with frame context result.official, result.officialCount = buildLanguageValue(officialRaw, officialReference, officialNote, frame) result.regional, result.regionalCount = buildLanguageValue(regionalRaw, regionalReference, regionalNote, frame) result.minority, result.minorityCount = buildLanguageValue(minorityRaw, minorityReference, minorityNote, frame) result.other, result.otherCount = buildLanguageValue(otherRaw, otherReference, otherNote, frame) -- Only reach for Wikidata if none of the three primary tiers were set manually if not result.official and not result.regional and not result.minority then local classified = classifyLanguages(getLanguagesFromWikidata()) result.official = joinLanguageList(classified.official) result.officialCount = #classified.official result.regional = joinLanguageList(classified.regional) result.regionalCount = #classified.regional result.minority = joinLanguageList(classified.minority) result.minorityCount = #classified.minority end return result end local function buildLanguageRows(args, frame) -- Pass the frame execution reference through local data = getLanguageData(args, frame) local rows = {} if data.official then local officialLabel = data.officialCount > 1 and "[[Çhengey oikoil|Çhengaghyn oikoil]]" or "[[Çhengey oikoil]]" local officialRow = '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. officialLabel .. '</th><td style="vertical-align:top;">' .. data.official .. '</td></tr>' if data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn&nbsp;ardjynagh er&nbsp;enney" or "Çhengey&nbsp;ardjynagh er&nbsp;enney" officialRow = officialRow .. '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:normal;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th>' .. '<td style="vertical-align:top;">' .. data.regional .. '</td></tr>' end table.insert(rows, officialRow) elseif data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn ardjynagh er enney" or "Çhengey ardjynagh er enney" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th><td style="vertical-align:top;">' .. data.regional .. '</td></tr>' ) end if data.minority then local minorityLabel = data.minorityCount > 1 and "[[Mynçhengey|Mynçhengaghyn]]" or "[[Mynçhengey]]" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. minorityLabel .. '</th><td style="vertical-align:top;">' .. data.minority .. '</td></tr>' ) end if data.other then local otherLabel = data.otherLabel or (data.otherCount > 1 and "Çhengaghyn" or "Çhengey") table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. otherLabel .. '</th><td style="vertical-align:top;">' .. data.other .. '</td></tr>' ) end if #rows == 0 then return nil end return table.concat(rows) end function p.languages(frame) local args = getArgs(frame) -- Updated to pass frame context downward cleanly return buildLanguageRows(args, frame) end local function getLanguageData(args) local officialRaw = getManual(args, { "çhengaghyn_oikoil", "çhengey_oikoil" }) local officialReference = getManual(args, { "imraa_çhengaghyn_oikoil", "imraa_çhengey_oikoil" }) local regionalRaw = getManual(args, { "çhengaghyn_ardjynagh", "çhengey_ardjynagh" }) local regionalReference = getManual(args, { "imraa_çhengaghyn_ardjynagh", "imraa_çhengey_ardjynagh" }) local minorityRaw = getManual(args, { "mynçhengaghyn", "mynçhengey" }) local minorityReference = getManual(args, { "imraa_mynçhengaghyn", "imraa_mynçhengey" }) local otherRaw = getManual(args, { "çhengaghyn", "çhengey" }) local otherReference = getManual(args, { "imraa_çhengaghyn", "imraa_çhengey" }) local otherLabel = getManual(args, { "sorçh_çhengaghyn" }) local result = { otherLabel = otherLabel } result.official, result.officialCount = buildLanguageValue(officialRaw, officialReference) result.regional, result.regionalCount = buildLanguageValue(regionalRaw, regionalReference) result.minority, result.minorityCount = buildLanguageValue(minorityRaw, minorityReference) result.other, result.otherCount = buildLanguageValue(otherRaw, otherReference) -- Only reach for Wikidata if none of the three tiers -- were set manually - a manual "none" or partial set -- of overrides always wins over the auto-fetch. if not result.official and not result.regional and not result.minority then local classified = classifyLanguages(getLanguagesFromWikidata()) result.official = joinLanguageList(classified.official) result.officialCount = #classified.official result.regional = joinLanguageList(classified.regional) result.regionalCount = #classified.regional result.minority = joinLanguageList(classified.minority) result.minorityCount = #classified.minority end return result end local function buildLanguageRows(args) local data = getLanguageData(args) local rows = {} if data.official then local officialLabel = data.officialCount > 1 and "[[Çhengey oikoil|Çhengaghyn oikoil]]" or "[[Çhengey oikoil]]" local officialRow = '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. officialLabel .. '</th><td style="vertical-align:top;">' .. data.official .. '</td></tr>' if data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn&nbsp;ardjynagh er&nbsp;enney" or "Çhengey&nbsp;ardjynagh er&nbsp;enney" officialRow = officialRow .. '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:normal;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th>' .. '<td style="vertical-align:top;">' .. data.regional .. '</td></tr>' end table.insert(rows, officialRow) elseif data.regional then -- Regional recognised even without a separate -- official-language statement. local regionalLabel = data.regionalCount > 1 and "Çhengaghyn ardjynagh er enney" or "Çhengey ardjynagh er enney" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th><td style="vertical-align:top;">' .. data.regional .. '</td></tr>' ) end if data.minority then local minorityLabel = data.minorityCount > 1 and "[[Mynçhengey|Mynçhengaghyn]]" or "[[Mynçhengey]]" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. minorityLabel .. '</th><td style="vertical-align:top;">' .. data.minority .. '</td></tr>' ) end if data.other then local otherLabel = data.otherLabel or (data.otherCount > 1 and "Çhengaghyn" or "Çhengey") table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. otherLabel .. '</th><td style="vertical-align:top;">' .. data.other .. '</td></tr>' ) end if #rows == 0 then return nil end return table.concat(rows) end function p.languages(frame) local args = getArgs(frame) return buildLanguageRows(args) end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCityEntityFromTitle(value) local title = normaliseCityName(value) if title == "" then return nil end local entityId = mw.wikibase.getEntityIdForTitle(title) if not entityId then return nil end return mw.wikibase.getEntity(entityId) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end -- Extract custom note parameter local note = getManual(args, {"noteyn_preeu-valley"}) if capital then return { text = capital, entity = getCityEntityFromTitle(capital), reference = nil, note = note } end local entity, statement = getWikidataItem("P36") if entity then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or entity:getLabel(), entity = entity, reference = getWikidataReference(statement), note = nil -- Wikidata items don't have manual wiki notes } end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end -- Extract custom note parameter local note = getManual(args, {"noteyn_ynnyd_reiragh"}) if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil, note = note } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end -- Extract custom note parameter local note = getManual(args, {"noteyn_balley_smoo"}) if city then return { text = city, entity = getCityEntityFromTitle(city), reference = nil, note = note } end local country = mw.wikibase.getEntityObject() if not country then return nil end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id local target = mw.wikibase.getEntity(targetId) if target and not isDisambiguationPage(target) then local sitelink = target:getSitelink("gvwiki") return { text = sitelink or target:getLabel(), entity = target, reference = getWikidataReference(statement), note = nil } end end end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end if city then return { text = city, entity = getCityEntityFromTitle(city), reference = nil } end local country = mw.wikibase.getEntityObject() if not country then return nil end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id local target = mw.wikibase.getEntity(targetId) if target and not isDisambiguationPage(target) then local sitelink = target:getSitelink("gvwiki") return { text = sitelink or target:getLabel(), entity = target, reference = getWikidataReference(statement) } end end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) return { capital = getCapitalData(args), administrative = getAdministrativeCentreData(args), largest = getLargestCityData(args), labels = getCityLabels(args) } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end local title = nil if city.entity then title = city.entity:getSitelink("gvwiki") end if not title or title == "" then title = normaliseCityName(city.text) end if not title or title == "" then return "" end return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest -- Helper function to render the data chunk cleanly local function renderCityCell(cityObj) local text = makeCityLink(cityObj) -- Append the efn footnote tag if it exists if cityObj.note and cityObj.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { cityObj.note } } text = text .. efnOut end -- Append standard reference citations if cityObj.reference then text = text .. cityObj.reference end -- Append coordinates block on a new line below the name if cityObj.entity then local coordinates = makeCoordinates(cityObj.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text end if capital then return renderCityCell(capital) elseif administrative then return renderCityCell(administrative) elseif largest then return renderCityCell(largest) end return nil end function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} local function formatLegacyRow(label, cityObj) local text = makeCityLink(cityObj) if cityObj.note and cityObj.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { cityObj.note } } text = text .. efnOut end if cityObj.reference then text = text .. cityObj.reference end if cityObj.entity then local coordinates = makeCoordinates(cityObj.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end return "'''" .. label .. "''': " .. text end if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end table.insert(rows, formatLegacyRow(label, capital)) end if administrative then local label = labels.administrative or "Ynnyd reiragh" table.insert(rows, formatLegacyRow(label, administrative)) end if largest then table.insert(rows, formatLegacyRow("Balley smoo", largest)) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames[1] end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- OLD CITY OUTPUT -------------------------------------------------- function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end if capital.reference then text = text .. capital.reference end table.insert(rows, "'''" .. label .. "''': " .. text ) end if administrative then table.insert(rows, "'''" .. (labels.administrative or "Ynnyd reiragh") .. "''': " .. makeCityLink(administrative) ) end if largest then local text = makeCityLink(largest) if largest.reference then text = text .. largest.reference end table.insert(rows, "'''Balley smoo''': " .. text ) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- MAIN -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -------------------------------------------------- -- HEADER -------------------------------------------------- do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -------------------------------------------------- -- FLAG / ARMS -------------------------------------------------- do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -------------------------------------------------- -- MOTTO / ANTHEM -------------------------------------------------- do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -------------------------------------------------- -- CAPITAL / ADMINISTRATIVE CENTRE / LARGEST CITY -------------------------------------------------- do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels -- Add one divider before the city section only. if capital or administrative or largest then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '"></td></tr>' ) end -- Capital if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Administrative centre if administrative then local text = makeCityLink(administrative) if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end -- Largest city if largest then local text = makeCityLink(largest) if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- do local languageRows = buildLanguageRows(args) if languageRows then table.insert(rows, languageRows) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p c0d4ert80qc8ucj7zrm7xfrl5gv8bld 392899 392898 2026-09-07T02:18:25Z MacTire02 219 ++ 392899 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- DISAMBIGUATION GUARD -------------------------------------------------- local function isDisambiguationPage(entity) if not entity then return false end local statements = entity:getBestStatements("P31") if not statements then return false end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" and mainsnak.datavalue.value.id == "Q4167410" then return true end end return false end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity and not isDisambiguationPage(linkedEntity) then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- FLAG BORDER CHECK -------------------------------------------------- local NON_RECTANGULAR_FLAGS = { ["Flag of Nepal.svg"] = true, ["Flag of Ohio.svg"] = true, ["Flag of Switzerland.svg"] = true, } local function needsFlagBorder(flagFile) if not flagFile then return true end if NON_RECTANGULAR_FLAGS[flagFile] then return false end local lowerFile = mw.ustring.lower(flagFile) if mw.ustring.find(lowerFile, "nepal") then return false end return true end -------------------------------------------------- -- MULTI-FLAG SUPPORT -------------------------------------------------- local function getFlagData(args) local flag = getManual(args, {"jalloo_brattagh"}) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local flag2 = getManual(args, {"jalloo_brattagh_2", "jalloo_brattagh_elley"}) if flag2 and mw.ustring.lower(flag2) == "none" then flag2 = nil elseif not flag2 then flag2 = getWikidataImage("P163") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end local arms2 = getManual(args, { "jalloo_armys_2", "jalloo_cleinney_2" }) if arms2 and mw.ustring.lower(arms2) == "none" then arms2 = nil elseif not arms2 then arms2 = getWikidataImage("P237") end if not flag and not flag2 and not arms and not arms2 then return nil end local name = getCountryGenitive(args) or "" local data = { flags = {}, armses = {} } if flag then local flagWidth = getManual(args, {"lheead_brattagh"}) or "125px" local hasBorder = needsFlagBorder(flag) table.insert(data.flags, { image = flag, width = flagWidth, hasBorder = hasBorder, link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh"}) or "Brattagh", isPrimary = true }) end if flag2 then local flag2Width = getManual(args, {"lheead_brattagh_2", "lheead_brattagh"}) or "100px" local hasBorder2 = needsFlagBorder(flag2) table.insert(data.flags, { image = flag2, width = flag2Width, hasBorder = hasBorder2, link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh_2"}) or "Brattagh elley", isPrimary = false }) end if arms then local kind = getManual(args, {"art_sorçh_cowrey"}) or getManual(args, {"sorçh_cowrey"}) or "Armys" table.insert(data.armses, { image = arms, width = getManual(args, {"lheead_armys", "lheead_cleinney", "lheead_cowrey"}) or "85px", link = kind .. " " .. name, label = getManual(args, {"sorçh_cowrey"}) or "Armys", isPrimary = true }) end if arms2 then table.insert(data.armses, { image = arms2, width = getManual(args, {"lheead_armys_2", "lheead_cleinney_2"}) or "85px", link = "Armys " .. name, label = getManual(args, {"sorçh_cowrey_2"}) or "Armys", isPrimary = false }) end return data end local function buildFlagArmsBlock(args) local data = getFlagData(args) if not data then return nil end local imageCells = {} local captionCells = {} local hasFlags = #data.flags > 0 local hasArms = #data.armses > 0 if hasFlags then local flagContent = {} for i, flagData in ipairs(data.flags) do local borderStyle = "" if flagData.hasBorder then borderStyle = '|style="border:1px solid #a2a9b1;"' end local flagImage = '[[Coadan:' .. flagData.image .. '|' .. flagData.width .. borderStyle .. ']]' table.insert(flagContent, flagImage) end local combinedFlags = table.concat(flagContent, '<br/>') table.insert(imageCells, '<td align="center" style="' .. (hasArms and "width:58%; " or "width:100%; ") .. 'vertical-align:middle;">' .. combinedFlags .. '</td>' ) local flagCaptions = {} for i, flagData in ipairs(data.flags) do table.insert(flagCaptions, '<small>[[' .. flagData.link .. '|' .. flagData.label .. ']]</small>' ) end table.insert(captionCells, '<td align="center">' .. table.concat(flagCaptions, '<br/>') .. '</td>' ) end if hasArms then local armsContent = {} for i, armsData in ipairs(data.armses) do local armsImage = '[[Coadan:' .. armsData.image .. '|' .. armsData.width .. ']]' table.insert(armsContent, armsImage) end local combinedArms = table.concat(armsContent, '<br/>') table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">' .. combinedArms .. '</td>' ) local armsCaptions = {} for i, armsData in ipairs(data.armses) do table.insert(armsCaptions, '<small>[[' .. armsData.link .. '|' .. armsData.label .. ']]</small>' ) end table.insert(captionCells, '<td align="center">' .. table.concat(armsCaptions, '<br/>') .. '</td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) local chyndaa = getManual(args, {"çhyndaa_jarroo_raa", "chyndaa_jarroo_raa"}) local tessenLettyraghey = getManual(args, {"tessen-lettyraghey_jarroo_raa"}) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = motto, reference = reference and "<ref>" .. reference .. "</ref>" or nil, chyndaa = chyndaa, tessenLettyraghey = tessenLettyraghey } end local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = value.text, reference = getWikidataReference(statement), chyndaa = nil, tessenLettyraghey = nil } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, {"arrane_ashoonagh"}) local royal = getManual(args, {"arrane_reeoil"}) local other = getManual(args, {"arrane"}) local nationalReference = getManual(args, {"imraa_arrane_ashoonagh"}) local royalReference = getManual(args, {"imraa_arrane_reeoil"}) local otherReference = getManual(args, {"imraa_arrane"}) local nationalAudio = getManual(args, {"coadan_arrane_ashoonagh"}) local royalAudio = getManual(args, {"coadan_arrane_reeoil"}) local otherAudio = getManual(args, {"coadan_arrane"}) local nationalNote = getManual(args, {"noteyn_arrane_ashoonagh"}) local royalNote = getManual(args, {"noteyn_arrane_reeoil"}) local otherNote = getManual(args, {"noteyn_arrane"}) local nationalChyndaa = getManual(args, {"çhyndaa_arrane_ashoonagh", "chyndaa_arrane_ashoonagh"}) local royalChyndaa = getManual(args, {"çhyndaa_arrane_reeoil", "chyndaa_arrane_reeoil"}) local otherChyndaa = getManual(args, {"çhyndaa_arrane", "chyndaa_arrane"}) local nationalTessen = getManual(args, {"tessen-lettyraghey_arrane_ashoonagh"}) local royalTessen = getManual(args, {"tessen-lettyraghey_arrane_reeoil"}) local otherTessen = getManual(args, {"tessen-lettyraghey_arrane"}) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and ("<ref>" .. nationalReference .. "</ref>") or nil, audio = nationalAudio, note = nationalNote, chyndaa = nationalChyndaa, tessenLettyraghey = nationalTessen } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and ("<ref>" .. royalReference .. "</ref>") or nil, audio = royalAudio, note = royalNote, chyndaa = royalChyndaa, tessenLettyraghey = royalTessen } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and ("<ref>" .. otherReference .. "</ref>") or nil, audio = otherAudio, note = otherNote, chyndaa = otherChyndaa, tessenLettyraghey = otherTessen } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS OUTPUT -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local baseText = motto.text baseText = mw.text.trim(baseText):gsub('^["“]', ''):gsub('["”]$', '') if not mw.ustring.find(baseText, "%[%[") then baseText = "''" .. baseText .. "''" end if motto.tessenLettyraghey and motto.tessenLettyraghey ~= "" then baseText = baseText .. " (''" .. motto.tessenLettyraghey .. "'')" end if motto.chyndaa and motto.chyndaa ~= "" then baseText = baseText .. " <br/><small>“" .. motto.chyndaa .. "”</small>" end if motto.reference then baseText = baseText .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. baseText) end local function formatAnthemRow(label, anthemObj) if not anthemObj or not anthemObj.text then return nil end local cleanText = anthemObj.text cleanText = mw.text.trim(cleanText):gsub('^["...]', ''):gsub('["...]$', '') if not mw.ustring.find(cleanText, "%[%[") then cleanText = '[[' .. cleanText .. '|' .. cleanText .. ']]' end local display = '“' .. cleanText .. '”' if anthemObj.tessenLettyraghey and anthemObj.tessenLettyraghey ~= "" then display = display .. " (''" .. anthemObj.tessenLettyraghey .. "'')" end if anthemObj.chyndaa and anthemObj.chyndaa ~= "" then display = display .. " <br/><small>“" .. anthemObj.chyndaa .. "”</small>" end if anthemObj.note and anthemObj.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { anthemObj.note } } display = display .. efnOut end if anthemObj.reference then display = display .. anthemObj.reference end if anthemObj.audio and anthemObj.audio ~= "" then display = display .. '<br/><div style="text-align:center; margin-top:0.3em;">[[Coadan:' .. anthemObj.audio .. '|center]]</div>' end return "'''" .. label .. ":&nbsp;'''" .. display end local nationalRow = formatAnthemRow("[[Arrane ashoonagh]]", anthems.national) if nationalRow then table.insert(rows, nationalRow) end local otherRow = formatAnthemRow("Anthym", anthems.other) if otherRow then table.insert(rows, otherRow) end local royalRow = formatAnthemRow("[[Arrane reeoil]]", anthems.royal) if royalRow then table.insert(rows, royalRow) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- local function getLanguagesFromWikidata() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P37") if not statements or #statements == 0 then return {} end local languages = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local langEntity = mw.wikibase.getEntity(id) if langEntity then local label = langEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(languages, { text = label, role = role, reference = getWikidataReference(statement) }) end end end end return languages end local function classifyLanguages(languages) local result = { official = {}, regional = {}, minority = {} } for _, language in ipairs(languages) do local role = language.role or "" local lowerRole = mw.ustring.lower(role) if mw.ustring.find(lowerRole, "minority") then table.insert(result.minority, language) elseif mw.ustring.find(lowerRole, "regional") then table.insert(result.regional, language) else table.insert(result.official, language) end end return result end local function manxSort(a, b) local function normalize(text) text = mw.ustring.lower(text) text = mw.ustring.gsub(text, "çh", "ch") return text end return normalize(a) < normalize(b) end local function joinLanguageList(languages) if not languages or #languages == 0 then return nil end table.sort(languages, function(a, b) return manxSort(a.text, b.text) end) local parts = {} for _, language in ipairs(languages) do local text = language.text text = '[[' .. text .. '|' .. text .. ']]' if language.reference then text = text .. language.reference end table.insert(parts, text) end if #parts == 0 then return nil end return '<div class="hlist">' .. table.concat(parts, '&nbsp;· ') .. '</div>' end local function splitTopLevel(text, sep) local parts = {} local current = {} local depthCurly = 0 local depthSquare = 0 local len = mw.ustring.len(text) local i = 1 while i <= len do local two = mw.ustring.sub(text, i, i + 1) local one = mw.ustring.sub(text, i, i) if two == "{{" then depthCurly = depthCurly + 1 table.insert(current, two) i = i + 2 elseif two == "}}" and depthCurly > 0 then depthCurly = depthCurly - 1 table.insert(current, two) i = i + 2 elseif two == "[[" then depthSquare = depthSquare + 1 table.insert(current, two) i = i + 2 elseif two == "]]" and depthSquare > 0 then depthSquare = depthSquare - 1 table.insert(current, two) i = i + 2 elseif one == sep and depthCurly == 0 and depthSquare == 0 then table.insert(parts, table.concat(current)) current = {} i = i + 1 else table.insert(current, one) i = i + 1 end end table.insert(parts, table.concat(current)) return parts end local function findTemplateCall(text, namePattern) local searchPattern = "{{%s*" .. namePattern .. "%s*|" local matchStart, matchEnd = mw.ustring.find(text, searchPattern) if not matchStart then return nil end local contentStart = matchEnd + 1 local depth = 1 local i = contentStart local len = mw.ustring.len(text) while i <= len do local two = mw.ustring.sub(text, i, i + 1) if two == "{{" then depth = depth + 1 i = i + 2 elseif two == "}}" then depth = depth - 1 i = i + 2 if depth == 0 then local contentEnd = i - 3 return mw.ustring.sub(text, contentStart, contentEnd) end else i = i + 1 end end return nil end local function extractReferences(text) if not text then return text, nil end local refs = {} local cleaned = mw.ustring.gsub(text, "<ref[^>]*>.-</ref>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.ustring.gsub(cleaned, "<ref[^>]*/>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.text.trim(cleaned) if #refs == 0 then return cleaned, nil end return cleaned, table.concat(refs) end local function countHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local segments = splitTopLevel(inner, "|") local count = 0 for _, segment in ipairs(segments) do local trimmedSegment = mw.text.trim(segment) if trimmedSegment ~= "" and not mw.ustring.find(trimmedSegment, "^[%w_%- ]+=") then count = count + 1 end end return count end local function countListItems(text) if not text or text == "" then return 0 end local hlistCount = countHlistItems(text) if hlistCount then return hlistCount end local count = 0 for _ in mw.text.gsplit(text, ",", true) do count = count + 1 end return count end local function extractHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local items = {} local segments = splitTopLevel(inner, "|") for _, segment in ipairs(segments) do local trimmed = mw.text.trim(segment) if trimmed ~= "" and not mw.ustring.find(trimmed, "^[%w_%- ]+=") then local linkText = mw.ustring.match(trimmed, "%[%[.-|(.+)%]%]") or mw.ustring.match(trimmed, "%[%[(.+)%]%]") or trimmed table.insert(items, mw.text.trim(linkText)) end end return items end local function buildLanguageValue(raw, manualReference, manualNote, frame) if not raw or mw.ustring.lower(mw.text.trim(raw)) == "none" then return nil, 0 end local cleaned, inlineRefs = extractReferences(raw) local count = countListItems(cleaned) local languageNames = extractHlistItems(cleaned) if not languageNames then languageNames = {} for part in mw.text.gsplit(cleaned, ",", true) do local trimmed = mw.text.trim(part) if trimmed ~= "" then table.insert(languageNames, trimmed) end end end table.sort(languageNames, manxSort) local parts = {} for _, name in ipairs(languageNames) do table.insert(parts, '[[' .. name .. '|' .. name .. ']]') end local display = '<div class="hlist">' .. table.concat(parts, '&nbsp;· ') .. '</div>' if manualNote and manualNote ~= "" and frame then local efnOut = frame:expandTemplate{ title = "efn", args = { manualNote } } display = display .. efnOut end if inlineRefs then display = display .. inlineRefs end if manualReference then display = display .. "<ref>" .. manualReference .. "</ref>" end return display, count end local function getLanguageData(args, frame) local officialRaw = getManual(args, { "çhengaghyn_oikoil", "çhengey_oikoil" }) local officialReference = getManual(args, { "imraa_çhengaghyn_oikoil", "imraa_çhengey_oikoil" }) local regionalRaw = getManual(args, { "çhengaghyn_ardjynagh", "çhengey_ardjynagh" }) local regionalReference = getManual(args, { "imraa_çhengaghyn_ardjynagh", "imraa_çhengey_ardjynagh" }) local minorityRaw = getManual(args, { "mynçhengaghyn", "mynçhengey" }) local minorityReference = getManual(args, { "imraa_mynçhengaghyn", "imraa_mynçhengey" }) local otherRaw = getManual(args, { "çhengaghyn", "çhengey" }) local otherReference = getManual(args, { "imraa_çhengaghyn", "imraa_çhengey" }) local otherLabel = getManual(args, { "sorçh_çhengaghyn" }) local officialNote = getManual(args, {"noteyn_çhengaghyn_oikoil", "noteyn_çhengey_oikoil"}) local regionalNote = getManual(args, {"noteyn_çhengaghyn_ardjynagh", "noteyn_çhengey_ardjynagh"}) local minorityNote = getManual(args, {"noteyn_mynçhengaghyn", "noteyn_mynçhengey"}) local otherNote = getManual(args, {"noteyn_çhengaghyn", "noteyn_çhengey"}) local result = { otherLabel = otherLabel } result.official, result.officialCount = buildLanguageValue(officialRaw, officialReference, officialNote, frame) result.regional, result.regionalCount = buildLanguageValue(regionalRaw, regionalReference, regionalNote, frame) result.minority, result.minorityCount = buildLanguageValue(minorityRaw, minorityReference, minorityNote, frame) result.other, result.otherCount = buildLanguageValue(otherRaw, otherReference, otherNote, frame) if not result.official and not result.regional and not result.minority then local classified = classifyLanguages(getLanguagesFromWikidata()) result.official = joinLanguageList(classified.official) result.officialCount = #classified.official result.regional = joinLanguageList(classified.regional) result.regionalCount = #classified.regional result.minority = joinLanguageList(classified.minority) result.minorityCount = #classified.minority end return result end local function buildLanguageRows(args, frame) local data = getLanguageData(args, frame) local rows = {} if data.official then local officialLabel = data.officialCount > 1 and "[[Çhengey oikoil|Çhengaghyn oikoil]]" or "[[Çhengey oikoil]]" local officialRow = '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. officialLabel .. '</th><td style="vertical-align:top;">' .. data.official .. '</td></tr>' if data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn&nbsp;ardjynagh er&nbsp;enney" or "Çhengey&nbsp;ardjynagh er&nbsp;enney" officialRow = officialRow .. '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:normal;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th>' .. '<td style="vertical-align:top;">' .. data.regional .. '</td></tr>' end table.insert(rows, officialRow) elseif data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn ardjynagh er enney" or "Çhengey ardjynagh er enney" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th><td style="vertical-align:top;">' .. data.regional .. '</td></tr>' ) end if data.minority then local minorityLabel = data.minorityCount > 1 and "[[Mynçhengey|Mynçhengaghyn]]" or "[[Mynçhengey]]" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. minorityLabel .. '</th><td style="vertical-align:top;">' .. data.minority .. '</td></tr>' ) end if data.other then local otherLabel = data.otherLabel or (data.otherCount > 1 and "Çhengaghyn" or "Çhengey") table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. otherLabel .. '</th><td style="vertical-align:top;">' .. data.other .. '</td></tr>' ) end if #rows == 0 then return nil end return table.concat(rows) end function p.languages(frame) local args = getArgs(frame) return buildLanguageRows(args, frame) end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCityEntityFromTitle(value) local title = normaliseCityName(value) if title == "" then return nil end local entityId = mw.wikibase.getEntityIdForTitle(title) if not entityId then return nil end return mw.wikibase.getEntity(entityId) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end local note = getManual(args, {"noteyn_preeu-valley"}) if capital then return { text = capital, entity = getCityEntityFromTitle(capital), reference = nil, note = note } end local entity, statement = getWikidataItem("P36") if entity then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or entity:getLabel(), entity = entity, reference = getWikidataReference(statement), note = nil } end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end local note = getManual(args, {"noteyn_ynnyd_reiragh"}) if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil, note = note } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end local note = getManual(args, {"noteyn_balley_smoo"}) if city then return { text = city, entity = getCityEntityFromTitle(city), reference = nil, note = note } end local country = mw.wikibase.getEntityObject() if not country then return nil end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id local target = mw.wikibase.getEntity(targetId) if target and not isDisambiguationPage(target) then local sitelink = target:getSitelink("gvwiki") return { text = sitelink or target:getLabel(), entity = target, reference = getWikidataReference(statement), note = nil } end end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) return { capital = getCapitalData(args), administrative = getAdministrativeCentreData(args), largest = getLargestCityData(args), labels = getCityLabels(args) } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end local title = nil if city.entity then title = city.entity:getSitelink("gvwiki") end if not title or title == "" then title = normaliseCityName(city.text) end if not title or title == "" then return "" end return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local function renderCityCell(cityObj) local text = makeCityLink(cityObj) if cityObj.note and cityObj.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { cityObj.note } } text = text .. efnOut end if cityObj.reference then text = text .. cityObj.reference end if cityObj.entity then local coordinates = makeCoordinates(cityObj.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text end if capital then return renderCityCell(capital) elseif administrative then return renderCityCell(administrative) elseif largest then return renderCityCell(largest) end return nil end function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} local function formatLegacyRow(label, cityObj) local text = makeCityLink(cityObj) if cityObj.note and cityObj.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { cityObj.note } } text = text .. efnOut end if cityObj.reference then text = text .. cityObj.reference end if cityObj.entity then local coordinates = makeCoordinates(cityObj.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end return "'''" .. label .. "''': " .. text end if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end table.insert(rows, formatLegacyRow(label, capital)) end if administrative then local label = labels.administrative or "Ynnyd reiragh" table.insert(rows, formatLegacyRow(label, administrative)) end if largest then table.insert(rows, formatLegacyRow("Balley smoo", largest)) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- MAIN -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -------------------------------------------------- -- HEADER -------------------------------------------------- do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -------------------------------------------------- -- FLAG / ARMS -------------------------------------------------- do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -------------------------------------------------- -- MOTTO / ANTHEM -------------------------------------------------- do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -------------------------------------------------- -- CAPITAL / ADMINISTRATIVE CENTRE / LARGEST CITY -------------------------------------------------- do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels if capital or administrative or largest then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '"></td></tr>' ) end if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.note and capital.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { capital.note } } text = text .. efnOut end if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end if administrative then local text = makeCityLink(administrative) if administrative.note and administrative.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { administrative.note } } text = text .. efnOut end if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end if largest then local text = makeCityLink(largest) if largest.note and largest.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { largest.note } } text = text .. efnOut end if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- do local languageRows = buildLanguageRows(args, frame) if languageRows then table.insert(rows, languageRows) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p pb6d5zoi7pet5bqtolamh1iazbod8k0 392900 392899 2026-09-07T02:22:18Z MacTire02 219 ++ 392900 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- DISAMBIGUATION GUARD -------------------------------------------------- local function isDisambiguationPage(entity) if not entity then return false end local statements = entity:getBestStatements("P31") if not statements then return false end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" and mainsnak.datavalue.value.id == "Q4167410" then return true end end return false end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity and not isDisambiguationPage(linkedEntity) then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- FLAG BORDER CHECK -------------------------------------------------- local NON_RECTANGULAR_FLAGS = { ["Flag of Nepal.svg"] = true, ["Flag of Ohio.svg"] = true, ["Flag of Switzerland.svg"] = true, } local function needsFlagBorder(flagFile) if not flagFile then return true end if NON_RECTANGULAR_FLAGS[flagFile] then return false end local lowerFile = mw.ustring.lower(flagFile) if mw.ustring.find(lowerFile, "nepal") then return false end return true end -------------------------------------------------- -- MULTI-FLAG SUPPORT -------------------------------------------------- local function getFlagData(args) local flag = getManual(args, {"jalloo_brattagh"}) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local flag2 = getManual(args, {"jalloo_brattagh_2", "jalloo_brattagh_elley"}) if flag2 and mw.ustring.lower(flag2) == "none" then flag2 = nil elseif not flag2 then flag2 = getWikidataImage("P163") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end local arms2 = getManual(args, { "jalloo_armys_2", "jalloo_cleinney_2" }) if arms2 and mw.ustring.lower(arms2) == "none" then arms2 = nil elseif not arms2 then arms2 = getWikidataImage("P237") end if not flag and not flag2 and not arms and not arms2 then return nil end local name = getCountryGenitive(args) or "" local data = { flags = {}, armses = {} } if flag then local flagWidth = getManual(args, {"lheead_brattagh"}) or "125px" local hasBorder = needsFlagBorder(flag) table.insert(data.flags, { image = flag, width = flagWidth, hasBorder = hasBorder, link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh"}) or "Brattagh", isPrimary = true }) end if flag2 then local flag2Width = getManual(args, {"lheead_brattagh_2", "lheead_brattagh"}) or "100px" local hasBorder2 = needsFlagBorder(flag2) table.insert(data.flags, { image = flag2, width = flag2Width, hasBorder = hasBorder2, link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh_2"}) or "Brattagh elley", isPrimary = false }) end if arms then local kind = getManual(args, {"art_sorçh_cowrey"}) or getManual(args, {"sorçh_cowrey"}) or "Armys" table.insert(data.armses, { image = arms, width = getManual(args, {"lheead_armys", "lheead_cleinney", "lheead_cowrey"}) or "85px", link = kind .. " " .. name, label = getManual(args, {"sorçh_cowrey"}) or "Armys", isPrimary = true }) end if arms2 then table.insert(data.armses, { image = arms2, width = getManual(args, {"lheead_armys_2", "lheead_cleinney_2"}) or "85px", link = "Armys " .. name, label = getManual(args, {"sorçh_cowrey_2"}) or "Armys", isPrimary = false }) end return data end local function buildFlagArmsBlock(args) local data = getFlagData(args) if not data then return nil end local imageCells = {} local captionCells = {} local hasFlags = #data.flags > 0 local hasArms = #data.armses > 0 if hasFlags then local flagContent = {} for i, flagData in ipairs(data.flags) do local borderStyle = "" if flagData.hasBorder then borderStyle = '|style="border:1px solid #a2a9b1;"' end local flagImage = '[[Coadan:' .. flagData.image .. '|' .. flagData.width .. borderStyle .. ']]' table.insert(flagContent, flagImage) end local combinedFlags = table.concat(flagContent, '<br/>') table.insert(imageCells, '<td align="center" style="' .. (hasArms and "width:58%; " or "width:100%; ") .. 'vertical-align:middle;">' .. combinedFlags .. '</td>' ) local flagCaptions = {} for i, flagData in ipairs(data.flags) do table.insert(flagCaptions, '<small>[[' .. flagData.link .. '|' .. flagData.label .. ']]</small>' ) end table.insert(captionCells, '<td align="center">' .. table.concat(flagCaptions, '<br/>') .. '</td>' ) end if hasArms then local armsContent = {} for i, armsData in ipairs(data.armses) do local armsImage = '[[Coadan:' .. armsData.image .. '|' .. armsData.width .. ']]' table.insert(armsContent, armsImage) end local combinedArms = table.concat(armsContent, '<br/>') table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">' .. combinedArms .. '</td>' ) local armsCaptions = {} for i, armsData in ipairs(data.armses) do table.insert(armsCaptions, '<small>[[' .. armsData.link .. '|' .. armsData.label .. ']]</small>' ) end table.insert(captionCells, '<td align="center">' .. table.concat(armsCaptions, '<br/>') .. '</td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) local chyndaa = getManual(args, { "çhyndaa_jarroo-raa", "chyndaa_jarroo-raa", "çhyndaa_jarroo_raa", "chyndaa_jarroo_raa" }) local tessenLettyraghey = getManual(args, { "tessen-lettyraghey_jarroo_raa", "tessen-lettyraghey_jarroo-raa" }) if motto then if mw.ustring.lower(motto) == "none" then return nil end return { text = motto, reference = reference and "<ref>" .. reference .. "</ref>" or nil, chyndaa = chyndaa, tessenLettyraghey = tessenLettyraghey } end local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1451") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then return { text = value.text, reference = getWikidataReference(statement), chyndaa = nil, tessenLettyraghey = nil } end end end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, {"arrane_ashoonagh"}) local royal = getManual(args, {"arrane_reeoil"}) local other = getManual(args, {"arrane"}) local nationalReference = getManual(args, {"imraa_arrane_ashoonagh"}) local royalReference = getManual(args, {"imraa_arrane_reeoil"}) local otherReference = getManual(args, {"imraa_arrane"}) local nationalAudio = getManual(args, {"coadan_arrane_ashoonagh"}) local royalAudio = getManual(args, {"coadan_arrane_reeoil"}) local otherAudio = getManual(args, {"coadan_arrane"}) local nationalNote = getManual(args, {"noteyn_arrane_ashoonagh"}) local royalNote = getManual(args, {"noteyn_arrane_reeoil"}) local otherNote = getManual(args, {"noteyn_arrane"}) local nationalChyndaa = getManual(args, {"çhyndaa_arrane_ashoonagh", "chyndaa_arrane_ashoonagh"}) local royalChyndaa = getManual(args, {"çhyndaa_arrane_reeoil", "chyndaa_arrane_reeoil"}) local otherChyndaa = getManual(args, {"çhyndaa_arrane", "chyndaa_arrane"}) local nationalTessen = getManual(args, {"tessen-lettyraghey_arrane_ashoonagh"}) local royalTessen = getManual(args, {"tessen-lettyraghey_arrane_reeoil"}) local otherTessen = getManual(args, {"tessen-lettyraghey_arrane"}) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and ("<ref>" .. nationalReference .. "</ref>") or nil, audio = nationalAudio, note = nationalNote, chyndaa = nationalChyndaa, tessenLettyraghey = nationalTessen } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and ("<ref>" .. royalReference .. "</ref>") or nil, audio = royalAudio, note = royalNote, chyndaa = royalChyndaa, tessenLettyraghey = royalTessen } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and ("<ref>" .. otherReference .. "</ref>") or nil, audio = otherAudio, note = otherNote, chyndaa = otherChyndaa, tessenLettyraghey = otherTessen } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS OUTPUT -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local baseText = motto.text baseText = mw.text.trim(baseText):gsub('^["“]', ''):gsub('["”]$', '') if not mw.ustring.find(baseText, "%[%[") then baseText = "''" .. baseText .. "''" end if motto.tessenLettyraghey and motto.tessenLettyraghey ~= "" then baseText = baseText .. " (''" .. motto.tessenLettyraghey .. "'')" end if motto.chyndaa and motto.chyndaa ~= "" then baseText = baseText .. " <br/><small>“" .. motto.chyndaa .. "”</small>" end if motto.reference then baseText = baseText .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. baseText) end local function formatAnthemRow(label, anthemObj) if not anthemObj or not anthemObj.text then return nil end local cleanText = anthemObj.text cleanText = mw.text.trim(cleanText):gsub('^["...]', ''):gsub('["...]$', '') if not mw.ustring.find(cleanText, "%[%[") then cleanText = '[[' .. cleanText .. '|' .. cleanText .. ']]' end local display = '“' .. cleanText .. '”' if anthemObj.tessenLettyraghey and anthemObj.tessenLettyraghey ~= "" then display = display .. " (''" .. anthemObj.tessenLettyraghey .. "'')" end if anthemObj.chyndaa and anthemObj.chyndaa ~= "" then display = display .. " <br/><small>“" .. anthemObj.chyndaa .. "”</small>" end if anthemObj.note and anthemObj.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { anthemObj.note } } display = display .. efnOut end if anthemObj.reference then display = display .. anthemObj.reference end if anthemObj.audio and anthemObj.audio ~= "" then display = display .. '<br/><div style="text-align:center; margin-top:0.3em;">[[Coadan:' .. anthemObj.audio .. '|center]]</div>' end return "'''" .. label .. ":&nbsp;'''" .. display end local nationalRow = formatAnthemRow("[[Arrane ashoonagh]]", anthems.national) if nationalRow then table.insert(rows, nationalRow) end local otherRow = formatAnthemRow("Anthym", anthems.other) if otherRow then table.insert(rows, otherRow) end local royalRow = formatAnthemRow("[[Arrane reeoil]]", anthems.royal) if royalRow then table.insert(rows, royalRow) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- local function getLanguagesFromWikidata() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P37") if not statements or #statements == 0 then return {} end local languages = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local langEntity = mw.wikibase.getEntity(id) if langEntity then local label = langEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(languages, { text = label, role = role, reference = getWikidataReference(statement) }) end end end end return languages end local function classifyLanguages(languages) local result = { official = {}, regional = {}, minority = {} } for _, language in ipairs(languages) do local role = language.role or "" local lowerRole = mw.ustring.lower(role) if mw.ustring.find(lowerRole, "minority") then table.insert(result.minority, language) elseif mw.ustring.find(lowerRole, "regional") then table.insert(result.regional, language) else table.insert(result.official, language) end end return result end local function manxSort(a, b) local function normalize(text) text = mw.ustring.lower(text) text = mw.ustring.gsub(text, "çh", "ch") return text end return normalize(a) < normalize(b) end local function joinLanguageList(languages) if not languages or #languages == 0 then return nil end table.sort(languages, function(a, b) return manxSort(a.text, b.text) end) local parts = {} for _, language in ipairs(languages) do local text = language.text text = '[[' .. text .. '|' .. text .. ']]' if language.reference then text = text .. language.reference end table.insert(parts, text) end if #parts == 0 then return nil end return '<div class="hlist">' .. table.concat(parts, '&nbsp;· ') .. '</div>' end local function splitTopLevel(text, sep) local parts = {} local current = {} local depthCurly = 0 local depthSquare = 0 local len = mw.ustring.len(text) local i = 1 while i <= len do local two = mw.ustring.sub(text, i, i + 1) local one = mw.ustring.sub(text, i, i) if two == "{{" then depthCurly = depthCurly + 1 table.insert(current, two) i = i + 2 elseif two == "}}" and depthCurly > 0 then depthCurly = depthCurly - 1 table.insert(current, two) i = i + 2 elseif two == "[[" then depthSquare = depthSquare + 1 table.insert(current, two) i = i + 2 elseif two == "]]" and depthSquare > 0 then depthSquare = depthSquare - 1 table.insert(current, two) i = i + 2 elseif one == sep and depthCurly == 0 and depthSquare == 0 then table.insert(parts, table.concat(current)) current = {} i = i + 1 else table.insert(current, one) i = i + 1 end end table.insert(parts, table.concat(current)) return parts end local function findTemplateCall(text, namePattern) local searchPattern = "{{%s*" .. namePattern .. "%s*|" local matchStart, matchEnd = mw.ustring.find(text, searchPattern) if not matchStart then return nil end local contentStart = matchEnd + 1 local depth = 1 local i = contentStart local len = mw.ustring.len(text) while i <= len do local two = mw.ustring.sub(text, i, i + 1) if two == "{{" then depth = depth + 1 i = i + 2 elseif two == "}}" then depth = depth - 1 i = i + 2 if depth == 0 then local contentEnd = i - 3 return mw.ustring.sub(text, contentStart, contentEnd) end else i = i + 1 end end return nil end local function extractReferences(text) if not text then return text, nil end local refs = {} local cleaned = mw.ustring.gsub(text, "<ref[^>]*>.-</ref>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.ustring.gsub(cleaned, "<ref[^>]*/>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.text.trim(cleaned) if #refs == 0 then return cleaned, nil end return cleaned, table.concat(refs) end local function countHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local segments = splitTopLevel(inner, "|") local count = 0 for _, segment in ipairs(segments) do local trimmedSegment = mw.text.trim(segment) if trimmedSegment ~= "" and not mw.ustring.find(trimmedSegment, "^[%w_%- ]+=") then count = count + 1 end end return count end local function countListItems(text) if not text or text == "" then return 0 end local hlistCount = countHlistItems(text) if hlistCount then return hlistCount end local count = 0 for _ in mw.text.gsplit(text, ",", true) do count = count + 1 end return count end local function extractHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local items = {} local segments = splitTopLevel(inner, "|") for _, segment in ipairs(segments) do local trimmed = mw.text.trim(segment) if trimmed ~= "" and not mw.ustring.find(trimmed, "^[%w_%- ]+=") then local linkText = mw.ustring.match(trimmed, "%[%[.-|(.+)%]%]") or mw.ustring.match(trimmed, "%[%[(.+)%]%]") or trimmed table.insert(items, mw.text.trim(linkText)) end end return items end local function buildLanguageValue(raw, manualReference, manualNote, frame) if not raw or mw.ustring.lower(mw.text.trim(raw)) == "none" then return nil, 0 end local cleaned, inlineRefs = extractReferences(raw) local count = countListItems(cleaned) local languageNames = extractHlistItems(cleaned) if not languageNames then languageNames = {} for part in mw.text.gsplit(cleaned, ",", true) do local trimmed = mw.text.trim(part) if trimmed ~= "" then table.insert(languageNames, trimmed) end end end table.sort(languageNames, manxSort) local parts = {} for _, name in ipairs(languageNames) do table.insert(parts, '[[' .. name .. '|' .. name .. ']]') end local display = '<div class="hlist">' .. table.concat(parts, '&nbsp;· ') .. '</div>' if manualNote and manualNote ~= "" and frame then local efnOut = frame:expandTemplate{ title = "efn", args = { manualNote } } display = display .. efnOut end if inlineRefs then display = display .. inlineRefs end if manualReference then display = display .. "<ref>" .. manualReference .. "</ref>" end return display, count end local function getLanguageData(args, frame) local officialRaw = getManual(args, { "çhengaghyn_oikoil", "çhengey_oikoil" }) local officialReference = getManual(args, { "imraa_çhengaghyn_oikoil", "imraa_çhengey_oikoil" }) local regionalRaw = getManual(args, { "çhengaghyn_ardjynagh", "çhengey_ardjynagh" }) local regionalReference = getManual(args, { "imraa_çhengaghyn_ardjynagh", "imraa_çhengey_ardjynagh" }) local minorityRaw = getManual(args, { "mynçhengaghyn", "mynçhengey" }) local minorityReference = getManual(args, { "imraa_mynçhengaghyn", "imraa_mynçhengey" }) local otherRaw = getManual(args, { "çhengaghyn", "çhengey" }) local otherReference = getManual(args, { "imraa_çhengaghyn", "imraa_çhengey" }) local otherLabel = getManual(args, { "sorçh_çhengaghyn" }) local officialNote = getManual(args, {"noteyn_çhengaghyn_oikoil", "noteyn_çhengey_oikoil"}) local regionalNote = getManual(args, {"noteyn_çhengaghyn_ardjynagh", "noteyn_çhengey_ardjynagh"}) local minorityNote = getManual(args, {"noteyn_mynçhengaghyn", "noteyn_mynçhengey"}) local otherNote = getManual(args, {"noteyn_çhengaghyn", "noteyn_çhengey"}) local result = { otherLabel = otherLabel } result.official, result.officialCount = buildLanguageValue(officialRaw, officialReference, officialNote, frame) result.regional, result.regionalCount = buildLanguageValue(regionalRaw, regionalReference, regionalNote, frame) result.minority, result.minorityCount = buildLanguageValue(minorityRaw, minorityReference, minorityNote, frame) result.other, result.otherCount = buildLanguageValue(otherRaw, otherReference, otherNote, frame) if not result.official and not result.regional and not result.minority then local classified = classifyLanguages(getLanguagesFromWikidata()) result.official = joinLanguageList(classified.official) result.officialCount = #classified.official result.regional = joinLanguageList(classified.regional) result.regionalCount = #classified.regional result.minority = joinLanguageList(classified.minority) result.minorityCount = #classified.minority end return result end local function buildLanguageRows(args, frame) local data = getLanguageData(args, frame) local rows = {} if data.official then local officialLabel = data.officialCount > 1 and "[[Çhengey oikoil|Çhengaghyn oikoil]]" or "[[Çhengey oikoil]]" local officialRow = '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. officialLabel .. '</th><td style="vertical-align:top;">' .. data.official .. '</td></tr>' if data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn&nbsp;ardjynagh er&nbsp;enney" or "Çhengey&nbsp;ardjynagh er&nbsp;enney" officialRow = officialRow .. '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:normal;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th>' .. '<td style="vertical-align:top;">' .. data.regional .. '</td></tr>' end table.insert(rows, officialRow) elseif data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn ardjynagh er enney" or "Çhengey ardjynagh er enney" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th><td style="vertical-align:top;">' .. data.regional .. '</td></tr>' ) end if data.minority then local minorityLabel = data.minorityCount > 1 and "[[Mynçhengey|Mynçhengaghyn]]" or "[[Mynçhengey]]" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. minorityLabel .. '</th><td style="vertical-align:top;">' .. data.minority .. '</td></tr>' ) end if data.other then local otherLabel = data.otherLabel or (data.otherCount > 1 and "Çhengaghyn" or "Çhengey") table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. otherLabel .. '</th><td style="vertical-align:top;">' .. data.other .. '</td></tr>' ) end if #rows == 0 then return nil end return table.concat(rows) end function p.languages(frame) local args = getArgs(frame) return buildLanguageRows(args, frame) end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCityEntityFromTitle(value) local title = normaliseCityName(value) if title == "" then return nil end local entityId = mw.wikibase.getEntityIdForTitle(title) if not entityId then return nil end return mw.wikibase.getEntity(entityId) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end local note = getManual(args, {"noteyn_preeu-valley"}) if capital then return { text = capital, entity = getCityEntityFromTitle(capital), reference = nil, note = note } end local entity, statement = getWikidataItem("P36") if entity then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or entity:getLabel(), entity = entity, reference = getWikidataReference(statement), note = nil } end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end local note = getManual(args, {"noteyn_ynnyd_reiragh"}) if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil, note = note } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end local note = getManual(args, {"noteyn_balley_smoo"}) if city then return { text = city, entity = getCityEntityFromTitle(city), reference = nil, note = note } end local country = mw.wikibase.getEntityObject() if not country then return nil end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id local target = mw.wikibase.getEntity(targetId) if target and not isDisambiguationPage(target) then local sitelink = target:getSitelink("gvwiki") return { text = sitelink or target:getLabel(), entity = target, reference = getWikidataReference(statement), note = nil } end end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) return { capital = getCapitalData(args), administrative = getAdministrativeCentreData(args), largest = getLargestCityData(args), labels = getCityLabels(args) } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end local title = nil if city.entity then title = city.entity:getSitelink("gvwiki") end if not title or title == "" then title = normaliseCityName(city.text) end if not title or title == "" then return "" end return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local function renderCityCell(cityObj) local text = makeCityLink(cityObj) if cityObj.note and cityObj.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { cityObj.note } } text = text .. efnOut end if cityObj.reference then text = text .. cityObj.reference end if cityObj.entity then local coordinates = makeCoordinates(cityObj.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text end if capital then return renderCityCell(capital) elseif administrative then return renderCityCell(administrative) elseif largest then return renderCityCell(largest) end return nil end function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} local function formatLegacyRow(label, cityObj) local text = makeCityLink(cityObj) if cityObj.note and cityObj.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { cityObj.note } } text = text .. efnOut end if cityObj.reference then text = text .. cityObj.reference end if cityObj.entity then local coordinates = makeCoordinates(cityObj.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end return "'''" .. label .. "''': " .. text end if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end table.insert(rows, formatLegacyRow(label, capital)) end if administrative then local label = labels.administrative or "Ynnyd reiragh" table.insert(rows, formatLegacyRow(label, administrative)) end if largest then table.insert(rows, formatLegacyRow("Balley smoo", largest)) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- MAIN -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -------------------------------------------------- -- HEADER -------------------------------------------------- do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -------------------------------------------------- -- FLAG / ARMS -------------------------------------------------- do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -------------------------------------------------- -- MOTTO / ANTHEM -------------------------------------------------- do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -------------------------------------------------- -- CAPITAL / ADMINISTRATIVE CENTRE / LARGEST CITY -------------------------------------------------- do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels if capital or administrative or largest then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '"></td></tr>' ) end if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.note and capital.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { capital.note } } text = text .. efnOut end if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end if administrative then local text = makeCityLink(administrative) if administrative.note and administrative.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { administrative.note } } text = text .. efnOut end if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end if largest then local text = makeCityLink(largest) if largest.note and largest.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { largest.note } } text = text .. efnOut end if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- do local languageRows = buildLanguageRows(args, frame) if languageRows then table.insert(rows, languageRows) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p 1a0q8q8g10ykq3vq65fkvjxfd85reea 392901 392900 2026-09-07T02:26:55Z MacTire02 219 ++ 392901 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- DISAMBIGUATION GUARD -------------------------------------------------- local function isDisambiguationPage(entity) if not entity then return false end local statements = entity:getBestStatements("P31") if not statements then return false end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" and mainsnak.datavalue.value.id == "Q4167410" then return true end end return false end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity and not isDisambiguationPage(linkedEntity) then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- FLAG BORDER CHECK -------------------------------------------------- local NON_RECTANGULAR_FLAGS = { ["Flag of Nepal.svg"] = true, ["Flag of Ohio.svg"] = true, ["Flag of Switzerland.svg"] = true, } local function needsFlagBorder(flagFile) if not flagFile then return true end if NON_RECTANGULAR_FLAGS[flagFile] then return false end local lowerFile = mw.ustring.lower(flagFile) if mw.ustring.find(lowerFile, "nepal") then return false end return true end -------------------------------------------------- -- MULTI-FLAG SUPPORT -------------------------------------------------- local function getFlagData(args) local flag = getManual(args, {"jalloo_brattagh"}) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local flag2 = getManual(args, {"jalloo_brattagh_2", "jalloo_brattagh_elley"}) if flag2 and mw.ustring.lower(flag2) == "none" then flag2 = nil elseif not flag2 then flag2 = getWikidataImage("P163") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end local arms2 = getManual(args, { "jalloo_armys_2", "jalloo_cleinney_2" }) if arms2 and mw.ustring.lower(arms2) == "none" then arms2 = nil elseif not arms2 then arms2 = getWikidataImage("P237") end if not flag and not flag2 and not arms and not arms2 then return nil end local name = getCountryGenitive(args) or "" local data = { flags = {}, armses = {} } if flag then local flagWidth = getManual(args, {"lheead_brattagh"}) or "125px" local hasBorder = needsFlagBorder(flag) table.insert(data.flags, { image = flag, width = flagWidth, hasBorder = hasBorder, link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh"}) or "Brattagh", isPrimary = true }) end if flag2 then local flag2Width = getManual(args, {"lheead_brattagh_2", "lheead_brattagh"}) or "100px" local hasBorder2 = needsFlagBorder(flag2) table.insert(data.flags, { image = flag2, width = flag2Width, hasBorder = hasBorder2, link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh_2"}) or "Brattagh elley", isPrimary = false }) end if arms then local kind = getManual(args, {"art_sorçh_cowrey"}) or getManual(args, {"sorçh_cowrey"}) or "Armys" table.insert(data.armses, { image = arms, width = getManual(args, {"lheead_armys", "lheead_cleinney", "lheead_cowrey"}) or "85px", link = kind .. " " .. name, label = getManual(args, {"sorçh_cowrey"}) or "Armys", isPrimary = true }) end if arms2 then table.insert(data.armses, { image = arms2, width = getManual(args, {"lheead_armys_2", "lheead_cleinney_2"}) or "85px", link = "Armys " .. name, label = getManual(args, {"sorçh_cowrey_2"}) or "Armys", isPrimary = false }) end return data end local function buildFlagArmsBlock(args) local data = getFlagData(args) if not data then return nil end local imageCells = {} local captionCells = {} local hasFlags = #data.flags > 0 local hasArms = #data.armses > 0 if hasFlags then local flagContent = {} for i, flagData in ipairs(data.flags) do local borderStyle = "" if flagData.hasBorder then borderStyle = '|style="border:1px solid #a2a9b1;"' end local flagImage = '[[Coadan:' .. flagData.image .. '|' .. flagData.width .. borderStyle .. ']]' table.insert(flagContent, flagImage) end local combinedFlags = table.concat(flagContent, '<br/>') table.insert(imageCells, '<td align="center" style="' .. (hasArms and "width:58%; " or "width:100%; ") .. 'vertical-align:middle;">' .. combinedFlags .. '</td>' ) local flagCaptions = {} for i, flagData in ipairs(data.flags) do table.insert(flagCaptions, '<small>[[' .. flagData.link .. '|' .. flagData.label .. ']]</small>' ) end table.insert(captionCells, '<td align="center">' .. table.concat(flagCaptions, '<br/>') .. '</td>' ) end if hasArms then local armsContent = {} for i, armsData in ipairs(data.armses) do local armsImage = '[[Coadan:' .. armsData.image .. '|' .. armsData.width .. ']]' table.insert(armsContent, armsImage) end local combinedArms = table.concat(armsContent, '<br/>') table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">' .. combinedArms .. '</td>' ) local armsCaptions = {} for i, armsData in ipairs(data.armses) do table.insert(armsCaptions, '<small>[[' .. armsData.link .. '|' .. armsData.label .. ']]</small>' ) end table.insert(captionCells, '<td align="center">' .. table.concat(armsCaptions, '<br/>') .. '</td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) -- 1. Extract manual parameters local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) local chyndaa = getManual(args, { "çhyndaa_jarroo-raa", "chyndaa_jarroo-raa", "çhyndaa_jarroo_raa", "chyndaa_jarroo_raa" }) local tessenLettyraghey = getManual(args, { "tessen-lettyraghey_jarroo-raa", "tessen-lettyraghey_jarroo_raa" }) -- 2. Evaluate actual text content source local finalMottoText = nil local finalReference = nil if motto then if mw.ustring.lower(motto) == "none" then return nil end finalMottoText = motto if reference then finalReference = "<ref>" .. reference .. "</ref>" end else -- Fall back to Wikidata for text strings, but RETAIN manual overrides local entity = mw.wikibase.getEntityObject() if entity then local statements = entity:getBestStatements("P1451") if statements and #statements > 0 then for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then finalMottoText = value.text finalReference = getWikidataReference(statement) break end end end end end end -- 3. Return consolidated data package if finalMottoText then return { text = finalMottoText, reference = finalReference, chyndaa = chyndaa, -- Always preserves your local translation parameters tessenLettyraghey = tessenLettyraghey -- Always preserves your local transliteration parameters } end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, {"arrane_ashoonagh"}) local royal = getManual(args, {"arrane_reeoil"}) local other = getManual(args, {"arrane"}) local nationalReference = getManual(args, {"imraa_arrane_ashoonagh"}) local royalReference = getManual(args, {"imraa_arrane_reeoil"}) local otherReference = getManual(args, {"imraa_arrane"}) local nationalAudio = getManual(args, {"coadan_arrane_ashoonagh"}) local royalAudio = getManual(args, {"coadan_arrane_reeoil"}) local otherAudio = getManual(args, {"coadan_arrane"}) local nationalNote = getManual(args, {"noteyn_arrane_ashoonagh"}) local royalNote = getManual(args, {"noteyn_arrane_reeoil"}) local otherNote = getManual(args, {"noteyn_arrane"}) local nationalChyndaa = getManual(args, {"çhyndaa_arrane_ashoonagh", "chyndaa_arrane_ashoonagh"}) local royalChyndaa = getManual(args, {"çhyndaa_arrane_reeoil", "chyndaa_arrane_reeoil"}) local otherChyndaa = getManual(args, {"çhyndaa_arrane", "chyndaa_arrane"}) local nationalTessen = getManual(args, {"tessen-lettyraghey_arrane_ashoonagh"}) local royalTessen = getManual(args, {"tessen-lettyraghey_arrane_reeoil"}) local otherTessen = getManual(args, {"tessen-lettyraghey_arrane"}) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and ("<ref>" .. nationalReference .. "</ref>") or nil, audio = nationalAudio, note = nationalNote, chyndaa = nationalChyndaa, tessenLettyraghey = nationalTessen } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and ("<ref>" .. royalReference .. "</ref>") or nil, audio = royalAudio, note = royalNote, chyndaa = royalChyndaa, tessenLettyraghey = royalTessen } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and ("<ref>" .. otherReference .. "</ref>") or nil, audio = otherAudio, note = otherNote, chyndaa = otherChyndaa, tessenLettyraghey = otherTessen } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS OUTPUT -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local baseText = motto.text baseText = mw.text.trim(baseText):gsub('^["“]', ''):gsub('["”]$', '') if not mw.ustring.find(baseText, "%[%[") then baseText = "''" .. baseText .. "''" end if motto.tessenLettyraghey and motto.tessenLettyraghey ~= "" then baseText = baseText .. " (''" .. motto.tessenLettyraghey .. "'')" end if motto.chyndaa and motto.chyndaa ~= "" then baseText = baseText .. " <br/><small>“" .. motto.chyndaa .. "”</small>" end if motto.reference then baseText = baseText .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. baseText) end local function formatAnthemRow(label, anthemObj) if not anthemObj or not anthemObj.text then return nil end local cleanText = anthemObj.text cleanText = mw.text.trim(cleanText):gsub('^["...]', ''):gsub('["...]$', '') if not mw.ustring.find(cleanText, "%[%[") then cleanText = '[[' .. cleanText .. '|' .. cleanText .. ']]' end local display = '“' .. cleanText .. '”' if anthemObj.tessenLettyraghey and anthemObj.tessenLettyraghey ~= "" then display = display .. " (''" .. anthemObj.tessenLettyraghey .. "'')" end if anthemObj.chyndaa and anthemObj.chyndaa ~= "" then display = display .. " <br/><small>“" .. anthemObj.chyndaa .. "”</small>" end if anthemObj.note and anthemObj.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { anthemObj.note } } display = display .. efnOut end if anthemObj.reference then display = display .. anthemObj.reference end if anthemObj.audio and anthemObj.audio ~= "" then display = display .. '<br/><div style="text-align:center; margin-top:0.3em;">[[Coadan:' .. anthemObj.audio .. '|center]]</div>' end return "'''" .. label .. ":&nbsp;'''" .. display end local nationalRow = formatAnthemRow("[[Arrane ashoonagh]]", anthems.national) if nationalRow then table.insert(rows, nationalRow) end local otherRow = formatAnthemRow("Anthym", anthems.other) if otherRow then table.insert(rows, otherRow) end local royalRow = formatAnthemRow("[[Arrane reeoil]]", anthems.royal) if royalRow then table.insert(rows, royalRow) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- local function getLanguagesFromWikidata() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P37") if not statements or #statements == 0 then return {} end local languages = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local langEntity = mw.wikibase.getEntity(id) if langEntity then local label = langEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(languages, { text = label, role = role, reference = getWikidataReference(statement) }) end end end end return languages end local function classifyLanguages(languages) local result = { official = {}, regional = {}, minority = {} } for _, language in ipairs(languages) do local role = language.role or "" local lowerRole = mw.ustring.lower(role) if mw.ustring.find(lowerRole, "minority") then table.insert(result.minority, language) elseif mw.ustring.find(lowerRole, "regional") then table.insert(result.regional, language) else table.insert(result.official, language) end end return result end local function manxSort(a, b) local function normalize(text) text = mw.ustring.lower(text) text = mw.ustring.gsub(text, "çh", "ch") return text end return normalize(a) < normalize(b) end local function joinLanguageList(languages) if not languages or #languages == 0 then return nil end table.sort(languages, function(a, b) return manxSort(a.text, b.text) end) local parts = {} for _, language in ipairs(languages) do local text = language.text text = '[[' .. text .. '|' .. text .. ']]' if language.reference then text = text .. language.reference end table.insert(parts, text) end if #parts == 0 then return nil end return '<div class="hlist">' .. table.concat(parts, '&nbsp;· ') .. '</div>' end local function splitTopLevel(text, sep) local parts = {} local current = {} local depthCurly = 0 local depthSquare = 0 local len = mw.ustring.len(text) local i = 1 while i <= len do local two = mw.ustring.sub(text, i, i + 1) local one = mw.ustring.sub(text, i, i) if two == "{{" then depthCurly = depthCurly + 1 table.insert(current, two) i = i + 2 elseif two == "}}" and depthCurly > 0 then depthCurly = depthCurly - 1 table.insert(current, two) i = i + 2 elseif two == "[[" then depthSquare = depthSquare + 1 table.insert(current, two) i = i + 2 elseif two == "]]" and depthSquare > 0 then depthSquare = depthSquare - 1 table.insert(current, two) i = i + 2 elseif one == sep and depthCurly == 0 and depthSquare == 0 then table.insert(parts, table.concat(current)) current = {} i = i + 1 else table.insert(current, one) i = i + 1 end end table.insert(parts, table.concat(current)) return parts end local function findTemplateCall(text, namePattern) local searchPattern = "{{%s*" .. namePattern .. "%s*|" local matchStart, matchEnd = mw.ustring.find(text, searchPattern) if not matchStart then return nil end local contentStart = matchEnd + 1 local depth = 1 local i = contentStart local len = mw.ustring.len(text) while i <= len do local two = mw.ustring.sub(text, i, i + 1) if two == "{{" then depth = depth + 1 i = i + 2 elseif two == "}}" then depth = depth - 1 i = i + 2 if depth == 0 then local contentEnd = i - 3 return mw.ustring.sub(text, contentStart, contentEnd) end else i = i + 1 end end return nil end local function extractReferences(text) if not text then return text, nil end local refs = {} local cleaned = mw.ustring.gsub(text, "<ref[^>]*>.-</ref>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.ustring.gsub(cleaned, "<ref[^>]*/>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.text.trim(cleaned) if #refs == 0 then return cleaned, nil end return cleaned, table.concat(refs) end local function countHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local segments = splitTopLevel(inner, "|") local count = 0 for _, segment in ipairs(segments) do local trimmedSegment = mw.text.trim(segment) if trimmedSegment ~= "" and not mw.ustring.find(trimmedSegment, "^[%w_%- ]+=") then count = count + 1 end end return count end local function countListItems(text) if not text or text == "" then return 0 end local hlistCount = countHlistItems(text) if hlistCount then return hlistCount end local count = 0 for _ in mw.text.gsplit(text, ",", true) do count = count + 1 end return count end local function extractHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local items = {} local segments = splitTopLevel(inner, "|") for _, segment in ipairs(segments) do local trimmed = mw.text.trim(segment) if trimmed ~= "" and not mw.ustring.find(trimmed, "^[%w_%- ]+=") then local linkText = mw.ustring.match(trimmed, "%[%[.-|(.+)%]%]") or mw.ustring.match(trimmed, "%[%[(.+)%]%]") or trimmed table.insert(items, mw.text.trim(linkText)) end end return items end local function buildLanguageValue(raw, manualReference, manualNote, frame) if not raw or mw.ustring.lower(mw.text.trim(raw)) == "none" then return nil, 0 end local cleaned, inlineRefs = extractReferences(raw) local count = countListItems(cleaned) local languageNames = extractHlistItems(cleaned) if not languageNames then languageNames = {} for part in mw.text.gsplit(cleaned, ",", true) do local trimmed = mw.text.trim(part) if trimmed ~= "" then table.insert(languageNames, trimmed) end end end table.sort(languageNames, manxSort) local parts = {} for _, name in ipairs(languageNames) do table.insert(parts, '[[' .. name .. '|' .. name .. ']]') end local display = '<div class="hlist">' .. table.concat(parts, '&nbsp;· ') .. '</div>' if manualNote and manualNote ~= "" and frame then local efnOut = frame:expandTemplate{ title = "efn", args = { manualNote } } display = display .. efnOut end if inlineRefs then display = display .. inlineRefs end if manualReference then display = display .. "<ref>" .. manualReference .. "</ref>" end return display, count end local function getLanguageData(args, frame) local officialRaw = getManual(args, { "çhengaghyn_oikoil", "çhengey_oikoil" }) local officialReference = getManual(args, { "imraa_çhengaghyn_oikoil", "imraa_çhengey_oikoil" }) local regionalRaw = getManual(args, { "çhengaghyn_ardjynagh", "çhengey_ardjynagh" }) local regionalReference = getManual(args, { "imraa_çhengaghyn_ardjynagh", "imraa_çhengey_ardjynagh" }) local minorityRaw = getManual(args, { "mynçhengaghyn", "mynçhengey" }) local minorityReference = getManual(args, { "imraa_mynçhengaghyn", "imraa_mynçhengey" }) local otherRaw = getManual(args, { "çhengaghyn", "çhengey" }) local otherReference = getManual(args, { "imraa_çhengaghyn", "imraa_çhengey" }) local otherLabel = getManual(args, { "sorçh_çhengaghyn" }) local officialNote = getManual(args, {"noteyn_çhengaghyn_oikoil", "noteyn_çhengey_oikoil"}) local regionalNote = getManual(args, {"noteyn_çhengaghyn_ardjynagh", "noteyn_çhengey_ardjynagh"}) local minorityNote = getManual(args, {"noteyn_mynçhengaghyn", "noteyn_mynçhengey"}) local otherNote = getManual(args, {"noteyn_çhengaghyn", "noteyn_çhengey"}) local result = { otherLabel = otherLabel } result.official, result.officialCount = buildLanguageValue(officialRaw, officialReference, officialNote, frame) result.regional, result.regionalCount = buildLanguageValue(regionalRaw, regionalReference, regionalNote, frame) result.minority, result.minorityCount = buildLanguageValue(minorityRaw, minorityReference, minorityNote, frame) result.other, result.otherCount = buildLanguageValue(otherRaw, otherReference, otherNote, frame) if not result.official and not result.regional and not result.minority then local classified = classifyLanguages(getLanguagesFromWikidata()) result.official = joinLanguageList(classified.official) result.officialCount = #classified.official result.regional = joinLanguageList(classified.regional) result.regionalCount = #classified.regional result.minority = joinLanguageList(classified.minority) result.minorityCount = #classified.minority end return result end local function buildLanguageRows(args, frame) local data = getLanguageData(args, frame) local rows = {} if data.official then local officialLabel = data.officialCount > 1 and "[[Çhengey oikoil|Çhengaghyn oikoil]]" or "[[Çhengey oikoil]]" local officialRow = '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. officialLabel .. '</th><td style="vertical-align:top;">' .. data.official .. '</td></tr>' if data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn&nbsp;ardjynagh er&nbsp;enney" or "Çhengey&nbsp;ardjynagh er&nbsp;enney" officialRow = officialRow .. '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:normal;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th>' .. '<td style="vertical-align:top;">' .. data.regional .. '</td></tr>' end table.insert(rows, officialRow) elseif data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn ardjynagh er enney" or "Çhengey ardjynagh er enney" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th><td style="vertical-align:top;">' .. data.regional .. '</td></tr>' ) end if data.minority then local minorityLabel = data.minorityCount > 1 and "[[Mynçhengey|Mynçhengaghyn]]" or "[[Mynçhengey]]" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. minorityLabel .. '</th><td style="vertical-align:top;">' .. data.minority .. '</td></tr>' ) end if data.other then local otherLabel = data.otherLabel or (data.otherCount > 1 and "Çhengaghyn" or "Çhengey") table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. otherLabel .. '</th><td style="vertical-align:top;">' .. data.other .. '</td></tr>' ) end if #rows == 0 then return nil end return table.concat(rows) end function p.languages(frame) local args = getArgs(frame) return buildLanguageRows(args, frame) end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCityEntityFromTitle(value) local title = normaliseCityName(value) if title == "" then return nil end local entityId = mw.wikibase.getEntityIdForTitle(title) if not entityId then return nil end return mw.wikibase.getEntity(entityId) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end local note = getManual(args, {"noteyn_preeu-valley"}) if capital then return { text = capital, entity = getCityEntityFromTitle(capital), reference = nil, note = note } end local entity, statement = getWikidataItem("P36") if entity then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or entity:getLabel(), entity = entity, reference = getWikidataReference(statement), note = nil } end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end local note = getManual(args, {"noteyn_ynnyd_reiragh"}) if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil, note = note } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end local note = getManual(args, {"noteyn_balley_smoo"}) if city then return { text = city, entity = getCityEntityFromTitle(city), reference = nil, note = note } end local country = mw.wikibase.getEntityObject() if not country then return nil end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id local target = mw.wikibase.getEntity(targetId) if target and not isDisambiguationPage(target) then local sitelink = target:getSitelink("gvwiki") return { text = sitelink or target:getLabel(), entity = target, reference = getWikidataReference(statement), note = nil } end end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) return { capital = getCapitalData(args), administrative = getAdministrativeCentreData(args), largest = getLargestCityData(args), labels = getCityLabels(args) } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end local function makeCityLink(city) if not city or not city.text then return "" end local title = nil if city.entity then title = city.entity:getSitelink("gvwiki") end if not title or title == "" then title = normaliseCityName(city.text) end if not title or title == "" then return "" end return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local function renderCityCell(cityObj) local text = makeCityLink(cityObj) if cityObj.note and cityObj.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { cityObj.note } } text = text .. efnOut end if cityObj.reference then text = text .. cityObj.reference end if cityObj.entity then local coordinates = makeCoordinates(cityObj.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text end if capital then return renderCityCell(capital) elseif administrative then return renderCityCell(administrative) elseif largest then return renderCityCell(largest) end return nil end function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} local function formatLegacyRow(label, cityObj) local text = makeCityLink(cityObj) if cityObj.note and cityObj.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { cityObj.note } } text = text .. efnOut end if cityObj.reference then text = text .. cityObj.reference end if cityObj.entity then local coordinates = makeCoordinates(cityObj.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end return "'''" .. label .. "''': " .. text end if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end table.insert(rows, formatLegacyRow(label, capital)) end if administrative then local label = labels.administrative or "Ynnyd reiragh" table.insert(rows, formatLegacyRow(label, administrative)) end if largest then table.insert(rows, formatLegacyRow("Balley smoo", largest)) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- MAIN -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -------------------------------------------------- -- HEADER -------------------------------------------------- do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -------------------------------------------------- -- FLAG / ARMS -------------------------------------------------- do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -------------------------------------------------- -- MOTTO / ANTHEM -------------------------------------------------- do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -------------------------------------------------- -- CAPITAL / ADMINISTRATIVE CENTRE / LARGEST CITY -------------------------------------------------- do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels if capital or administrative or largest then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '"></td></tr>' ) end if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.note and capital.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { capital.note } } text = text .. efnOut end if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end if administrative then local text = makeCityLink(administrative) if administrative.note and administrative.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { administrative.note } } text = text .. efnOut end if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end if largest then local text = makeCityLink(largest) if largest.note and largest.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { largest.note } } text = text .. efnOut end if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- do local languageRows = buildLanguageRows(args, frame) if languageRows then table.insert(rows, languageRows) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p b2t8hygt6jnq67twuyyv4wc29y3xtkw 392902 392901 2026-09-07T02:32:40Z MacTire02 219 ++ 392902 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- DISAMBIGUATION GUARD -------------------------------------------------- local function isDisambiguationPage(entity) if not entity then return false end local statements = entity:getBestStatements("P31") if not statements then return false end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" and mainsnak.datavalue.value.id == "Q4167410" then return true end end return false end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity and not isDisambiguationPage(linkedEntity) then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- FLAG BORDER CHECK -------------------------------------------------- local NON_RECTANGULAR_FLAGS = { ["Flag of Nepal.svg"] = true, ["Flag of Ohio.svg"] = true, ["Flag of Switzerland.svg"] = true, } local function needsFlagBorder(flagFile) if not flagFile then return true end if NON_RECTANGULAR_FLAGS[flagFile] then return false end local lowerFile = mw.ustring.lower(flagFile) if mw.ustring.find(lowerFile, "nepal") then return false end return true end -------------------------------------------------- -- MULTI-FLAG SUPPORT -------------------------------------------------- local function getFlagData(args) local flag = getManual(args, {"jalloo_brattagh"}) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local flag2 = getManual(args, {"jalloo_brattagh_2", "jalloo_brattagh_elley"}) if flag2 and mw.ustring.lower(flag2) == "none" then flag2 = nil elseif not flag2 then flag2 = getWikidataImage("P163") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end local arms2 = getManual(args, { "jalloo_armys_2", "jalloo_cleinney_2" }) if arms2 and mw.ustring.lower(arms2) == "none" then arms2 = nil elseif not arms2 then arms2 = getWikidataImage("P237") end if not flag and not flag2 and not arms and not arms2 then return nil end local name = getCountryGenitive(args) or "" local data = { flags = {}, armses = {} } if flag then local flagWidth = getManual(args, {"lheead_brattagh"}) or "125px" local hasBorder = needsFlagBorder(flag) table.insert(data.flags, { image = flag, width = flagWidth, hasBorder = hasBorder, link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh"}) or "Brattagh", isPrimary = true }) end if flag2 then local flag2Width = getManual(args, {"lheead_brattagh_2", "lheead_brattagh"}) or "100px" local hasBorder2 = needsFlagBorder(flag2) table.insert(data.flags, { image = flag2, width = flag2Width, hasBorder = hasBorder2, link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh_2"}) or "Brattagh elley", isPrimary = false }) end if arms then local kind = getManual(args, {"art_sorçh_cowrey"}) or getManual(args, {"sorçh_cowrey"}) or "Armys" table.insert(data.armses, { image = arms, width = getManual(args, {"lheead_armys", "lheead_cleinney", "lheead_cowrey"}) or "85px", link = kind .. " " .. name, label = getManual(args, {"sorçh_cowrey"}) or "Armys", isPrimary = true }) end if arms2 then table.insert(data.armses, { image = arms2, width = getManual(args, {"lheead_armys_2", "lheead_cleinney_2"}) or "85px", link = "Armys " .. name, label = getManual(args, {"sorçh_cowrey_2"}) or "Armys", isPrimary = false }) end return data end local function buildFlagArmsBlock(args) local data = getFlagData(args) if not data then return nil end local imageCells = {} local captionCells = {} local hasFlags = #data.flags > 0 local hasArms = #data.armses > 0 if hasFlags then local flagContent = {} for i, flagData in ipairs(data.flags) do local borderStyle = "" if flagData.hasBorder then borderStyle = '|style="border:1px solid #a2a9b1;"' end local flagImage = '[[Coadan:' .. flagData.image .. '|' .. flagData.width .. borderStyle .. ']]' table.insert(flagContent, flagImage) end local combinedFlags = table.concat(flagContent, '<br/>') table.insert(imageCells, '<td align="center" style="' .. (hasArms and "width:58%; " or "width:100%; ") .. 'vertical-align:middle;">' .. combinedFlags .. '</td>' ) local flagCaptions = {} for i, flagData in ipairs(data.flags) do table.insert(flagCaptions, '<small>[[' .. flagData.link .. '|' .. flagData.label .. ']]</small>' ) end table.insert(captionCells, '<td align="center">' .. table.concat(flagCaptions, '<br/>') .. '</td>' ) end if hasArms then local armsContent = {} for i, armsData in ipairs(data.armses) do local armsImage = '[[Coadan:' .. armsData.image .. '|' .. armsData.width .. ']]' table.insert(armsContent, armsImage) end local combinedArms = table.concat(armsContent, '<br/>') table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">' .. combinedArms .. '</td>' ) local armsCaptions = {} for i, armsData in ipairs(data.armses) do table.insert(armsCaptions, '<small>[[' .. armsData.link .. '|' .. armsData.label .. ']]</small>' ) end table.insert(captionCells, '<td align="center">' .. table.concat(armsCaptions, '<br/>') .. '</td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) -- 1. Extract manual parameters local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) local chyndaa = getManual(args, { "çhyndaa_jarroo-raa", "chyndaa_jarroo-raa", "çhyndaa_jarroo_raa", "chyndaa_jarroo_raa" }) local tessenLettyraghey = getManual(args, { "tessen-lettyraghey_jarroo-raa", "tessen-lettyraghey_jarroo_raa" }) -- 2. Evaluate actual text content source local finalMottoText = nil local finalReference = nil if motto then if mw.ustring.lower(motto) == "none" then return nil end finalMottoText = motto if reference then finalReference = "<ref>" .. reference .. "</ref>" end else -- Fall back to Wikidata for text strings, but RETAIN manual overrides local entity = mw.wikibase.getEntityObject() if entity then local statements = entity:getBestStatements("P1451") if statements and #statements > 0 then for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then finalMottoText = value.text finalReference = getWikidataReference(statement) break end end end end end end -- 3. Return consolidated data package if finalMottoText then return { text = finalMottoText, reference = finalReference, chyndaa = chyndaa, -- Always preserves your local translation parameters tessenLettyraghey = tessenLettyraghey -- Always preserves your local transliteration parameters } end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, {"arrane_ashoonagh"}) local royal = getManual(args, {"arrane_reeoil"}) local other = getManual(args, {"arrane"}) local nationalReference = getManual(args, {"imraa_arrane_ashoonagh"}) local royalReference = getManual(args, {"imraa_arrane_reeoil"}) local otherReference = getManual(args, {"imraa_arrane"}) local nationalAudio = getManual(args, {"coadan_arrane_ashoonagh"}) local royalAudio = getManual(args, {"coadan_arrane_reeoil"}) local otherAudio = getManual(args, {"coadan_arrane"}) local nationalNote = getManual(args, {"noteyn_arrane_ashoonagh"}) local royalNote = getManual(args, {"noteyn_arrane_reeoil"}) local otherNote = getManual(args, {"noteyn_arrane"}) local nationalChyndaa = getManual(args, {"çhyndaa_arrane_ashoonagh", "chyndaa_arrane_ashoonagh"}) local royalChyndaa = getManual(args, {"çhyndaa_arrane_reeoil", "chyndaa_arrane_reeoil"}) local otherChyndaa = getManual(args, {"çhyndaa_arrane", "chyndaa_arrane"}) local nationalTessen = getManual(args, {"tessen-lettyraghey_arrane_ashoonagh"}) local royalTessen = getManual(args, {"tessen-lettyraghey_arrane_reeoil"}) local otherTessen = getManual(args, {"tessen-lettyraghey_arrane"}) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and ("<ref>" .. nationalReference .. "</ref>") or nil, audio = nationalAudio, note = nationalNote, chyndaa = nationalChyndaa, tessenLettyraghey = nationalTessen } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and ("<ref>" .. royalReference .. "</ref>") or nil, audio = royalAudio, note = royalNote, chyndaa = royalChyndaa, tessenLettyraghey = royalTessen } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and ("<ref>" .. otherReference .. "</ref>") or nil, audio = otherAudio, note = otherNote, chyndaa = otherChyndaa, tessenLettyraghey = otherTessen } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS OUTPUT -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local baseText = motto.text baseText = mw.text.trim(baseText):gsub('^["“]', ''):gsub('["”]$', '') if not mw.ustring.find(baseText, "%[%[") then baseText = "''" .. baseText .. "''" end if motto.tessenLettyraghey and motto.tessenLettyraghey ~= "" then baseText = baseText .. " (''" .. motto.tessenLettyraghey .. "'')" end if motto.chyndaa and motto.chyndaa ~= "" then baseText = baseText .. " <br/><small>“" .. motto.chyndaa .. "”</small>" end if motto.reference then baseText = baseText .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. baseText) end local function formatAnthemRow(label, anthemObj) if not anthemObj or not anthemObj.text then return nil end local cleanText = anthemObj.text cleanText = mw.text.trim(cleanText):gsub('^["...]', ''):gsub('["...]$', '') if not mw.ustring.find(cleanText, "%[%[") then cleanText = '[[' .. cleanText .. '|' .. cleanText .. ']]' end local display = '“' .. cleanText .. '”' if anthemObj.tessenLettyraghey and anthemObj.tessenLettyraghey ~= "" then display = display .. " (''" .. anthemObj.tessenLettyraghey .. "'')" end if anthemObj.chyndaa and anthemObj.chyndaa ~= "" then display = display .. " <br/><small>“" .. anthemObj.chyndaa .. "”</small>" end if anthemObj.note and anthemObj.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { anthemObj.note } } display = display .. efnOut end if anthemObj.reference then display = display .. anthemObj.reference end if anthemObj.audio and anthemObj.audio ~= "" then display = display .. '<br/><div style="text-align:center; margin-top:0.3em;">[[Coadan:' .. anthemObj.audio .. '|center]]</div>' end return "'''" .. label .. ":&nbsp;'''" .. display end local nationalRow = formatAnthemRow("[[Arrane ashoonagh]]", anthems.national) if nationalRow then table.insert(rows, nationalRow) end local otherRow = formatAnthemRow("Anthym", anthems.other) if otherRow then table.insert(rows, otherRow) end local royalRow = formatAnthemRow("[[Arrane reeoil]]", anthems.royal) if royalRow then table.insert(rows, royalRow) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- local function getLanguagesFromWikidata() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P37") if not statements or #statements == 0 then return {} end local languages = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local langEntity = mw.wikibase.getEntity(id) if langEntity then local label = langEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(languages, { text = label, role = role, reference = getWikidataReference(statement) }) end end end end return languages end local function classifyLanguages(languages) local result = { official = {}, regional = {}, minority = {} } for _, language in ipairs(languages) do local role = language.role or "" local lowerRole = mw.ustring.lower(role) if mw.ustring.find(lowerRole, "minority") then table.insert(result.minority, language) elseif mw.ustring.find(lowerRole, "regional") then table.insert(result.regional, language) else table.insert(result.official, language) end end return result end local function manxSort(a, b) local function normalize(text) text = mw.ustring.lower(text) text = mw.ustring.gsub(text, "çh", "ch") return text end return normalize(a) < normalize(b) end local function joinLanguageList(languages) if not languages or #languages == 0 then return nil end table.sort(languages, function(a, b) return manxSort(a.text, b.text) end) local parts = {} for _, language in ipairs(languages) do local text = language.text text = '[[' .. text .. '|' .. text .. ']]' if language.reference then text = text .. language.reference end table.insert(parts, text) end if #parts == 0 then return nil end return '<div class="hlist">' .. table.concat(parts, '&nbsp;· ') .. '</div>' end local function splitTopLevel(text, sep) local parts = {} local current = {} local depthCurly = 0 local depthSquare = 0 local len = mw.ustring.len(text) local i = 1 while i <= len do local two = mw.ustring.sub(text, i, i + 1) local one = mw.ustring.sub(text, i, i) if two == "{{" then depthCurly = depthCurly + 1 table.insert(current, two) i = i + 2 elseif two == "}}" and depthCurly > 0 then depthCurly = depthCurly - 1 table.insert(current, two) i = i + 2 elseif two == "[[" then depthSquare = depthSquare + 1 table.insert(current, two) i = i + 2 elseif two == "]]" and depthSquare > 0 then depthSquare = depthSquare - 1 table.insert(current, two) i = i + 2 elseif one == sep and depthCurly == 0 and depthSquare == 0 then table.insert(parts, table.concat(current)) current = {} i = i + 1 else table.insert(current, one) i = i + 1 end end table.insert(parts, table.concat(current)) return parts end local function findTemplateCall(text, namePattern) local searchPattern = "{{%s*" .. namePattern .. "%s*|" local matchStart, matchEnd = mw.ustring.find(text, searchPattern) if not matchStart then return nil end local contentStart = matchEnd + 1 local depth = 1 local i = contentStart local len = mw.ustring.len(text) while i <= len do local two = mw.ustring.sub(text, i, i + 1) if two == "{{" then depth = depth + 1 i = i + 2 elseif two == "}}" then depth = depth - 1 i = i + 2 if depth == 0 then local contentEnd = i - 3 return mw.ustring.sub(text, contentStart, contentEnd) end else i = i + 1 end end return nil end local function extractReferences(text) if not text then return text, nil end local refs = {} local cleaned = mw.ustring.gsub(text, "<ref[^>]*>.-</ref>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.ustring.gsub(cleaned, "<ref[^>]*/>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.text.trim(cleaned) if #refs == 0 then return cleaned, nil end return cleaned, table.concat(refs) end local function countHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local segments = splitTopLevel(inner, "|") local count = 0 for _, segment in ipairs(segments) do local trimmedSegment = mw.text.trim(segment) if trimmedSegment ~= "" and not mw.ustring.find(trimmedSegment, "^[%w_%- ]+=") then count = count + 1 end end return count end local function countListItems(text) if not text or text == "" then return 0 end local hlistCount = countHlistItems(text) if hlistCount then return hlistCount end local count = 0 for _ in mw.text.gsplit(text, ",", true) do count = count + 1 end return count end local function extractHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local items = {} local segments = splitTopLevel(inner, "|") for _, segment in ipairs(segments) do local trimmed = mw.text.trim(segment) if trimmed ~= "" and not mw.ustring.find(trimmed, "^[%w_%- ]+=") then local linkText = mw.ustring.match(trimmed, "%[%[.-|(.+)%]%]") or mw.ustring.match(trimmed, "%[%[(.+)%]%]") or trimmed table.insert(items, mw.text.trim(linkText)) end end return items end local function buildLanguageValue(raw, manualReference, manualNote, frame) if not raw or mw.ustring.lower(mw.text.trim(raw)) == "none" then return nil, 0 end local cleaned, inlineRefs = extractReferences(raw) local count = countListItems(cleaned) local languageNames = extractHlistItems(cleaned) if not languageNames then languageNames = {} for part in mw.text.gsplit(cleaned, ",", true) do local trimmed = mw.text.trim(part) if trimmed ~= "" then table.insert(languageNames, trimmed) end end end table.sort(languageNames, manxSort) local parts = {} for _, name in ipairs(languageNames) do table.insert(parts, '[[' .. name .. '|' .. name .. ']]') end local display = '<div class="hlist">' .. table.concat(parts, '&nbsp;· ') .. '</div>' if manualNote and manualNote ~= "" and frame then local efnOut = frame:expandTemplate{ title = "efn", args = { manualNote } } display = display .. efnOut end if inlineRefs then display = display .. inlineRefs end if manualReference then display = display .. "<ref>" .. manualReference .. "</ref>" end return display, count end local function getLanguageData(args, frame) local officialRaw = getManual(args, { "çhengaghyn_oikoil", "çhengey_oikoil" }) local officialReference = getManual(args, { "imraa_çhengaghyn_oikoil", "imraa_çhengey_oikoil" }) local regionalRaw = getManual(args, { "çhengaghyn_ardjynagh", "çhengey_ardjynagh" }) local regionalReference = getManual(args, { "imraa_çhengaghyn_ardjynagh", "imraa_çhengey_ardjynagh" }) local minorityRaw = getManual(args, { "mynçhengaghyn", "mynçhengey" }) local minorityReference = getManual(args, { "imraa_mynçhengaghyn", "imraa_mynçhengey" }) local otherRaw = getManual(args, { "çhengaghyn", "çhengey" }) local otherReference = getManual(args, { "imraa_çhengaghyn", "imraa_çhengey" }) local otherLabel = getManual(args, { "sorçh_çhengaghyn" }) local officialNote = getManual(args, {"noteyn_çhengaghyn_oikoil", "noteyn_çhengey_oikoil"}) local regionalNote = getManual(args, {"noteyn_çhengaghyn_ardjynagh", "noteyn_çhengey_ardjynagh"}) local minorityNote = getManual(args, {"noteyn_mynçhengaghyn", "noteyn_mynçhengey"}) local otherNote = getManual(args, {"noteyn_çhengaghyn", "noteyn_çhengey"}) local result = { otherLabel = otherLabel } result.official, result.officialCount = buildLanguageValue(officialRaw, officialReference, officialNote, frame) result.regional, result.regionalCount = buildLanguageValue(regionalRaw, regionalReference, regionalNote, frame) result.minority, result.minorityCount = buildLanguageValue(minorityRaw, minorityReference, minorityNote, frame) result.other, result.otherCount = buildLanguageValue(otherRaw, otherReference, otherNote, frame) if not result.official and not result.regional and not result.minority then local classified = classifyLanguages(getLanguagesFromWikidata()) result.official = joinLanguageList(classified.official) result.officialCount = #classified.official result.regional = joinLanguageList(classified.regional) result.regionalCount = #classified.regional result.minority = joinLanguageList(classified.minority) result.minorityCount = #classified.minority end return result end local function buildLanguageRows(args, frame) local data = getLanguageData(args, frame) local rows = {} if data.official then local officialLabel = data.officialCount > 1 and "[[Çhengey oikoil|Çhengaghyn oikoil]]" or "[[Çhengey oikoil]]" local officialRow = '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. officialLabel .. '</th><td style="vertical-align:top;">' .. data.official .. '</td></tr>' if data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn&nbsp;ardjynagh er&nbsp;enney" or "Çhengey&nbsp;ardjynagh er&nbsp;enney" officialRow = officialRow .. '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:normal;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th>' .. '<td style="vertical-align:top;">' .. data.regional .. '</td></tr>' end table.insert(rows, officialRow) elseif data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn ardjynagh er enney" or "Çhengey ardjynagh er enney" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th><td style="vertical-align:top;">' .. data.regional .. '</td></tr>' ) end if data.minority then local minorityLabel = data.minorityCount > 1 and "[[Mynçhengey|Mynçhengaghyn]]" or "[[Mynçhengey]]" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. minorityLabel .. '</th><td style="vertical-align:top;">' .. data.minority .. '</td></tr>' ) end if data.other then local otherLabel = data.otherLabel or (data.otherCount > 1 and "Çhengaghyn" or "Çhengey") table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. otherLabel .. '</th><td style="vertical-align:top;">' .. data.other .. '</td></tr>' ) end if #rows == 0 then return nil end return table.concat(rows) end function p.languages(frame) local args = getArgs(frame) return buildLanguageRows(args, frame) end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCityEntityFromTitle(value) local title = normaliseCityName(value) if title == "" then return nil end local entityId = mw.wikibase.getEntityIdForTitle(title) if not entityId then return nil end return mw.wikibase.getEntity(entityId) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end local note = getManual(args, {"noteyn_preeu-valley"}) if capital then return { text = capital, entity = getCityEntityFromTitle(capital), reference = nil, note = note } end local entity, statement = getWikidataItem("P36") if entity then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or entity:getLabel(), entity = entity, reference = getWikidataReference(statement), note = nil } end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end local note = getManual(args, {"noteyn_ynnyd_reiragh"}) if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil, note = note } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end local note = getManual(args, {"noteyn_balley_smoo"}) if city then return { text = city, entity = getCityEntityFromTitle(city), reference = nil, note = note } end local country = mw.wikibase.getEntityObject() if not country then return nil end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id local target = mw.wikibase.getEntity(targetId) if target and not isDisambiguationPage(target) then local sitelink = target:getSitelink("gvwiki") return { text = sitelink or target:getLabel(), entity = target, reference = getWikidataReference(statement), note = nil } end end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) return { capital = getCapitalData(args), administrative = getAdministrativeCentreData(args), largest = getLargestCityData(args), labels = getCityLabels(args) } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end -- Check if the raw text input for the largest city is explicitly set to "preeu-valley" if largest.text and mw.ustring.lower(mw.text.trim(largest.text)) == "preeu-valley" then return true end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end local function makeCityLink(city) if not city or not city.text then return "" end local title = nil if city.entity then title = city.entity:getSitelink("gvwiki") end if not title or title == "" then title = normaliseCityName(city.text) end if not title or title == "" then return "" end return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local function renderCityCell(cityObj) local text = makeCityLink(cityObj) if cityObj.note and cityObj.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { cityObj.note } } text = text .. efnOut end if cityObj.reference then text = text .. cityObj.reference end if cityObj.entity then local coordinates = makeCoordinates(cityObj.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text end if capital then return renderCityCell(capital) elseif administrative then return renderCityCell(administrative) elseif largest then return renderCityCell(largest) end return nil end function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} local function formatLegacyRow(label, cityObj) local text = makeCityLink(cityObj) if cityObj.note and cityObj.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { cityObj.note } } text = text .. efnOut end if cityObj.reference then text = text .. cityObj.reference end if cityObj.entity then local coordinates = makeCoordinates(cityObj.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end return "'''" .. label .. "''': " .. text end if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end table.insert(rows, formatLegacyRow(label, capital)) end if administrative then local label = labels.administrative or "Ynnyd reiragh" table.insert(rows, formatLegacyRow(label, administrative)) end if largest then table.insert(rows, formatLegacyRow("Balley smoo", largest)) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- MAIN -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -------------------------------------------------- -- HEADER -------------------------------------------------- do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -------------------------------------------------- -- FLAG / ARMS -------------------------------------------------- do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -------------------------------------------------- -- MOTTO / ANTHEM -------------------------------------------------- do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -------------------------------------------------- -- CAPITAL / ADMINISTRATIVE CENTRE / LARGEST CITY -------------------------------------------------- do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels if capital or administrative or largest then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '"></td></tr>' ) end if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end local text = makeCityLink(capital) if capital.note and capital.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { capital.note } } text = text .. efnOut end if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. label .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end if administrative then local text = makeCityLink(administrative) if administrative.note and administrative.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { administrative.note } } text = text .. efnOut end if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. (labels.administrative or "Ynnyd reiragh") .. ']]' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end if largest then local text = makeCityLink(largest) if largest.note and largest.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { largest.note } } text = text .. efnOut end if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="' .. 'vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="' .. 'vertical-align:top;">' .. text .. '</td></tr>' ) end end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- do local languageRows = buildLanguageRows(args, frame) if languageRows then table.insert(rows, languageRows) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p 25qfnoecxpciixr81h0zbilyn9xmmos 392903 392902 2026-09-07T02:37:13Z MacTire02 219 ++ 392903 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local langData = mw.loadData("Module:Lang/data") local langNameTable = langData.lang_name_table.lang local langOverrideTable = langData.override -------------------------------------------------- -- ARGUMENTS -------------------------------------------------- local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -------------------------------------------------- -- WIKIDATA IMAGE -------------------------------------------------- local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- DISAMBIGUATION GUARD -------------------------------------------------- local function isDisambiguationPage(entity) if not entity then return false end local statements = entity:getBestStatements("P31") if not statements then return false end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" and mainsnak.datavalue.value.id == "Q4167410" then return true end end return false end -------------------------------------------------- -- WIKIDATA ITEM -------------------------------------------------- local function getWikidataItem(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local linkedEntity = mw.wikibase.getEntity(id) if linkedEntity and not isDisambiguationPage(linkedEntity) then return linkedEntity, statement end end end return nil end -------------------------------------------------- -- WIKIDATA REFERENCE -------------------------------------------------- local function getWikidataReference(statement) if not statement or not statement.references then return nil end for _, reference in ipairs(statement.references) do local snaks = reference.snaks if snaks and snaks["P854"] then for _, snak in ipairs(snaks["P854"]) do if snak and snak.snaktype == "value" and snak.datavalue and snak.datavalue.type == "string" then local url = snak.datavalue.value if url and url ~= "" then return "<ref>[" .. url .. " " .. url .. "]</ref>" end end end end end return nil end -------------------------------------------------- -- AUDIO -------------------------------------------------- local function getWikidataAudio(entity) if not entity then return nil end local statements = entity:getBestStatements("P51") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end -------------------------------------------------- -- NAME / GENITIVE -------------------------------------------------- local function getRawCountryName(args) local name = getManual(args, { "ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer" }) if name then return name end local title = mw.title.getCurrentTitle() if title then return title.text end return nil end local function getCountryName(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.name(name) end local function getCountryGenitive(args) local name = getRawCountryName(args) if not name then return nil end return enmynCheerey.genitive(name) end -------------------------------------------------- -- OFFICIAL NAMES -------------------------------------------------- local function getOfficialNames() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P1448") if not statements or #statements == 0 then return {} end local names = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then local language = value.language or "" table.insert(names, { text = value.text, language = language, reference = getWikidataReference(statement) }) end end end return names end -------------------------------------------------- -- LANGUAGE NAME -------------------------------------------------- local function getLanguageName(code) if not code or code == "" then return nil end if langOverrideTable and langOverrideTable[code] then return langOverrideTable[code] end if langNameTable and langNameTable[code] then return langNameTable[code] end return code end -------------------------------------------------- -- FLAG BORDER CHECK -------------------------------------------------- local NON_RECTANGULAR_FLAGS = { ["Flag of Nepal.svg"] = true, ["Flag of Ohio.svg"] = true, ["Flag of Switzerland.svg"] = true, } local function needsFlagBorder(flagFile) if not flagFile then return true end if NON_RECTANGULAR_FLAGS[flagFile] then return false end local lowerFile = mw.ustring.lower(flagFile) if mw.ustring.find(lowerFile, "nepal") then return false end return true end -------------------------------------------------- -- MULTI-FLAG SUPPORT -------------------------------------------------- local function getFlagData(args) local flag = getManual(args, {"jalloo_brattagh"}) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local flag2 = getManual(args, {"jalloo_brattagh_2", "jalloo_brattagh_elley"}) if flag2 and mw.ustring.lower(flag2) == "none" then flag2 = nil elseif not flag2 then flag2 = getWikidataImage("P163") end local arms = getManual(args, { "jalloo_armys", "jalloo_cleinney", "jalloo_cowrey" }) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end local arms2 = getManual(args, { "jalloo_armys_2", "jalloo_cleinney_2" }) if arms2 and mw.ustring.lower(arms2) == "none" then arms2 = nil elseif not arms2 then arms2 = getWikidataImage("P237") end if not flag and not flag2 and not arms and not arms2 then return nil end local name = getCountryGenitive(args) or "" local data = { flags = {}, armses = {} } if flag then local flagWidth = getManual(args, {"lheead_brattagh"}) or "125px" local hasBorder = needsFlagBorder(flag) table.insert(data.flags, { image = flag, width = flagWidth, hasBorder = hasBorder, link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh"}) or "Brattagh", isPrimary = true }) end if flag2 then local flag2Width = getManual(args, {"lheead_brattagh_2", "lheead_brattagh"}) or "100px" local hasBorder2 = needsFlagBorder(flag2) table.insert(data.flags, { image = flag2, width = flag2Width, hasBorder = hasBorder2, link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh_2"}) or "Brattagh elley", isPrimary = false }) end if arms then local kind = getManual(args, {"art_sorçh_cowrey"}) or getManual(args, {"sorçh_cowrey"}) or "Armys" table.insert(data.armses, { image = arms, width = getManual(args, {"lheead_armys", "lheead_cleinney", "lheead_cowrey"}) or "85px", link = kind .. " " .. name, label = getManual(args, {"sorçh_cowrey"}) or "Armys", isPrimary = true }) end if arms2 then table.insert(data.armses, { image = arms2, width = getManual(args, {"lheead_armys_2", "lheead_cleinney_2"}) or "85px", link = "Armys " .. name, label = getManual(args, {"sorçh_cowrey_2"}) or "Armys", isPrimary = false }) end return data end local function buildFlagArmsBlock(args) local data = getFlagData(args) if not data then return nil end local imageCells = {} local captionCells = {} local hasFlags = #data.flags > 0 local hasArms = #data.armses > 0 if hasFlags then local flagContent = {} for i, flagData in ipairs(data.flags) do local borderStyle = "" if flagData.hasBorder then borderStyle = '|style="border:1px solid #a2a9b1;"' end local flagImage = '[[Coadan:' .. flagData.image .. '|' .. flagData.width .. borderStyle .. ']]' table.insert(flagContent, flagImage) end local combinedFlags = table.concat(flagContent, '<br/>') table.insert(imageCells, '<td align="center" style="' .. (hasArms and "width:58%; " or "width:100%; ") .. 'vertical-align:middle;">' .. combinedFlags .. '</td>' ) local flagCaptions = {} for i, flagData in ipairs(data.flags) do table.insert(flagCaptions, '<small>[[' .. flagData.link .. '|' .. flagData.label .. ']]</small>' ) end table.insert(captionCells, '<td align="center">' .. table.concat(flagCaptions, '<br/>') .. '</td>' ) end if hasArms then local armsContent = {} for i, armsData in ipairs(data.armses) do local armsImage = '[[Coadan:' .. armsData.image .. '|' .. armsData.width .. ']]' table.insert(armsContent, armsImage) end local combinedArms = table.concat(armsContent, '<br/>') table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">' .. combinedArms .. '</td>' ) local armsCaptions = {} for i, armsData in ipairs(data.armses) do table.insert(armsCaptions, '<small>[[' .. armsData.link .. '|' .. armsData.label .. ']]</small>' ) end table.insert(captionCells, '<td align="center">' .. table.concat(armsCaptions, '<br/>') .. '</td>' ) end return '<table align="center" style="width:100%; background:none;">' .. '<tr>' .. table.concat(imageCells) .. '</tr>' .. '<tr>' .. table.concat(captionCells) .. '</tr>' .. '</table>' end -------------------------------------------------- -- MOTTO -------------------------------------------------- local function getMottoData(args) -- 1. Extract manual parameters local motto = getManual(args, { "jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa" }) local reference = getManual(args, { "imraa_jarroo_raa", "imraa_jarroo-raa" }) local chyndaa = getManual(args, { "çhyndaa_jarroo-raa", "chyndaa_jarroo-raa", "çhyndaa_jarroo_raa", "chyndaa_jarroo_raa" }) local tessenLettyraghey = getManual(args, { "tessen-lettyraghey_jarroo-raa", "tessen-lettyraghey_jarroo_raa" }) -- 2. Evaluate actual text content source local finalMottoText = nil local finalReference = nil if motto then if mw.ustring.lower(motto) == "none" then return nil end finalMottoText = motto if reference then finalReference = "<ref>" .. reference .. "</ref>" end else -- Fall back to Wikidata for text strings, but RETAIN manual overrides local entity = mw.wikibase.getEntityObject() if entity then local statements = entity:getBestStatements("P1451") if statements and #statements > 0 then for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "monolingualtext" then local value = mainsnak.datavalue.value if value and value.text and value.text ~= "" then finalMottoText = value.text finalReference = getWikidataReference(statement) break end end end end end end -- 3. Return consolidated data package if finalMottoText then return { text = finalMottoText, reference = finalReference, chyndaa = chyndaa, -- Always preserves your local translation parameters tessenLettyraghey = tessenLettyraghey -- Always preserves your local transliteration parameters } end return nil end -------------------------------------------------- -- ANTHEMS -------------------------------------------------- local function getAnthems() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P85") if not statements or #statements == 0 then return {} end local anthems = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local anthemEntity = mw.wikibase.getEntity(id) if anthemEntity then local label = anthemEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(anthems, { text = label, role = role, reference = getWikidataReference(statement), audio = getWikidataAudio(anthemEntity) }) end end end end return anthems end local function classifyAnthems(anthems) local result = { national = nil, royal = nil, other = nil } for _, anthem in ipairs(anthems) do local role = anthem.role or "" local lowerRole = mw.ustring.lower(role) if not result.royal and mw.ustring.find(lowerRole, "royal") then result.royal = anthem elseif not result.national and ( mw.ustring.find(lowerRole, "national") or mw.ustring.find(lowerRole, "state anthem") ) then result.national = anthem elseif not result.other then result.other = anthem end end if not result.national and result.other then result.national = result.other result.other = nil end return result end local function getAnthemData(args) local national = getManual(args, {"arrane_ashoonagh"}) local royal = getManual(args, {"arrane_reeoil"}) local other = getManual(args, {"arrane"}) local nationalReference = getManual(args, {"imraa_arrane_ashoonagh"}) local royalReference = getManual(args, {"imraa_arrane_reeoil"}) local otherReference = getManual(args, {"imraa_arrane"}) local nationalAudio = getManual(args, {"coadan_arrane_ashoonagh"}) local royalAudio = getManual(args, {"coadan_arrane_reeoil"}) local otherAudio = getManual(args, {"coadan_arrane"}) local nationalNote = getManual(args, {"noteyn_arrane_ashoonagh"}) local royalNote = getManual(args, {"noteyn_arrane_reeoil"}) local otherNote = getManual(args, {"noteyn_arrane"}) local nationalChyndaa = getManual(args, {"çhyndaa_arrane_ashoonagh", "chyndaa_arrane_ashoonagh"}) local royalChyndaa = getManual(args, {"çhyndaa_arrane_reeoil", "chyndaa_arrane_reeoil"}) local otherChyndaa = getManual(args, {"çhyndaa_arrane", "chyndaa_arrane"}) local nationalTessen = getManual(args, {"tessen-lettyraghey_arrane_ashoonagh"}) local royalTessen = getManual(args, {"tessen-lettyraghey_arrane_reeoil"}) local otherTessen = getManual(args, {"tessen-lettyraghey_arrane"}) local result = { national = nil, royal = nil, other = nil } if national and mw.ustring.lower(national) ~= "none" then result.national = { text = national, reference = nationalReference and ("<ref>" .. nationalReference .. "</ref>") or nil, audio = nationalAudio, note = nationalNote, chyndaa = nationalChyndaa, tessenLettyraghey = nationalTessen } end if royal and mw.ustring.lower(royal) ~= "none" then result.royal = { text = royal, reference = royalReference and ("<ref>" .. royalReference .. "</ref>") or nil, audio = royalAudio, note = royalNote, chyndaa = royalChyndaa, tessenLettyraghey = royalTessen } end if other and mw.ustring.lower(other) ~= "none" then result.other = { text = other, reference = otherReference and ("<ref>" .. otherReference .. "</ref>") or nil, audio = otherAudio, note = otherNote, chyndaa = otherChyndaa, tessenLettyraghey = otherTessen } end if not national and not royal and not other then local anthems = classifyAnthems(getAnthems()) result.national = anthems.national result.royal = anthems.royal result.other = anthems.other end return result end -------------------------------------------------- -- SYMBOLS OUTPUT -------------------------------------------------- function p.symbols(frame) local args = getArgs(frame) local motto = getMottoData(args) local anthems = getAnthemData(args) local rows = {} if motto then local baseText = motto.text baseText = mw.text.trim(baseText):gsub('^["“]', ''):gsub('["”]$', '') if not mw.ustring.find(baseText, "%[%[") then baseText = "''" .. baseText .. "''" end if motto.tessenLettyraghey and motto.tessenLettyraghey ~= "" then baseText = baseText .. " (''" .. motto.tessenLettyraghey .. "'')" end if motto.chyndaa and motto.chyndaa ~= "" then baseText = baseText .. " <br/><small>“" .. motto.chyndaa .. "”</small>" end if motto.reference then baseText = baseText .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. baseText) end local function formatAnthemRow(label, anthemObj) if not anthemObj or not anthemObj.text then return nil end local cleanText = anthemObj.text cleanText = mw.text.trim(cleanText):gsub('^["...]', ''):gsub('["...]$', '') if not mw.ustring.find(cleanText, "%[%[") then cleanText = '[[' .. cleanText .. '|' .. cleanText .. ']]' end local display = '“' .. cleanText .. '”' if anthemObj.tessenLettyraghey and anthemObj.tessenLettyraghey ~= "" then display = display .. " (''" .. anthemObj.tessenLettyraghey .. "'')" end if anthemObj.chyndaa and anthemObj.chyndaa ~= "" then display = display .. " <br/><small>“" .. anthemObj.chyndaa .. "”</small>" end if anthemObj.note and anthemObj.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { anthemObj.note } } display = display .. efnOut end if anthemObj.reference then display = display .. anthemObj.reference end if anthemObj.audio and anthemObj.audio ~= "" then display = display .. '<br/><div style="text-align:center; margin-top:0.3em;">[[Coadan:' .. anthemObj.audio .. '|center]]</div>' end return "'''" .. label .. ":&nbsp;'''" .. display end local nationalRow = formatAnthemRow("[[Arrane ashoonagh]]", anthems.national) if nationalRow then table.insert(rows, nationalRow) end local otherRow = formatAnthemRow("Anthym", anthems.other) if otherRow then table.insert(rows, otherRow) end local royalRow = formatAnthemRow("[[Arrane reeoil]]", anthems.royal) if royalRow then table.insert(rows, royalRow) end if #rows == 0 then return nil end return mw.text.listToText(rows, "<br/>", "<br/>") end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- local function getLanguagesFromWikidata() local entity = mw.wikibase.getEntityObject() if not entity then return {} end local statements = entity:getBestStatements("P37") if not statements or #statements == 0 then return {} end local languages = {} for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local id = mainsnak.datavalue.value.id local langEntity = mw.wikibase.getEntity(id) if langEntity then local label = langEntity:getLabel() if label and label ~= "" then local role = nil if statement.qualifiers and statement.qualifiers["P3831"] then for _, qualifier in ipairs(statement.qualifiers["P3831"]) do if qualifier.datavalue and qualifier.datavalue.type == "wikibase-entityid" then local roleEntity = mw.wikibase.getEntity( qualifier.datavalue.value.id ) if roleEntity then role = roleEntity:getLabel() break end end end end table.insert(languages, { text = label, role = role, reference = getWikidataReference(statement) }) end end end end return languages end local function classifyLanguages(languages) local result = { official = {}, regional = {}, minority = {} } for _, language in ipairs(languages) do local role = language.role or "" local lowerRole = mw.ustring.lower(role) if mw.ustring.find(lowerRole, "minority") then table.insert(result.minority, language) elseif mw.ustring.find(lowerRole, "regional") then table.insert(result.regional, language) else table.insert(result.official, language) end end return result end local function manxSort(a, b) local function normalize(text) text = mw.ustring.lower(text) text = mw.ustring.gsub(text, "çh", "ch") return text end return normalize(a) < normalize(b) end local function joinLanguageList(languages) if not languages or #languages == 0 then return nil end table.sort(languages, function(a, b) return manxSort(a.text, b.text) end) local parts = {} for _, language in ipairs(languages) do local text = language.text text = '[[' .. text .. '|' .. text .. ']]' if language.reference then text = text .. language.reference end table.insert(parts, text) end if #parts == 0 then return nil end return '<div class="hlist">' .. table.concat(parts, '&nbsp;· ') .. '</div>' end local function splitTopLevel(text, sep) local parts = {} local current = {} local depthCurly = 0 local depthSquare = 0 local len = mw.ustring.len(text) local i = 1 while i <= len do local two = mw.ustring.sub(text, i, i + 1) local one = mw.ustring.sub(text, i, i) if two == "{{" then depthCurly = depthCurly + 1 table.insert(current, two) i = i + 2 elseif two == "}}" and depthCurly > 0 then depthCurly = depthCurly - 1 table.insert(current, two) i = i + 2 elseif two == "[[" then depthSquare = depthSquare + 1 table.insert(current, two) i = i + 2 elseif two == "]]" and depthSquare > 0 then depthSquare = depthSquare - 1 table.insert(current, two) i = i + 2 elseif one == sep and depthCurly == 0 and depthSquare == 0 then table.insert(parts, table.concat(current)) current = {} i = i + 1 else table.insert(current, one) i = i + 1 end end table.insert(parts, table.concat(current)) return parts end local function findTemplateCall(text, namePattern) local searchPattern = "{{%s*" .. namePattern .. "%s*|" local matchStart, matchEnd = mw.ustring.find(text, searchPattern) if not matchStart then return nil end local contentStart = matchEnd + 1 local depth = 1 local i = contentStart local len = mw.ustring.len(text) while i <= len do local two = mw.ustring.sub(text, i, i + 1) if two == "{{" then depth = depth + 1 i = i + 2 elseif two == "}}" then depth = depth - 1 i = i + 2 if depth == 0 then local contentEnd = i - 3 return mw.ustring.sub(text, contentStart, contentEnd) end else i = i + 1 end end return nil end local function extractReferences(text) if not text then return text, nil end local refs = {} local cleaned = mw.ustring.gsub(text, "<ref[^>]*>.-</ref>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.ustring.gsub(cleaned, "<ref[^>]*/>", function(match) table.insert(refs, match) return "" end ) cleaned = mw.text.trim(cleaned) if #refs == 0 then return cleaned, nil end return cleaned, table.concat(refs) end local function countHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local segments = splitTopLevel(inner, "|") local count = 0 for _, segment in ipairs(segments) do local trimmedSegment = mw.text.trim(segment) if trimmedSegment ~= "" and not mw.ustring.find(trimmedSegment, "^[%w_%- ]+=") then count = count + 1 end end return count end local function countListItems(text) if not text or text == "" then return 0 end local hlistCount = countHlistItems(text) if hlistCount then return hlistCount end local count = 0 for _ in mw.text.gsplit(text, ",", true) do count = count + 1 end return count end local function extractHlistItems(text) local inner = findTemplateCall(text, "[Hh][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Ff][Ll][Aa][Tt][Ll][Ii][Ss][Tt]") or findTemplateCall(text, "[Uu][Bb][Ll]") or findTemplateCall(text, "[Uu][Nn][Bb][Uu][Ll][Ll][Ee][Tt][Ee][Dd]%s+[Ll][Ii][Ss][Tt]") if not inner then return nil end local items = {} local segments = splitTopLevel(inner, "|") for _, segment in ipairs(segments) do local trimmed = mw.text.trim(segment) if trimmed ~= "" and not mw.ustring.find(trimmed, "^[%w_%- ]+=") then local linkText = mw.ustring.match(trimmed, "%[%[.-|(.+)%]%]") or mw.ustring.match(trimmed, "%[%[(.+)%]%]") or trimmed table.insert(items, mw.text.trim(linkText)) end end return items end local function buildLanguageValue(raw, manualReference, manualNote, frame) if not raw or mw.ustring.lower(mw.text.trim(raw)) == "none" then return nil, 0 end local cleaned, inlineRefs = extractReferences(raw) local count = countListItems(cleaned) local languageNames = extractHlistItems(cleaned) if not languageNames then languageNames = {} for part in mw.text.gsplit(cleaned, ",", true) do local trimmed = mw.text.trim(part) if trimmed ~= "" then table.insert(languageNames, trimmed) end end end table.sort(languageNames, manxSort) local parts = {} for _, name in ipairs(languageNames) do table.insert(parts, '[[' .. name .. '|' .. name .. ']]') end local display = '<div class="hlist">' .. table.concat(parts, '&nbsp;· ') .. '</div>' if manualNote and manualNote ~= "" and frame then local efnOut = frame:expandTemplate{ title = "efn", args = { manualNote } } display = display .. efnOut end if inlineRefs then display = display .. inlineRefs end if manualReference then display = display .. "<ref>" .. manualReference .. "</ref>" end return display, count end local function getLanguageData(args, frame) local officialRaw = getManual(args, { "çhengaghyn_oikoil", "çhengey_oikoil" }) local officialReference = getManual(args, { "imraa_çhengaghyn_oikoil", "imraa_çhengey_oikoil" }) local regionalRaw = getManual(args, { "çhengaghyn_ardjynagh", "çhengey_ardjynagh" }) local regionalReference = getManual(args, { "imraa_çhengaghyn_ardjynagh", "imraa_çhengey_ardjynagh" }) local minorityRaw = getManual(args, { "mynçhengaghyn", "mynçhengey" }) local minorityReference = getManual(args, { "imraa_mynçhengaghyn", "imraa_mynçhengey" }) local otherRaw = getManual(args, { "çhengaghyn", "çhengey" }) local otherReference = getManual(args, { "imraa_çhengaghyn", "imraa_çhengey" }) local otherLabel = getManual(args, { "sorçh_çhengaghyn" }) local officialNote = getManual(args, {"noteyn_çhengaghyn_oikoil", "noteyn_çhengey_oikoil"}) local regionalNote = getManual(args, {"noteyn_çhengaghyn_ardjynagh", "noteyn_çhengey_ardjynagh"}) local minorityNote = getManual(args, {"noteyn_mynçhengaghyn", "noteyn_mynçhengey"}) local otherNote = getManual(args, {"noteyn_çhengaghyn", "noteyn_çhengey"}) local result = { otherLabel = otherLabel } result.official, result.officialCount = buildLanguageValue(officialRaw, officialReference, officialNote, frame) result.regional, result.regionalCount = buildLanguageValue(regionalRaw, regionalReference, regionalNote, frame) result.minority, result.minorityCount = buildLanguageValue(minorityRaw, minorityReference, minorityNote, frame) result.other, result.otherCount = buildLanguageValue(otherRaw, otherReference, otherNote, frame) if not result.official and not result.regional and not result.minority then local classified = classifyLanguages(getLanguagesFromWikidata()) result.official = joinLanguageList(classified.official) result.officialCount = #classified.official result.regional = joinLanguageList(classified.regional) result.regionalCount = #classified.regional result.minority = joinLanguageList(classified.minority) result.minorityCount = #classified.minority end return result end local function buildLanguageRows(args, frame) local data = getLanguageData(args, frame) local rows = {} if data.official then local officialLabel = data.officialCount > 1 and "[[Çhengey oikoil|Çhengaghyn oikoil]]" or "[[Çhengey oikoil]]" local officialRow = '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. officialLabel .. '</th><td style="vertical-align:top;">' .. data.official .. '</td></tr>' if data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn&nbsp;ardjynagh er&nbsp;enney" or "Çhengey&nbsp;ardjynagh er&nbsp;enney" officialRow = officialRow .. '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:normal;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th>' .. '<td style="vertical-align:top;">' .. data.regional .. '</td></tr>' end table.insert(rows, officialRow) elseif data.regional then local regionalLabel = data.regionalCount > 1 and "Çhengaghyn ardjynagh er enney" or "Çhengey ardjynagh er enney" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[Çhengey ardjynagh|' .. regionalLabel .. ']]</th><td style="vertical-align:top;">' .. data.regional .. '</td></tr>' ) end if data.minority then local minorityLabel = data.minorityCount > 1 and "[[Mynçhengey|Mynçhengaghyn]]" or "[[Mynçhengey]]" table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. minorityLabel .. '</th><td style="vertical-align:top;">' .. data.minority .. '</td></tr>' ) end if data.other then local otherLabel = data.otherLabel or (data.otherCount > 1 and "Çhengaghyn" or "Çhengey") table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. otherLabel .. '</th><td style="vertical-align:top;">' .. data.other .. '</td></tr>' ) end if #rows == 0 then return nil end return table.concat(rows) end function p.languages(frame) local args = getArgs(frame) return buildLanguageRows(args, frame) end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local function getLocatorMapData(args) local map = getManual(args, { "jalloo_caslys-çheerey", "jalloo_caslys" }) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end return { image = map, width = getManual(args, { "lheead_caslys-çheerey", "lheead_caslys" }) or "250px", caption = getManual(args, { "fo-heidyl_caslys-çheerey", "fo-heidyl_caslys" }) } end function p.map(frame) local args = getArgs(frame) local locatorMap = getLocatorMapData(args) if not locatorMap then return "" end local map = '[[Coadan:' .. locatorMap.image .. '|' .. locatorMap.width .. '|center]]' if locatorMap.caption then map = map .. '<div style="position:relative; top:0.3em;">' .. '<small>' .. locatorMap.caption .. '</small></div>' end return '<div style="text-align:center; padding:0.6em 0em;">' .. map .. '</div>' end -------------------------------------------------- -- CAPITAL / LARGEST CITY -------------------------------------------------- local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value) value = mw.ustring.gsub(value, "^%[%[", "") value = mw.ustring.gsub(value, "%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function getCityEntityFromTitle(value) local title = normaliseCityName(value) if title == "" then return nil end local entityId = mw.wikibase.getEntityIdForTitle(title) if not entityId then return nil end return mw.wikibase.getEntity(entityId) end local function getCapitalData(args) local capital = getManual(args, { "preeu-valley" }) if capital and mw.ustring.lower(capital) == "none" then return nil end local note = getManual(args, {"noteyn_preeu-valley"}) if capital then return { text = capital, entity = getCityEntityFromTitle(capital), reference = nil, note = note } end local entity, statement = getWikidataItem("P36") if entity then local sitelink = entity:getSitelink("gvwiki") return { text = sitelink or entity:getLabel(), entity = entity, reference = getWikidataReference(statement), note = nil } end return nil end local function getAdministrativeCentreData(args) local centre = getManual(args, { "ynnyd_reiragh" }) if centre and mw.ustring.lower(centre) == "none" then return nil end local note = getManual(args, {"noteyn_ynnyd_reiragh"}) if centre then return { text = centre, entity = getCityEntityFromTitle(centre), reference = nil, note = note } end return nil end local function getLargestCityData(args) local city = getManual(args, { "balley_smoo" }) if city and mw.ustring.lower(city) == "none" then return nil end local note = getManual(args, {"noteyn_balley_smoo"}) if city then return { text = city, entity = getCityEntityFromTitle(city), reference = nil, note = note } end local country = mw.wikibase.getEntityObject() if not country then return nil end local statements = country:getBestStatements("P13574") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "wikibase-entityid" then local targetId = mainsnak.datavalue.value.id local target = mw.wikibase.getEntity(targetId) if target and not isDisambiguationPage(target) then local sitelink = target:getSitelink("gvwiki") return { text = sitelink or target:getLabel(), entity = target, reference = getWikidataReference(statement), note = nil } end end end return nil end local function getCityLabels(args) return { capital = getManual(args, { "sorçh_preeu-valley" }), administrative = getManual(args, { "sorçh_ynnyd_reiragh" }) } end local function getCityData(args) return { capital = getCapitalData(args), administrative = getAdministrativeCentreData(args), largest = getLargestCityData(args), labels = getCityLabels(args) } end local function capitalIsLargest(capital, largest) if not capital or not largest then return false end -- Check if the raw text input for the largest city is explicitly set to "preeu-valley" if largest.text and mw.ustring.lower(mw.text.trim(largest.text)) == "preeu-valley" then return true end if capital.entity and largest.entity then if capital.entity.id == largest.entity.id then return true end end local capitalText = normaliseCityName(capital.text) local largestText = normaliseCityName(largest.text) if capitalText == "" or largestText == "" then return false end return mw.ustring.lower(capitalText) == mw.ustring.lower(largestText) end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then -- Keep it clean and unlinked here; p.main will safely apply formatting return labels.capital or "Preeu-valley" end if cityData.administrative then return labels.administrative or "Ynnyd reiragh" end if largest then return "Balley smoo" end return nil end local function makeCityLink(city) if not city or not city.text then return "" end local title = nil if city.entity then title = city.entity:getSitelink("gvwiki") end if not title or title == "" then title = normaliseCityName(city.text) end if not title or title == "" then return "" end return "[[" .. title .. "|" .. title .. "]]" end local function makeCoordinates(entity) if not entity then return nil end local statements = entity:getBestStatements("P625") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "globecoordinate" then local value = mainsnak.datavalue.value if value and value.latitude and value.longitude then return mw.getCurrentFrame():expandTemplate{ title = "coord", args = { value.latitude, value.longitude, display = "inline", format = "dms" } } end end end return nil end -------------------------------------------------- -- CITY LABEL -------------------------------------------------- function p.city_label(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local largest = cityData.largest local labels = cityData.labels if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. '<br/><small style="font-weight:normal;">' .. '(as y balley smoo)' .. '</small>' end return "[[Preeu-valley|" .. label .. "]]" end if cityData.administrative then return "[[Ynnyd reiragh|" .. (labels.administrative or "Ynnyd reiragh") .. "]]" end if largest then return "Balley smoo" end return nil end -------------------------------------------------- -- CITY DATA -------------------------------------------------- function p.city_data(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local function renderCityCell(cityObj) local text = makeCityLink(cityObj) if cityObj.note and cityObj.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { cityObj.note } } text = text .. efnOut end if cityObj.reference then text = text .. cityObj.reference end if cityObj.entity then local coordinates = makeCoordinates(cityObj.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end return text end if capital then return renderCityCell(capital) elseif administrative then return renderCityCell(administrative) elseif largest then return renderCityCell(largest) end return nil end function p.cities(frame) local args = getArgs(frame) local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels local rows = {} local function formatLegacyRow(label, cityObj) local text = makeCityLink(cityObj) if cityObj.note and cityObj.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { cityObj.note } } text = text .. efnOut end if cityObj.reference then text = text .. cityObj.reference end if cityObj.entity then local coordinates = makeCoordinates(cityObj.entity) if coordinates then text = text .. "<br/><small>" .. coordinates .. "</small>" end end return "'''" .. label .. "''': " .. text end if capital then local label = labels.capital or "Preeu-valley" if capitalIsLargest(capital, largest) then label = label .. "<br/><small>(as y balley smoo)</small>" end table.insert(rows, formatLegacyRow(label, capital)) end if administrative then local label = labels.administrative or "Ynnyd reiragh" table.insert(rows, formatLegacyRow(label, administrative)) end if largest then table.insert(rows, formatLegacyRow("Balley smoo", largest)) end if #rows == 0 then return nil end return table.concat(rows, "<br/>") end -------------------------------------------------- -- TITLE OUTPUT -------------------------------------------------- function p.title(frame) local args = getArgs(frame) local top = getManual(args, { "ennym" }) if not top then local pageTitle = mw.title.getCurrentTitle() if pageTitle then top = pageTitle.text end end local bottom = getManual(args, { "ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh" }) if not bottom then local officialNames = getOfficialNames() local entry = nil for _, candidate in ipairs(officialNames) do if candidate.language == "en" then entry = candidate break end end if not entry then entry = officialNames end if entry then bottom = entry.text bottom = mw.ustring.gsub( bottom, "^[Tt][Hh][Ee]%s+", "" ) local langName = getLanguageName(entry.language) if langName then bottom = bottom .. ' <small>(' .. '[[' .. langName .. '|' .. langName .. ']]' .. ')</small>' end if entry.reference then bottom = bottom .. entry.reference end end end local parts = {} if top then table.insert(parts, '<span style="font-weight:bold;">' .. top .. '</span>' ) end if bottom then table.insert(parts, '<div style="padding-top:0.25em; font-weight:normal;">' .. bottom .. '</div>' ) end if #parts == 0 then return nil end return table.concat(parts) end -------------------------------------------------- -- IMAGE OUTPUT -------------------------------------------------- function p.images(frame) local args = getArgs(frame) return buildFlagArmsBlock(args) end -------------------------------------------------- -- CAPTION OUTPUT -------------------------------------------------- function p.captions(frame) return nil end -------------------------------------------------- -- MAIN -------------------------------------------------- function p.main(frame) local args = getArgs(frame) local rows = {} local dividerStyle = "border-top:1px solid #a2a9b1; padding-top:0.4em;" -------------------------------------------------- -- HEADER -------------------------------------------------- do local titleContent = p.title(frame) if titleContent then table.insert(rows, '<tr class="adr"><th colspan="2" ' .. 'class="fn org country-name" ' .. 'style="line-height:1.2em; padding:0.25em 0.33em 0.33em; ' .. 'font-size:1.25em; text-align:center; font-weight:normal;">' .. titleContent .. '</th></tr>' ) end end -------------------------------------------------- -- FLAG / ARMS -------------------------------------------------- do local flagArms = buildFlagArmsBlock(args) if flagArms then table.insert(rows, '<tr><td colspan="2" ' .. 'align="center" style="' .. dividerStyle .. ' padding-bottom:0.5em;">' .. flagArms .. '</td></tr>' ) end end -------------------------------------------------- -- MOTTO / ANTHEM -------------------------------------------------- do local symbols = p.symbols(frame) if symbols then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. ' padding-bottom:0.4em; line-height:1.2em; text-align:center;">' .. symbols .. '</td></tr>' ) end end -------------------------------------------------- -- LOCATOR MAP -------------------------------------------------- do local map = p.map(frame) if map and map ~= "" then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '">' .. map .. '</td></tr>' ) end end -------------------------------------------------- -- CAPITAL / ADMINISTRATIVE CENTRE / LARGEST CITY -------------------------------------------------- -------------------------------------------------- -- CAPITAL / ADMINISTRATIVE CENTRE / LARGEST CITY -------------------------------------------------- do local cityData = getCityData(args) local capital = cityData.capital local administrative = cityData.administrative local largest = cityData.largest local labels = cityData.labels if capital or administrative or largest then table.insert(rows, '<tr><td colspan="2" style="' .. dividerStyle .. '"></td></tr>' ) end -- Capital Row Execution if capital then local labelText = labels.capital or "Preeu-valley" -- SAFELY construct the combined link label without breaking MediaWiki parser tracking local displayLabel = '[[' .. labelText .. ']]' if capitalIsLargest(capital, largest) then displayLabel = '[[' .. labelText .. ']]<br/><small style="font-weight:normal;">(as y balley smoo)</small>' end local text = makeCityLink(capital) if capital.note and capital.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { capital.note } } text = text .. efnOut end if capital.entity then local coordinates = makeCoordinates(capital.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if capital.reference then text = text .. capital.reference end table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. displayLabel .. '</th><td style="vertical-align:top;">' .. text .. '</td></tr>' ) end -- Administrative Centre Row Execution if administrative then local text = makeCityLink(administrative) local labelText = labels.administrative or "Ynnyd reiragh" if administrative.note and administrative.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { administrative.note } } text = text .. efnOut end if administrative.entity then local coordinates = makeCoordinates(administrative.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. '[[' .. labelText .. ']]' .. '</th><td style="vertical-align:top;">' .. text .. '</td></tr>' ) end -- Largest City Row Execution (FIXED: Bypassed completely if already handled by the capital row) if largest and not capitalIsLargest(capital, largest) then local text = makeCityLink(largest) if largest.note and largest.note ~= "" then local efnOut = frame:expandTemplate{ title = "efn", args = { largest.note } } text = text .. efnOut end if largest.entity then local coordinates = makeCoordinates(largest.entity) if coordinates then text = text .. '<br/><small>' .. coordinates .. '</small>' end end if largest.reference then text = text .. largest.reference end table.insert(rows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left;">' .. 'Balley smoo' .. '</th><td style="vertical-align:top;">' .. text .. '</td></tr>' ) end end -------------------------------------------------- -- LANGUAGES -------------------------------------------------- do local languageRows = buildLanguageRows(args, frame) if languageRows then table.insert(rows, languageRows) end end if #rows == 0 then return nil end return '<table class="infobox geography vcard" ' .. 'style="float:right; clear:right; margin:0.5em 0 1em 1em; ' .. 'width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p 617piq09z1685x09qp35ohoqw0py48s 392904 392903 2026-09-07T02:47:39Z MacTire02 219 Ta fo-voddylyn ny share. Goaill toshiaght rish adsyn 392904 Scribunto text/plain local p = {} -- Helper to safely grab template arguments local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end function p.main(frame) local args = getArgs(frame) local rows = {} -- The universal border rule separating your modules local dividerLine = '<tr><td colspan="2" style="border-top:1px solid #a2a9b1; padding:0; height:0px;"></td></tr>' -- Centralized module injection manager local function appendModule(content) if content and content ~= "" then if #rows > 0 then table.insert(rows, dividerLine) end table.insert(rows, content) end end -------------------------------------------------- -- MODULE 1: HEADER & NAMES (Kept local for speed) -------------------------------------------------- local title = args["ennym"] or mw.title.getCurrentTitle().text local subTitle = args["ennym_foddey_cadjincliaghtagh"] or args["ennym_dooghyssagh"] local headerHtml = '<tr class="adr"><th colspan="2" class="fn org country-name" style="line-height:1.2em; padding:0.25em 0.33em 0.33em; font-size:1.25em; text-align:center; font-weight:normal;"><span style="font-weight:bold;">' .. title .. '</span>' if subTitle and subTitle ~= "" then headerHtml = headerHtml .. '<div style="padding-top:0.25em; font-weight:normal;">' .. subTitle .. '</div>' end headerHtml = headerHtml .. '</th></tr>' table.insert(rows, headerHtml) -------------------------------------------------- -- MODULE 2: FLAGS & ARMS -------------------------------------------------- local successFlags, flagsMod = pcall(require, "Module:Kishtey fys çheer/brattaghyn") if successFlags and flagsMod and flagsMod.main then appendModule(flagsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 3: SYMBOLS (MOTTO & ANTHEMS) -------------------------------------------------- local successSymbols, symbolsMod = pcall(require, "Module:Kishtey fys çheer/cowraghyn") if successSymbols and symbolsMod and symbolsMod.main then appendModule(symbolsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 4: LOCATOR MAPS -------------------------------------------------- local successMaps, mapsMod = pcall(require, "Module:Kishtey fys çheer/caslyssyn") if successMaps and mapsMod and mapsMod.main then appendModule(mapsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 5: CITIES & CAPITALS -------------------------------------------------- local successCities, citiesMod = pcall(require, "Module:Kishtey fys çheer/balley") if successCities and citiesMod and citiesMod.main then appendModule(citiesMod.main(frame, args)) end -------------------------------------------------- -- MODULE 6: LANGUAGES -------------------------------------------------- local successLanguages, languagesMod = pcall(require, "Module:Kishtey fys çheer/çhengaghyn") if successLanguages and languagesMod and languagesMod.main then appendModule(languagesMod.main(frame, args)) end if #rows <= 1 then return nil end return '<table class="infobox geography vcard" style="float:right; clear:right; margin:0.5em 0 1em 1em; width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p 7kuiiq2hkrm8oecpxkwv9eph0quj1j0 392906 392904 2026-09-07T02:49:48Z MacTire02 219 brattaghyn > bratteeyn 392906 Scribunto text/plain local p = {} -- Helper to safely grab template arguments local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end function p.main(frame) local args = getArgs(frame) local rows = {} -- The universal border rule separating your modules local dividerLine = '<tr><td colspan="2" style="border-top:1px solid #a2a9b1; padding:0; height:0px;"></td></tr>' -- Centralized module injection manager local function appendModule(content) if content and content ~= "" then if #rows > 0 then table.insert(rows, dividerLine) end table.insert(rows, content) end end -------------------------------------------------- -- MODULE 1: HEADER & NAMES (Kept local for speed) -------------------------------------------------- local title = args["ennym"] or mw.title.getCurrentTitle().text local subTitle = args["ennym_foddey_cadjincliaghtagh"] or args["ennym_dooghyssagh"] local headerHtml = '<tr class="adr"><th colspan="2" class="fn org country-name" style="line-height:1.2em; padding:0.25em 0.33em 0.33em; font-size:1.25em; text-align:center; font-weight:normal;"><span style="font-weight:bold;">' .. title .. '</span>' if subTitle and subTitle ~= "" then headerHtml = headerHtml .. '<div style="padding-top:0.25em; font-weight:normal;">' .. subTitle .. '</div>' end headerHtml = headerHtml .. '</th></tr>' table.insert(rows, headerHtml) -------------------------------------------------- -- MODULE 2: FLAGS & ARMS -------------------------------------------------- local successFlags, flagsMod = pcall(require, "Module:Kishtey fys çheer/bratteeyn") if successFlags and flagsMod and flagsMod.main then appendModule(flagsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 3: SYMBOLS (MOTTO & ANTHEMS) -------------------------------------------------- local successSymbols, symbolsMod = pcall(require, "Module:Kishtey fys çheer/cowraghyn") if successSymbols and symbolsMod and symbolsMod.main then appendModule(symbolsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 4: LOCATOR MAPS -------------------------------------------------- local successMaps, mapsMod = pcall(require, "Module:Kishtey fys çheer/caslyssyn") if successMaps and mapsMod and mapsMod.main then appendModule(mapsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 5: CITIES & CAPITALS -------------------------------------------------- local successCities, citiesMod = pcall(require, "Module:Kishtey fys çheer/balley") if successCities and citiesMod and citiesMod.main then appendModule(citiesMod.main(frame, args)) end -------------------------------------------------- -- MODULE 6: LANGUAGES -------------------------------------------------- local successLanguages, languagesMod = pcall(require, "Module:Kishtey fys çheer/çhengaghyn") if successLanguages and languagesMod and languagesMod.main then appendModule(languagesMod.main(frame, args)) end if #rows <= 1 then return nil end return '<table class="infobox geography vcard" style="float:right; clear:right; margin:0.5em 0 1em 1em; width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p hmiyeht3q76qjfu20v6wtbuf2hsnibm 392910 392906 2026-09-07T02:54:10Z MacTire02 219 ++ 392910 Scribunto text/plain local p = {} -- Helper to safely grab template arguments local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end function p.main(frame) local args = getArgs(frame) local rows = {} -- The universal border rule separating your modules local dividerLine = '<tr><td colspan="2" style="border-top:1px solid #a2a9b1; padding:0; height:0px;"></td></tr>' -- Centralized module injection manager local function appendModule(content) if content and content ~= "" then if #rows > 0 then table.insert(rows, dividerLine) end table.insert(rows, content) end end -------------------------------------------------- -- MODULE 1: HEADER & NAMES (Kept local for speed) -------------------------------------------------- local title = args["ennym"] or mw.title.getCurrentTitle().text local subTitle = args["ennym_foddey_cadjincliaghtagh"] or args["ennym_dooghyssagh"] local headerHtml = '<tr class="adr"><th colspan="2" class="fn org country-name" style="line-height:1.2em; padding:0.25em 0.33em 0.33em; font-size:1.25em; text-align:center; font-weight:normal;"><span style="font-weight:bold;">' .. title .. '</span>' if subTitle and subTitle ~= "" then headerHtml = headerHtml .. '<div style="padding-top:0.25em; font-weight:normal;">' .. subTitle .. '</div>' end headerHtml = headerHtml .. '</th></tr>' table.insert(rows, headerHtml) -------------------------------------------------- -- MODULE 2: FLAGS & ARMS -------------------------------------------------- local successFlags, flagsMod = pcall(require, "Module:Kishtey fys çheer/bratteeyn") if successFlags and flagsMod and flagsMod.main then appendModule(flagsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 3: SYMBOLS (MOTTO & ANTHEMS) -------------------------------------------------- local successSymbols, symbolsMod = pcall(require, "Module:Kishtey fys çheer/cowraghyn") if successSymbols and symbolsMod and symbolsMod.main then appendModule(symbolsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 4: LOCATOR MAPS -------------------------------------------------- local successMaps, mapsMod = pcall(require, "Module:Kishtey fys çheer/caslyssyn-çheerey") if successMaps and mapsMod and mapsMod.main then appendModule(mapsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 5: CITIES & CAPITALS -------------------------------------------------- local successCities, citiesMod = pcall(require, "Module:Kishtey fys çheer/balley") if successCities and citiesMod and citiesMod.main then appendModule(citiesMod.main(frame, args)) end -------------------------------------------------- -- MODULE 6: LANGUAGES -------------------------------------------------- local successLanguages, languagesMod = pcall(require, "Module:Kishtey fys çheer/çhengaghyn") if successLanguages and languagesMod and languagesMod.main then appendModule(languagesMod.main(frame, args)) end if #rows <= 1 then return nil end return '<table class="infobox geography vcard" style="float:right; clear:right; margin:0.5em 0 1em 1em; width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p qdbddvlzpxhu97psndxthl25khrpnia 392915 392910 2026-09-07T03:04:36Z MacTire02 219 prowal 392915 Scribunto text/plain local p = {} -- Helper to safely grab template arguments local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end function p.main(frame) local args = getArgs(frame) local rows = {} -- The universal border rule separating your modules local dividerLine = '<tr><td colspan="2" style="border-top:1px solid #a2a9b1; padding:0; height:0px;"></td></tr>' -- Centralized module injection manager local function appendModule(content) if content and content ~= "" then if #rows > 0 then table.insert(rows, dividerLine) end table.insert(rows, content) end end -------------------------------------------------- -- MODULE 1: HEADER & NAMES (Kept local for speed) -------------------------------------------------- local title = args["ennym"] or mw.title.getCurrentTitle().text local subTitle = args["ennym_foddey_cadjincliaghtagh"] or args["ennym_dooghyssagh"] local headerHtml = '<tr class="adr"><th colspan="2" class="fn org country-name" style="line-height:1.2em; padding:0.25em 0.33em 0.33em; font-size:1.25em; text-align:center; font-weight:normal;"><span style="font-weight:bold;">' .. title .. '</span>' if subTitle and subTitle ~= "" then headerHtml = headerHtml .. '<div style="padding-top:0.25em; font-weight:normal;">' .. subTitle .. '</div>' end headerHtml = headerHtml .. '</th></tr>' table.insert(rows, headerHtml) -------------------------------------------------- -- MODULE 2: FLAGS & ARMS -------------------------------------------------- local successFlags, flagsMod = pcall(require, "Module:Kishtey fys çheer/bratteeyn") if successFlags and flagsMod and flagsMod.main then appendModule(flagsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 3: SYMBOLS (MOTTO & ANTHEMS) -------------------------------------------------- local successSymbols, symbolsMod = pcall(require, "Module:Kishtey fys çheer/cowraghyn") if successSymbols and symbolsMod and symbolsMod.main then appendModule(symbolsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 4: LOCATOR MAPS -------------------------------------------------- local successMaps, mapsMod = pcall(require, "Module:Kishtey fys çheer/caslyssyn-çheerey") if successMaps and mapsMod and mapsMod.main then appendModule(mapsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 5: CITIES & CAPITALS -------------------------------------------------- -- FIXED: Swapped require path to use explicit page references or standard string loads local successCities, citiesMod = pcall(function() return require("Module:Kishtey fys çheer/balley") end) if not successCities or not citiesMod then -- Fallback helper block to ensure it hooks the page title accurately successCities, citiesMod = pcall(require, "Module.Kishtey fys çheer.balley") end if successCities and citiesMod and citiesMod.main then appendModule(citiesMod.main(frame, args)) end -------------------------------------------------- -- MODULE 6: LANGUAGES -------------------------------------------------- local successLanguages, languagesMod = pcall(function() return require("Module:Kishtey fys çheer/çhengaghyn") end) if not successLanguages or not languagesMod then successLanguages, languagesMod = pcall(require, "Module.Kishtey fys çheer.çhengaghyn") end if successLanguages and languagesMod and languagesMod.main then appendModule(languagesMod.main(frame, args)) end if #rows <= 1 then return nil end return '<table class="infobox geography vcard" style="float:right; clear:right; margin:0.5em 0 1em 1em; width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p dt8m4xve9235zicj10hhjm4823bsskx 392916 392915 2026-09-07T03:07:05Z MacTire02 219 prowal 392916 Scribunto text/plain local p = {} -- Helper to safely grab template arguments local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end function p.main(frame) local args = getArgs(frame) local rows = {} -- The universal border rule separating your modules local dividerLine = '<tr><td colspan="2" style="border-top:1px solid #a2a9b1; padding:0; height:0px;"></td></tr>' -- Centralized module injection manager local function appendModule(content) if content and content ~= "" then if #rows > 0 then table.insert(rows, dividerLine) end table.insert(rows, content) end end -------------------------------------------------- -- MODULE 1: HEADER & NAMES (Kept local for speed) -------------------------------------------------- local title = args["ennym"] or mw.title.getCurrentTitle().text local subTitle = args["ennym_foddey_cadjincliaghtagh"] or args["ennym_dooghyssagh"] local headerHtml = '<tr class="adr"><th colspan="2" class="fn org country-name" style="line-height:1.2em; padding:0.25em 0.33em 0.33em; font-size:1.25em; text-align:center; font-weight:normal;"><span style="font-weight:bold;">' .. title .. '</span>' if subTitle and subTitle ~= "" then headerHtml = headerHtml .. '<div style="padding-top:0.25em; font-weight:normal;">' .. subTitle .. '</div>' end headerHtml = headerHtml .. '</th></tr>' table.insert(rows, headerHtml) -------------------------------------------------- -- MODULE 2: FLAGS & ARMS -------------------------------------------------- -- FIXED: Changed path syntax from slashes to colons for standard Scribunto subpage loading local successFlags, flagsMod = pcall(require, "Module:Kishtey fys çheer:bratteeyn") if successFlags and flagsMod and flagsMod.main then appendModule(flagsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 3: SYMBOLS (MOTTO & ANTHEMS) -------------------------------------------------- -- FIXED: Changed path syntax from slashes to colons local successSymbols, symbolsMod = pcall(require, "Module:Kishtey fys çheer:cowraghyn") if successSymbols and symbolsMod and symbolsMod.main then appendModule(symbolsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 4: LOCATOR MAPS -------------------------------------------------- -- FIXED: Changed path syntax from slashes to colons local successMaps, mapsMod = pcall(require, "Module:Kishtey fys çheer:caslyssyn-çheerey") if successMaps and mapsMod and mapsMod.main then appendModule(mapsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 5: CITIES & CAPITALS -------------------------------------------------- -- FIXED: Cleaned up the require wrapper path to utilize correct colon subpage layout rules local successCities, citiesMod = pcall(require, "Module:Kishtey fys çheer:balley") if successCities and citiesMod and citiesMod.main then appendModule(citiesMod.main(frame, args)) end -------------------------------------------------- -- MODULE 6: LANGUAGES -------------------------------------------------- -- FIXED: Cleaned up the require wrapper path to utilize correct colon subpage layout rules local successLanguages, languagesMod = pcall(require, "Module:Kishtey fys çheer:çhengaghyn") if successLanguages and languagesMod and languagesMod.main then appendModule(languagesMod.main(frame, args)) end if #rows <= 1 then return nil end return '<table class="infobox geography vcard" style="float:right; clear:right; margin:0.5em 0 1em 1em; width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p rcsp944hrvxor5yflrb18f20kppmm0d 392917 392916 2026-09-07T03:08:22Z MacTire02 219 ++ 392917 Scribunto text/plain local p = {} -- Helper to safely grab template arguments local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end function p.main(frame) local args = getArgs(frame) local rows = {} -- The universal border rule separating your modules local dividerLine = '<tr><td colspan="2" style="border-top:1px solid #a2a9b1; padding:0; height:0px;"></td></tr>' -- Centralized module injection manager local function appendModule(content) if content and content ~= "" then if #rows > 0 then table.insert(rows, dividerLine) end table.insert(rows, content) end end -------------------------------------------------- -- MODULE 1: HEADER & NAMES (Kept local for speed) -------------------------------------------------- local title = args["ennym"] or mw.title.getCurrentTitle().text local subTitle = args["ennym_foddey_cadjincliaghtagh"] or args["ennym_dooghyssagh"] local headerHtml = '<tr class="adr"><th colspan="2" class="fn org country-name" style="line-height:1.2em; padding:0.25em 0.33em 0.33em; font-size:1.25em; text-align:center; font-weight:normal;"><span style="font-weight:bold;">' .. title .. '</span>' if subTitle and subTitle ~= "" then headerHtml = headerHtml .. '<div style="padding-top:0.25em; font-weight:normal;">' .. subTitle .. '</div>' end headerHtml = headerHtml .. '</th></tr>' table.insert(rows, headerHtml) -------------------------------------------------- -- MODULE 2: FLAGS & ARMS -------------------------------------------------- -- FIXED: Uses period paths which Scribunto translates to subpage forward-slashes natively local successFlags, flagsMod = pcall(require, "Module:Kishtey fys çheer.bratteeyn") if successFlags and flagsMod and flagsMod.main then appendModule(flagsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 3: SYMBOLS (MOTTO & ANTHEMS) -------------------------------------------------- -- FIXED: Uses standard period path format local successSymbols, symbolsMod = pcall(require, "Module:Kishtey fys çheer.cowraghyn") if successSymbols and symbolsMod and symbolsMod.main then appendModule(symbolsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 4: LOCATOR MAPS -------------------------------------------------- -- FIXED: Uses standard period path format local successMaps, mapsMod = pcall(require, "Module:Kishtey fys çheer.caslyssyn-çheerey") if successMaps and mapsMod and mapsMod.main then appendModule(mapsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 5: CITIES & CAPITALS -------------------------------------------------- -- FIXED: Uses standard period path format local successCities, citiesMod = pcall(require, "Module:Kishtey fys çheer.balley") if successCities and citiesMod and citiesMod.main then appendModule(citiesMod.main(frame, args)) end -------------------------------------------------- -- MODULE 6: LANGUAGES -------------------------------------------------- -- FIXED: Uses standard period path format local successLanguages, languagesMod = pcall(require, "Module:Kishtey fys çheer.çhengaghyn") if successLanguages and languagesMod and languagesMod.main then appendModule(languagesMod.main(frame, args)) end if #rows <= 1 then return nil end return '<table class="infobox geography vcard" style="float:right; clear:right; margin:0.5em 0 1em 1em; width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p mn3vqpfntnkvbw44vpnea32bhahfw92 392918 392917 2026-09-07T03:10:12Z MacTire02 219 ++ 392918 Scribunto text/plain local p = {} -- Helper to safely grab template arguments local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end function p.main(frame) local args = getArgs(frame) local rows = {} -- The universal border rule separating your modules local dividerLine = '<tr><td colspan="2" style="border-top:1px solid #a2a9b1; padding:0; height:0px;"></td></tr>' -- Centralized module injection manager local function appendModule(content) if content and content ~= "" then if #rows > 0 then table.insert(rows, dividerLine) end table.insert(rows, content) end end -------------------------------------------------- -- MODULE 1: HEADER & NAMES (Kept local for speed) -------------------------------------------------- local title = args["ennym"] or mw.title.getCurrentTitle().text local subTitle = args["ennym_foddey_cadjincliaghtagh"] or args["ennym_dooghyssagh"] local headerHtml = '<tr class="adr"><th colspan="2" class="fn org country-name" style="line-height:1.2em; padding:0.25em 0.33em 0.33em; font-size:1.25em; text-align:center; font-weight:normal;"><span style="font-weight:bold;">' .. title .. '</span>' if subTitle and subTitle ~= "" then headerHtml = headerHtml .. '<div style="padding-top:0.25em; font-weight:normal;">' .. subTitle .. '</div>' end headerHtml = headerHtml .. '</th></tr>' table.insert(rows, headerHtml) -------------------------------------------------- -- MODULE 2: FLAGS & ARMS -------------------------------------------------- local successFlags, flagsMod = pcall(require, "Module:Kishtey fys çheer/bratteeyn") if successFlags and flagsMod and flagsMod.main then appendModule(flagsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 3: SYMBOLS (MOTTO & ANTHEMS) -------------------------------------------------- local successSymbols, symbolsMod = pcall(require, "Module:Kishtey fys çheer/cowraghyn") if successSymbols and symbolsMod and symbolsMod.main then appendModule(symbolsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 4: LOCATOR MAPS -------------------------------------------------- local successMaps, mapsMod = pcall(require, "Module:Kishtey fys çheer/caslyssyn") if successMaps and mapsMod and mapsMod.main then appendModule(mapsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 5: CITIES & CAPITALS -------------------------------------------------- local successCities, citiesMod = pcall(require, "Module:Kishtey fys çheer/balley") if successCities and citiesMod and citiesMod.main then appendModule(citiesMod.main(frame, args)) end -------------------------------------------------- -- MODULE 6: LANGUAGES -------------------------------------------------- local successLanguages, languagesMod = pcall(require, "Module:Kishtey fys çheer/çhengaghyn") if successLanguages and languagesMod and languagesMod.main then appendModule(languagesMod.main(frame, args)) end if #rows <= 1 then return nil end return '<table class="infobox geography vcard" style="float:right; clear:right; margin:0.5em 0 1em 1em; width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p ef5nvyr5s8mnfgeb5ok8nc1do3bnfhm 392919 392918 2026-09-07T03:13:12Z MacTire02 219 ++ 392919 Scribunto text/plain local p = {} -- Helper to safely grab template arguments local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end function p.main(frame) local args = getArgs(frame) local rows = {} -- The universal border rule separating your modules local dividerLine = '<tr><td colspan="2" style="border-top:1px solid #a2a9b1; padding:0; height:0px;"></td></tr>' -- Centralized module injection manager local function appendModule(content) if content and content ~= "" then if #rows > 0 then table.insert(rows, dividerLine) end table.insert(rows, content) end end -------------------------------------------------- -- MODULE 1: HEADER & NAMES (Kept local for speed) -------------------------------------------------- local title = args["ennym"] or mw.title.getCurrentTitle().text local subTitle = args["ennym_foddey_cadjincliaghtagh"] or args["ennym_dooghyssagh"] local headerHtml = '<tr class="adr"><th colspan="2" class="fn org country-name" style="line-height:1.2em; padding:0.25em 0.33em 0.33em; font-size:1.25em; text-align:center; font-weight:normal;"><span style="font-weight:bold;">' .. title .. '</span>' if subTitle and subTitle ~= "" then headerHtml = headerHtml .. '<div style="padding-top:0.25em; font-weight:normal;">' .. subTitle .. '</div>' end headerHtml = headerHtml .. '</th></tr>' table.insert(rows, headerHtml) -------------------------------------------------- -- MODULE 2: FLAGS & ARMS -------------------------------------------------- local successFlags, flagsMod = pcall(require, "Module:Kishtey fys çheer/bratteeyn") if successFlags and flagsMod and flagsMod.main then appendModule(flagsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 3: SYMBOLS (MOTTO & ANTHEMS) -------------------------------------------------- local successSymbols, symbolsMod = pcall(require, "Module:Kishtey fys çheer/cowraghyn") if successSymbols and symbolsMod and symbolsMod.main then appendModule(symbolsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 4: LOCATOR MAPS -------------------------------------------------- -- Checks both standard subpage slashes and alternative unified strings local successMaps, mapsMod = pcall(require, "Module:Kishtey fys çheer/caslyssyn-çheerey") if not successMaps or not mapsMod then successMaps, mapsMod = pcall(require, "Module:Kishtey fys çheer/caslyssyn") end if not successMaps or not mapsMod then successMaps, mapsMod = pcall(require, "Module:Kishtey fys çheer/caslyssyn_cheerey") end if successMaps and mapsMod and mapsMod.main then appendModule(mapsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 5: CITIES & CAPITALS -------------------------------------------------- local successCities, citiesMod = pcall(require, "Module:Kishtey fys çheer/balley") if successCities and citiesMod and citiesMod.main then appendModule(citiesMod.main(frame, args)) end -------------------------------------------------- -- MODULE 6: LANGUAGES -------------------------------------------------- local successLanguages, languagesMod = pcall(require, "Module:Kishtey fys çheer/çhengaghyn") if not successLanguages or not languagesMod then successLanguages, languagesMod = pcall(require, "Module:Kishtey fys çheer/chengaghyn") end if successLanguages and languagesMod and languagesMod.main then appendModule(languagesMod.main(frame, args)) end if #rows <= 1 then return nil end return '<table class="infobox geography vcard" style="float:right; clear:right; margin:0.5em 0 1em 1em; width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p 7029561woxrs9v7taumlk5650jvm50z 392920 392919 2026-09-07T03:16:02Z MacTire02 219 ++ 392920 Scribunto text/plain local p = {} -- Helper to safely grab template arguments local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end -- Safely get manual parameters from priority list local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end function p.main(frame) local args = getArgs(frame) local rows = {} -- The universal border rule separating your modules local dividerLine = '<tr><td colspan="2" style="border-top:1px solid #a2a9b1; padding:0; height:0px;"></td></tr>' -- Centralized module injection manager local function appendModule(content) if content and content ~= "" then if #rows > 0 then table.insert(rows, dividerLine) end table.insert(rows, content) end end -------------------------------------------------- -- MODULE 1: HEADER & OFFICIAL NAMES (RESTORED) -------------------------------------------------- local title = args["ennym"] or mw.title.getCurrentTitle().text local subTitle = getManual(args, {"ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh"}) -- Fallback check for automated sub-labels if manual ones are empty if not subTitle or subTitle == "" then local successLang, langData = pcall(mw.loadData, "Module:Lang/data") local entity = mw.wikibase.getEntityObject() if entity and successLang and langData then local statements = entity:getBestStatements("P1448") if statements and #statements > 0 then local value = statements[1].mainsnak.datavalue.value if value and value.text then local langCode = value.language or "" local langName = langData.lang_name_table.lang[langCode] or langCode subTitle = value.text .. ' <small>([[' .. langName .. '|' .. langName .. ']])</small>' end end end end local headerHtml = '<tr class="adr"><th colspan="2" class="fn org country-name" style="line-height:1.2em; padding:0.25em 0.33em 0.33em; font-size:1.25em; text-align:center; font-weight:normal;"><span style="font-weight:bold;">' .. title .. '</span>' if subTitle and subTitle ~= "" then headerHtml = headerHtml .. '<div style="padding-top:0.25em; font-weight:normal;">' .. subTitle .. '</div>' end headerHtml = headerHtml .. '</th></tr>' table.insert(rows, headerHtml) -------------------------------------------------- -- MODULE 2: FLAGS & ARMS -------------------------------------------------- -- FORCE DIRECT EVALUATION: Bypasses restrictive require directory conversion barriers local successFlags, flagsMod = pcall(function() return require("Module:Kishtey fys çheer/bratteeyn") end) if successFlags and flagsMod and flagsMod.main then appendModule(flagsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 3: SYMBOLS (MOTTO & ANTHEMS) -------------------------------------------------- local successSymbols, symbolsMod = pcall(function() return require("Module:Kishtey fys çheer/cowraghyn") end) if successSymbols and symbolsMod and symbolsMod.main then appendModule(symbolsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 4: LOCATOR MAPS -------------------------------------------------- local successMaps, mapsMod = pcall(function() return require("Module:Kishtey fys çheer/caslyssyn") end) if successMaps and mapsMod and mapsMod.main then appendModule(mapsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 5: CITIES & CAPITALS -------------------------------------------------- local successCities, citiesMod = pcall(function() return require("Module:Kishtey fys çheer/balley") end) if successCities and citiesMod and citiesMod.main then appendModule(citiesMod.main(frame, args)) end -------------------------------------------------- -- MODULE 6: LANGUAGES -------------------------------------------------- local successLanguages, languagesMod = pcall(function() return require("Module:Kishtey fys çheer/çhengaghyn") end) if successLanguages and languagesMod and languagesMod.main then appendModule(languagesMod.main(frame, args)) end if #rows <= 1 then return nil end return '<table class="infobox geography vcard" style="float:right; clear:right; margin:0.5em 0 1em 1em; width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p nh8gq6gj00rm13kawaa2mcae8z8d50y 392921 392920 2026-09-07T03:17:48Z MacTire02 219 ++ 392921 Scribunto text/plain local p = {} -- Helper to safely grab template arguments local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end -- Safely get manual parameters from priority list local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end function p.main(frame) local args = getArgs(frame) local rows = {} -- The universal border rule separating your modules local dividerLine = '<tr><td colspan="2" style="border-top:1px solid #a2a9b1; padding:0; height:0px;"></td></tr>' -- Centralized module injection manager local function appendModule(content) if content and content ~= "" then if #rows > 0 then table.insert(rows, dividerLine) end table.insert(rows, content) end end -------------------------------------------------- -- MODULE 1: HEADER & OFFICIAL NAMES (FIXED) -------------------------------------------------- local title = args["ennym"] or mw.title.getCurrentTitle().text local subTitle = getManual(args, {"ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh"}) -- FIXED: Completely isolated and conditionalized Wikidata lookup check if not subTitle or subTitle == "" then local entity = mw.wikibase.getEntityObject() if entity then local successLang, langData = pcall(mw.loadData, "Module:Lang/data") if successLang and langData and langData.lang_name_table and langData.lang_name_table.lang then local statements = entity:getBestStatements("P1448") if statements and #statements > 0 and statements[1].mainsnak and statements[1].mainsnak.datavalue then local value = statements[1].mainsnak.datavalue.value if value and value.text then local langCode = value.language or "" local langName = langData.lang_name_table.lang[langCode] or langCode subTitle = value.text .. ' <small>([[' .. langName .. '|' .. langName .. ']])</small>' end end end end end local headerHtml = '<tr class="adr"><th colspan="2" class="fn org country-name" style="line-height:1.2em; padding:0.25em 0.33em 0.33em; font-size:1.25em; text-align:center; font-weight:normal;"><span style="font-weight:bold;">' .. title .. '</span>' if subTitle and subTitle ~= "" then headerHtml = headerHtml .. '<div style="padding-top:0.25em; font-weight:normal;">' .. subTitle .. '</div>' end headerHtml = headerHtml .. '</th></tr>' table.insert(rows, headerHtml) -------------------------------------------------- -- MODULE 2: FLAGS & ARMS -------------------------------------------------- local successFlags, flagsMod = pcall(require, "Module:Kishtey fys çheer/brattaghyn") if successFlags and flagsMod and flagsMod.main then appendModule(flagsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 3: SYMBOLS (MOTTO & ANTHEMS) -------------------------------------------------- local successSymbols, symbolsMod = pcall(require, "Module:Kishtey fys çheer/cowraghyn") if successSymbols and symbolsMod and symbolsMod.main then appendModule(symbolsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 4: LOCATOR MAPS -------------------------------------------------- local successMaps, mapsMod = pcall(require, "Module:Kishtey fys çheer/caslyssyn") if successMaps and mapsMod and mapsMod.main then appendModule(mapsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 5: CITIES & CAPITALS -------------------------------------------------- local successCities, citiesMod = pcall(require, "Module:Kishtey fys çheer/balley") if successCities and citiesMod and citiesMod.main then appendModule(citiesMod.main(frame, args)) end -------------------------------------------------- -- MODULE 6: LANGUAGES -------------------------------------------------- local successLanguages, languagesMod = pcall(require, "Module:Kishtey fys çheer/çhengaghyn") if successLanguages and languagesMod and languagesMod.main then appendModule(languagesMod.main(frame, args)) end if #rows <= 1 then return nil end return '<table class="infobox geography vcard" style="float:right; clear:right; margin:0.5em 0 1em 1em; width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p 3ng5ns2r6j0774k8tbl17mlhqutok8k 392922 392921 2026-09-07T03:19:37Z MacTire02 219 ++ 392922 Scribunto text/plain local p = {} -- Helper to safely grab template arguments local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end -- Safely get manual parameters from priority list local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end function p.main(frame) local args = getArgs(frame) local rows = {} -- The universal border rule separating your modules local dividerLine = '<tr><td colspan="2" style="border-top:1px solid #a2a9b1; padding:0; height:0px;"></td></tr>' -- Centralized module injection manager local function appendModule(content) if content and content ~= "" then if #rows > 0 then table.insert(rows, dividerLine) end table.insert(rows, content) end end -------------------------------------------------- -- MODULE 1: HEADER & OFFICIAL NAMES (FIXED) -------------------------------------------------- local title = args["ennym"] or mw.title.getCurrentTitle().text local subTitle = getManual(args, {"ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh"}) -- FIXED: Completely isolated and conditionalized Wikidata lookup check if not subTitle or subTitle == "" then local entity = mw.wikibase.getEntityObject() if entity then local successLang, langData = pcall(mw.loadData, "Module:Lang/data") if successLang and langData and langData.lang_name_table and langData.lang_name_table.lang then local statements = entity:getBestStatements("P1448") if statements and #statements > 0 and statements[1].mainsnak and statements[1].mainsnak.datavalue then local value = statements[1].mainsnak.datavalue.value if value and value.text then local langCode = value.language or "" local langName = langData.lang_name_table.lang[langCode] or langCode subTitle = value.text .. ' <small>([[' .. langName .. '|' .. langName .. ']])</small>' end end end end end local headerHtml = '<tr class="adr"><th colspan="2" class="fn org country-name" style="line-height:1.2em; padding:0.25em 0.33em 0.33em; font-size:1.25em; text-align:center; font-weight:normal;"><span style="font-weight:bold;">' .. title .. '</span>' if subTitle and subTitle ~= "" then headerHtml = headerHtml .. '<div style="padding-top:0.25em; font-weight:normal;">' .. subTitle .. '</div>' end headerHtml = headerHtml .. '</th></tr>' table.insert(rows, headerHtml) -------------------------------------------------- -- MODULE 2: FLAGS & ARMS -------------------------------------------------- local successFlags, flagsMod = pcall(require, "Module:Kishtey fys çheer/bratteeyn") if successFlags and flagsMod and flagsMod.main then appendModule(flagsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 3: SYMBOLS (MOTTO & ANTHEMS) -------------------------------------------------- local successSymbols, symbolsMod = pcall(require, "Module:Kishtey fys çheer/cowraghyn") if successSymbols and symbolsMod and symbolsMod.main then appendModule(symbolsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 4: LOCATOR MAPS -------------------------------------------------- local successMaps, mapsMod = pcall(require, "Module:Kishtey fys çheer/caslyssyn") if successMaps and mapsMod and mapsMod.main then appendModule(mapsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 5: CITIES & CAPITALS -------------------------------------------------- local successCities, citiesMod = pcall(require, "Module:Kishtey fys çheer/balley") if successCities and citiesMod and citiesMod.main then appendModule(citiesMod.main(frame, args)) end -------------------------------------------------- -- MODULE 6: LANGUAGES -------------------------------------------------- local successLanguages, languagesMod = pcall(require, "Module:Kishtey fys çheer/çhengaghyn") if successLanguages and languagesMod and languagesMod.main then appendModule(languagesMod.main(frame, args)) end if #rows <= 1 then return nil end return '<table class="infobox geography vcard" style="float:right; clear:right; margin:0.5em 0 1em 1em; width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p bgya6l6bjfg4xtfqcmkdrzvf165i7cq 392923 392922 2026-09-07T03:19:58Z MacTire02 219 ++ 392923 Scribunto text/plain local p = {} -- Helper to safely grab template arguments local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end -- Safely get manual parameters from priority list local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end function p.main(frame) local args = getArgs(frame) local rows = {} -- The universal border rule separating your modules local dividerLine = '<tr><td colspan="2" style="border-top:1px solid #a2a9b1; padding:0; height:0px;"></td></tr>' -- Centralized module injection manager local function appendModule(content) if content and content ~= "" then if #rows > 0 then table.insert(rows, dividerLine) end table.insert(rows, content) end end -------------------------------------------------- -- MODULE 1: HEADER & OFFICIAL NAMES (FIXED) -------------------------------------------------- local title = args["ennym"] or mw.title.getCurrentTitle().text local subTitle = getManual(args, {"ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh"}) -- FIXED: Completely isolated and conditionalized Wikidata lookup check if not subTitle or subTitle == "" then local entity = mw.wikibase.getEntityObject() if entity then local successLang, langData = pcall(mw.loadData, "Module:Lang/data") if successLang and langData and langData.lang_name_table and langData.lang_name_table.lang then local statements = entity:getBestStatements("P1448") if statements and #statements > 0 and statements[1].mainsnak and statements[1].mainsnak.datavalue then local value = statements[1].mainsnak.datavalue.value if value and value.text then local langCode = value.language or "" local langName = langData.lang_name_table.lang[langCode] or langCode subTitle = value.text .. ' <small>([[' .. langName .. '|' .. langName .. ']])</small>' end end end end end local headerHtml = '<tr class="adr"><th colspan="2" class="fn org country-name" style="line-height:1.2em; padding:0.25em 0.33em 0.33em; font-size:1.25em; text-align:center; font-weight:normal;"><span style="font-weight:bold;">' .. title .. '</span>' if subTitle and subTitle ~= "" then headerHtml = headerHtml .. '<div style="padding-top:0.25em; font-weight:normal;">' .. subTitle .. '</div>' end headerHtml = headerHtml .. '</th></tr>' table.insert(rows, headerHtml) -------------------------------------------------- -- MODULE 2: FLAGS & ARMS -------------------------------------------------- local successFlags, flagsMod = pcall(require, "Module:Kishtey fys çheer/bratteeyn") if successFlags and flagsMod and flagsMod.main then appendModule(flagsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 3: SYMBOLS (MOTTO & ANTHEMS) -------------------------------------------------- local successSymbols, symbolsMod = pcall(require, "Module:Kishtey fys çheer/cowraghyn") if successSymbols and symbolsMod and symbolsMod.main then appendModule(symbolsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 4: LOCATOR MAPS -------------------------------------------------- local successMaps, mapsMod = pcall(require, "Module:Kishtey fys çheer/caslyssyn-çheerey") if successMaps and mapsMod and mapsMod.main then appendModule(mapsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 5: CITIES & CAPITALS -------------------------------------------------- local successCities, citiesMod = pcall(require, "Module:Kishtey fys çheer/balley") if successCities and citiesMod and citiesMod.main then appendModule(citiesMod.main(frame, args)) end -------------------------------------------------- -- MODULE 6: LANGUAGES -------------------------------------------------- local successLanguages, languagesMod = pcall(require, "Module:Kishtey fys çheer/çhengaghyn") if successLanguages and languagesMod and languagesMod.main then appendModule(languagesMod.main(frame, args)) end if #rows <= 1 then return nil end return '<table class="infobox geography vcard" style="float:right; clear:right; margin:0.5em 0 1em 1em; width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p 1xeygmujmex2hoeie1hu3opjetatk9k 392924 392923 2026-09-07T03:21:38Z MacTire02 219 ++ 392924 Scribunto text/plain local p = {} -- Helper to safely grab template arguments local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end -- Safely get manual parameters from priority list local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end function p.main(frame) local args = getArgs(frame) local rows = {} -- The universal border rule separating your modules local dividerLine = '<tr><td colspan="2" style="border-top:1px solid #a2a9b1; padding:0; height:0px;"></td></tr>' -- Centralized module injection manager local function appendModule(content) if content and content ~= "" then if #rows > 0 then table.insert(rows, dividerLine) end table.insert(rows, content) end end -------------------------------------------------- -- MODULE 1: HEADER & OFFICIAL NAMES -------------------------------------------------- local title = args["ennym"] or mw.title.getCurrentTitle().text local subTitle = getManual(args, {"ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh"}) if not subTitle or subTitle == "" then local successTitle, titleFallback = pcall(function() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P1448") if statements and #statements > 0 and statements[1].mainsnak and statements[1].mainsnak.datavalue then local value = statements[1].mainsnak.datavalue.value if value and value.text then local langCode = value.language or "" local successLang, langData = pcall(mw.loadData, "Module:Lang/data") local langName = langCode if successLang and langData and langData.lang_name_table and langData.lang_name_table.lang then langName = langData.lang_name_table.lang[langCode] or langCode end return value.text .. ' <small>([[' .. langName .. '|' .. langName .. ']])</small>' end end return nil end) if successTitle and titleFallback then subTitle = titleFallback end end local headerHtml = '<tr class="adr"><th colspan="2" class="fn org country-name" style="line-height:1.2em; padding:0.25em 0.33em 0.33em; font-size:1.25em; text-align:center; font-weight:normal;"><span style="font-weight:bold;">' .. title .. '</span>' if subTitle and subTitle ~= "" then headerHtml = headerHtml .. '<div style="padding-top:0.25em; font-weight:normal;">' .. subTitle .. '</div>' end headerHtml = headerHtml .. '</th></tr>' table.insert(rows, headerHtml) -------------------------------------------------- -- MODULE 2: FLAGS & ARMS -------------------------------------------------- -- REFLECTED CHANGE: Swapped path title to use 'bratteeyn' local successFlags, flagsMod = pcall(require, "Module:Kishtey fys çheer/bratteeyn") if successFlags and flagsMod and flagsMod.main then appendModule(flagsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 3: SYMBOLS (MOTTO & ANTHEMS) -------------------------------------------------- local successSymbols, symbolsMod = pcall(require, "Module:Kishtey fys çheer/cowraghyn") if successSymbols and symbolsMod and symbolsMod.main then appendModule(symbolsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 4: LOCATOR MAPS -------------------------------------------------- -- REFLECTED CHANGE: Swapped path title to use 'caslyssyn-çheerey' local successMaps, mapsMod = pcall(require, "Module:Kishtey fys çheer/caslyssyn-çheerey") if successMaps and mapsMod and mapsMod.main then appendModule(mapsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 5: CITIES & CAPITALS -------------------------------------------------- local successCities, citiesMod = pcall(require, "Module:Kishtey fys çheer/balley") if successCities and citiesMod and citiesMod.main then appendModule(citiesMod.main(frame, args)) end -------------------------------------------------- -- MODULE 6: LANGUAGES -------------------------------------------------- local successLanguages, languagesMod = pcall(require, "Module:Kishtey fys çheer/çhengaghyn") if successLanguages and languagesMod and languagesMod.main then appendModule(languagesMod.main(frame, args)) end if #rows <= 1 then return nil end return '<table class="infobox geography vcard" style="float:right; clear:right; margin:0.5em 0 1em 1em; width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p hg58fyg9s9x3bboo945ehah32wqbyyh 392925 392924 2026-09-07T03:24:26Z MacTire02 219 ++ 392925 Scribunto text/plain local p = {} -- Helper to safely grab template arguments local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end -- Safely get manual parameters from priority list local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end function p.main(frame) local args = getArgs(frame) local rows = {} -- The universal border rule separating your modules local dividerLine = '<tr><td colspan="2" style="border-top:1px solid #a2a9b1; padding:0; height:0px;"></td></tr>' -- Centralized module injection manager local function appendModule(content) if content and content ~= "" then if #rows > 0 then table.insert(rows, dividerLine) end table.insert(rows, content) end end -------------------------------------------------- -- MODULE 1: HEADER & OFFICIAL NAMES -------------------------------------------------- local title = args["ennym"] or mw.title.getCurrentTitle().text local subTitle = getManual(args, {"ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh"}) -- Safely loops through the statement rows array structure correctly if not subTitle or subTitle == "" then local entity = mw.wikibase.getEntityObject() if entity then local successLang, langData = pcall(mw.loadData, "Module:Lang/data") if successLang and langData and langData.lang_name_table and langData.lang_name_table.lang then local statements = entity:getBestStatements("P1448") if statements and #statements > 0 then for _, statement in ipairs(statements) do if statement.mainsnak and statement.mainsnak.datavalue then local value = statement.mainsnak.datavalue.value if value and value.text then local langCode = value.language or "" local langName = langData.lang_name_table.lang[langCode] or langCode subTitle = value.text .. ' <small>([[' .. langName .. '|' .. langName .. ']])</small>' break end end end end end end end local headerHtml = '<tr class="adr"><th colspan="2" class="fn org country-name" style="line-height:1.2em; padding:0.25em 0.33em 0.33em; font-size:1.25em; text-align:center; font-weight:normal;"><span style="font-weight:bold;">' .. title .. '</span>' if subTitle and subTitle ~= "" then headerHtml = headerHtml .. '<div style="padding-top:0.25em; font-weight:normal;">' .. subTitle .. '</div>' end headerHtml = headerHtml .. '</th></tr>' table.insert(rows, headerHtml) -------------------------------------------------- -- MODULE 2: FLAGS & ARMS -------------------------------------------------- local successFlags, flagsMod = pcall(require, "Module:Kishtey fys çheer/bratteeyn") if successFlags and flagsMod and flagsMod.main then appendModule(flagsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 3: SYMBOLS (MOTTO & ANTHEMS) -------------------------------------------------- local successSymbols, symbolsMod = pcall(require, "Module:Kishtey fys çheer/cowraghyn") if successSymbols and symbolsMod and symbolsMod.main then appendModule(symbolsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 4: LOCATOR MAPS -------------------------------------------------- local successMaps, mapsMod = pcall(require, "Module:Kishtey fys çheer/caslyssyn-çheerey") if successMaps and mapsMod and mapsMod.main then appendModule(mapsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 5: CITIES & CAPITALS -------------------------------------------------- local successCities, citiesMod = pcall(require, "Module:Kishtey fys çheer/balley") if successCities and citiesMod and citiesMod.main then appendModule(citiesMod.main(frame, args)) end -------------------------------------------------- -- MODULE 6: LANGUAGES -------------------------------------------------- local successLanguages, languagesMod = pcall(require, "Module:Kishtey fys çheer/çhengaghyn") if successLanguages and languagesMod and languagesMod.main then appendModule(languagesMod.main(frame, args)) end if #rows <= 1 then return nil end return '<table class="infobox geography vcard" style="float:right; clear:right; margin:0.5em 0 1em 1em; width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p 5mcd2i49y4zlhffyq40gygunt7x6920 392932 392925 2026-09-07T03:33:24Z MacTire02 219 ++ 392932 Scribunto text/plain local p = {} -- Helper to safely grab template arguments local function getArgs(frame) local parent = frame:getParent() if parent then return parent.args end return frame.args end -- Safely get manual parameters from priority list local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and value ~= "" then local trimmed = value:match("^%s*(.-)%s*$") if trimmed ~= "" then return trimmed end end end return nil end function p.main(frame) local args = getArgs(frame) local rows = {} -- The universal border rule separating your modules local dividerLine = '<tr><td colspan="2" style="border-top:1px solid #a2a9b1; padding:0; height:0px;"></td></tr>' -- Centralized module injection manager local function appendModule(content) if content and content ~= "" then if #rows > 0 then table.insert(rows, dividerLine) end table.insert(rows, content) end end -------------------------------------------------- -- MODULE 1: HEADER & OFFICIAL NAMES -------------------------------------------------- local title = args["ennym"] or mw.title.getCurrentTitle().text local subTitle = getManual(args, {"ennym_foddey_cadjincliaghtagh", "ennym_dooghyssagh"}) if not subTitle or subTitle == "" then local entity = mw.wikibase.getEntityObject() if entity then local successLang, langData = pcall(mw.loadData, "Module:Lang/data") if successLang and langData and langData.lang_name_table and langData.lang_name_table.lang then local statements = entity:getBestStatements("P1448") if statements and #statements > 0 then for _, statement in ipairs(statements) do if statement.mainsnak and statement.mainsnak.datavalue then local value = statement.mainsnak.datavalue.value if value and value.text then local langCode = value.language or "" local langName = langData.lang_name_table.lang[langCode] or langCode subTitle = value.text .. ' <small>([[' .. langName .. '|' .. langName .. ']])</small>' break end end end end end end end local headerHtml = '<tr class="adr"><th colspan="2" class="fn org country-name" style="line-height:1.2em; padding:0.25em 0.33em 0.33em; font-size:1.25em; text-align:center; font-weight:normal;"><span style="font-weight:bold;">' .. title .. '</span>' if subTitle and subTitle ~= "" then headerHtml = headerHtml .. '<div style="padding-top:0.25em; font-weight:normal;">' .. subTitle .. '</div>' end headerHtml = headerHtml .. '</th></tr>' table.insert(rows, headerHtml) -------------------------------------------------- -- MODULE 2: FLAGS & ARMS -------------------------------------------------- local successFlags, flagsMod = pcall(require, "Module:Kishtey fys çheer/bratteeyn") if successFlags and flagsMod and flagsMod.main then appendModule(flagsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 3: SYMBOLS (MOTTO & ANTHEMS) -------------------------------------------------- local successSymbols, symbolsMod = pcall(require, "Module:Kishtey fys çheer/cowraghyn") if successSymbols and symbolsMod and symbolsMod.main then appendModule(symbolsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 4: LOCATOR MAPS -------------------------------------------------- -- FIXED: Tries BOTH paths sequentially to guarantee zero-fail execution regardless of your physical page name setup local successMaps, mapsMod = pcall(require, "Module:Kishtey fys çheer/caslyssyn-çheerey") if not successMaps or not mapsMod then successMaps, mapsMod = pcall(require, "Module:Kishtey fys çheer/caslyssyn") end if successMaps and mapsMod and mapsMod.main then appendModule(mapsMod.main(frame, args)) end -------------------------------------------------- -- MODULE 5: CITIES & CAPITALS -------------------------------------------------- local successCities, citiesMod = pcall(require, "Module:Kishtey fys çheer/balley") if successCities and citiesMod and citiesMod.main then appendModule(citiesMod.main(frame, args)) end -------------------------------------------------- -- MODULE 6: LANGUAGES -------------------------------------------------- local successLanguages, languagesMod = pcall(require, "Module:Kishtey fys çheer/çhengaghyn") if successLanguages and languagesMod and languagesMod.main then appendModule(languagesMod.main(frame, args)) end if #rows <= 1 then return nil end return '<table class="infobox geography vcard" style="float:right; clear:right; margin:0.5em 0 1em 1em; width:23em; border:1px solid #a2a9b1; border-collapse:collapse;">' .. table.concat(rows) .. '</table>' end return p o797vjuzi1w218tw6mzlqynkyd2srav Steatyn Unnaneysit America 0 55829 392850 2026-09-06T15:27:03Z MacTire02 219 MacTire02 moved page [[Steatyn Unnaneysit America]] to [[Ny Steatyn Unnaneysit]] over redirect: ennym cadjin 392850 wikitext text/x-wiki #REDIRECT [[Ny Steatyn Unnaneysit]] 07m63uvowlvg6gkwbislwrjseaqgcv3 Module:Kishtey fys çheer/balley 828 55830 392905 2026-09-07T02:48:36Z MacTire02 219 moddyl noa 392905 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value):gsub("^%[%[", ""):gsub("%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function capitalIsLargest(capitalText, largestText) if not capitalText or not largestText then return false end if mw.ustring.lower(mw.text.trim(largestText)) == "preeu-valley" then return true end return mw.ustring.lower(normaliseCityName(capitalText)) == mw.ustring.lower(normaliseCityName(largestText)) end function p.main(frame, args) local capital = getManual(args, {"preeu-valley"}) local administrative = getManual(args, {"ynnyd_reiragh"}) local largest = getManual(args, {"balley_smoo"}) local capNote = getManual(args, {"noteyn_preeu-valley"}) local adminNote = getManual(args, {"noteyn_ynnyd_reiragh"}) local largeNote = getManual(args, {"noteyn_balley_smoo"}) local subRows = {} -- 1. Format Capital row if capital and capital ~= "none" then local label = args["sorçh_preeu-valley"] or "Preeu-valley" local displayLabel = '[[' .. label .. ']]' if capitalIsLargest(capital, largest) then displayLabel = '[[' .. label .. ']]<br/><small style="font-weight:normal;">(as y balley smoo)</small>' end local text = '[[' .. normaliseCityName(capital) .. '|' .. normaliseCityName(capital) .. ']]' if capNote and capNote ~= "" then text = text .. frame:expandTemplate{ title = "efn", args = { capNote } } end table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">' .. displayLabel .. '</th><td style="vertical-align:top;">' .. text .. '</td></tr>') end -- 2. Format Administrative Center row if administrative and administrative ~= "none" then local label = args["sorçh_ynnyd_reiragh"] or "Ynnyd reiragh" local text = '[[' .. normaliseCityName(administrative) .. '|' .. normaliseCityName(administrative) .. ']]' if adminNote and adminNote ~= "" then text = text .. frame:expandTemplate{ title = "efn", args = { adminNote } } end table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">[[' .. label .. ']]</th><td style="vertical-align:top;">' .. text .. '</td></tr>') end -- 3. Format Largest City row if largest and largest ~= "none" and not capitalIsLargest(capital, largest) then local text = '[[' .. normaliseCityName(largest) .. '|' .. normaliseCityName(largest) .. ']]' if largeNote and largeNote ~= "" then text = text .. frame:expandTemplate{ title = "efn", args = { largeNote } } end table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">Balley smoo</th><td style="vertical-align:top;">' .. text .. '</td></tr>') end if #subRows == 0 then return nil end return table.concat(subRows) end return p 531gjsgozswt572jeiu9njisyka9ujc 392912 392905 2026-09-07T02:56:53Z MacTire02 219 ++ 392912 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value):gsub("^%[%[", ""):gsub("%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end -- FIXED: Performs safe validation checks against BOTH clean city text names and literal keyword shortcuts local function capitalIsLargest(capitalText, largestText) if not largestText then return false end local cleanLargest = mw.ustring.lower(mw.text.trim(largestText)) if cleanLargest == "preeu-valley" or cleanLargest == "preeu_valley" then return true end if not capitalText then return false end return mw.ustring.lower(normaliseCityName(capitalText)) == mw.ustring.lower(normaliseCityName(largestText)) end function p.main(frame, args) local capital = getManual(args, {"preeu-valley"}) local administrative = getManual(args, {"ynnyd_reiragh"}) local largest = getManual(args, {"balley_smoo"}) local capNote = getManual(args, {"noteyn_preeu-valley"}) local adminNote = getManual(args, {"noteyn_ynnyd_reiragh"}) local largeNote = getManual(args, {"noteyn_balley_smoo"}) local subRows = {} -- 1. Format Capital row if capital and mw.ustring.lower(mw.text.trim(capital)) ~= "none" then local label = args["sorçh_preeu-valley"] or "Preeu-valley" local displayLabel = '[[' .. label .. ']]' -- Share the string variable down to check for matching largest city settings if capitalIsLargest(capital, largest) then displayLabel = '[[' .. label .. ']]<br/><small style="font-weight:normal;">(as y balley smoo)</small>' end local cleanCapName = normaliseCityName(capital) local text = '[[' .. cleanCapName .. '|' .. cleanCapName .. ']]' if capNote and capNote ~= "" then text = text .. frame:expandTemplate{ title = "efn", args = { capNote } } end table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">' .. displayLabel .. '</th><td style="vertical-align:top;">' .. text .. '</td></tr>') end -- 2. Format Administrative Center row if administrative and mw.ustring.lower(mw.text.trim(administrative)) ~= "none" then local label = args["sorçh_ynnyd_reiragh"] or "Ynnyd reiragh" local cleanAdminName = normaliseCityName(administrative) local text = '[[' .. cleanAdminName .. '|' .. cleanAdminName .. ']]' if adminNote and adminNote ~= "" then text = text .. frame:expandTemplate{ title = "efn", args = { adminNote } } end table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">[[' .. label .. ']]</th><td style="vertical-align:top;">' .. text .. '</td></tr>') end -- 3. Format Largest City row (FIXED: Bypassed instantly if capitalIsLargest evaluates to true) if largest and mw.ustring.lower(mw.text.trim(largest)) ~= "none" and not capitalIsLargest(capital, largest) then local cleanLargeName = normaliseCityName(largest) local text = '[[' .. cleanLargeName .. '|' .. cleanLargeName .. ']]' if largeNote and largeNote ~= "" then text = text .. frame:expandTemplate{ title = "efn", args = { largeNote } } end table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">Balley smoo</th><td style="vertical-align:top;">' .. text .. '</td></tr>') end if #subRows == 0 then return nil end return table.concat(subRows) end return p 20471psz86rm6jhv86iyaftd0o64gmx 392913 392912 2026-09-07T02:59:14Z MacTire02 219 kiartaghey 392913 Scribunto text/plain local p = {} local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value):gsub("^%[%[", ""):gsub("%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end local function checkCapitalIsLargest(capitalText, largestText) if not largestText then return false end local cleanLargest = mw.ustring.lower(mw.text.trim(largestText)) if cleanLargest == "preeu-valley" or cleanLargest == "preeu_valley" then return true end if not capitalText then return false end return mw.ustring.lower(normaliseCityName(capitalText)) == mw.ustring.lower(normaliseCityName(largestText)) end function p.main(frame, args) local capital = getManual(args, {"preeu-valley"}) local administrative = getManual(args, {"ynnyd_reiragh"}) local largest = getManual(args, {"balley_smoo"}) local capNote = getManual(args, {"noteyn_preeu-valley"}) local adminNote = getManual(args, {"noteyn_ynnyd_reiragh"}) local largeNote = getManual(args, {"noteyn_balley_smoo"}) local subRows = {} local isSame = checkCapitalIsLargest(capital, largest) -- 1. PROCESS CAPITAL ROW if capital and mw.ustring.lower(mw.text.trim(capital)) ~= "none" then local label = args["sorçh_preeu-valley"] or "Preeu-valley" local displayLabel = '[[' .. label .. ']]' -- If it's the largest city, attach the combined sub-caption directly here if isSame then displayLabel = '[[' .. label .. ']]<br/><small style="font-weight:normal;">(as y balley smoo)</small>' end local cleanCapName = normaliseCityName(capital) local text = '[[' .. cleanCapName .. '|' .. cleanCapName .. ']]' if capNote and capNote ~= "" then text = text .. frame:expandTemplate{ title = "efn", args = { capNote } } end table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">' .. displayLabel .. '</th><td style="vertical-align:top;">' .. text .. '</td></tr>') end -- 2. PROCESS ADMINISTRATIVE CENTER ROW if administrative and mw.ustring.lower(mw.text.trim(administrative)) ~= "none" then local label = args["sorçh_ynnyd_reiragh"] or "Ynnyd reiragh" local cleanAdminName = normaliseCityName(administrative) local text = '[[' .. cleanAdminName .. '|' .. cleanAdminName .. ']]' if adminNote and adminNote ~= "" then text = text .. frame:expandTemplate{ title = "efn", args = { adminNote } } end table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">[[' .. label .. ']]</th><td style="vertical-align:top;">' .. text .. '</td></tr>') end -- 3. PROCESS STANDALONE LARGEST CITY ROW (Safely hidden if handled by Capital) if largest and mw.ustring.lower(mw.text.trim(largest)) ~= "none" and not isSame then local cleanLargeName = normaliseCityName(largest) local text = '[[' .. cleanLargeName .. '|' .. cleanLargeName .. ']]' if largeNote and largeNote ~= "" then text = text .. frame:expandTemplate{ title = "efn", args = { largeNote } } end table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">Balley smoo</th><td style="vertical-align:top;">' .. text .. '</td></tr>') end if #subRows == 0 then return nil end return table.concat(subRows) end return p 9bqo4vsaeze4e78bdby5p59816nd03q 392914 392913 2026-09-07T03:00:58Z MacTire02 219 ++ 392914 Scribunto text/plain local p = {} local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value):gsub("^%[%[", ""):gsub("%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end function p.main(frame, args) local capital = getManual(args, {"preeu-valley"}) local administrative = getManual(args, {"ynnyd_reiragh"}) local largest = getManual(args, {"balley_smoo"}) local capNote = getManual(args, {"noteyn_preeu-valley"}) local adminNote = getManual(args, {"noteyn_ynnyd_reiragh"}) local largeNote = getManual(args, {"noteyn_balley_smoo"}) local subRows = {} -- 1. PRE-SCREEN FOR SYNONYM STATUS (Safely flags literal shortcut phrases) local isSame = false if largest then local cleanLargest = mw.ustring.lower(mw.text.trim(largest)) if cleanLargest == "preeu-valley" or cleanLargest == "preeu_valley" then isSame = true elseif capital and mw.ustring.lower(normaliseCityName(capital)) == mw.ustring.lower(normaliseCityName(largest)) then isSame = true end end -- 2. PROCESS CAPITAL ROW if capital and mw.ustring.lower(mw.text.trim(capital)) ~= "none" then local label = args["sorçh_preeu-valley"] or "Preeu-valley" local displayLabel = '[[' .. label .. ']]' -- Attach sub-caption inside the left column if matched if isSame then displayLabel = '[[' .. label .. ']]<br/><small style="font-weight:normal;">(as y balley smoo)</small>' end local cleanCapName = normaliseCityName(capital) local text = '[[' .. cleanCapName .. '|' .. cleanCapName .. ']]' if capNote and capNote ~= "" then text = text .. frame:expandTemplate{ title = "efn", args = { capNote } } end table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">' .. displayLabel .. '</th><td style="vertical-align:top;">' .. text .. '</td></tr>') end -- 3. PROCESS ADMINISTRATIVE CENTER ROW if administrative and mw.ustring.lower(mw.text.trim(administrative)) ~= "none" then local label = args["sorçh_ynnyd_reiragh"] or "Ynnyd reiragh" local cleanAdminName = normaliseCityName(administrative) local text = '[[' .. cleanAdminName .. '|' .. cleanAdminName .. ']]' if adminNote and adminNote ~= "" then text = text .. frame:expandTemplate{ title = "efn", args = { adminNote } } end table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">[[' .. label .. ']]</th><td style="vertical-align:top;">' .. text .. '</td></tr>') end -- 4. PROCESS STANDALONE LARGEST CITY ROW (Safely ignored if isSame matches) if largest and mw.ustring.lower(mw.text.trim(largest)) ~= "none" and not isSame then local cleanLargeName = normaliseCityName(largest) local text = '[[' .. cleanLargeName .. '|' .. cleanLargeName .. ']]' if largeNote and largeNote ~= "" then text = text .. frame:expandTemplate{ title = "efn", args = { largeNote } } end table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">Balley smoo</th><td style="vertical-align:top;">' .. text .. '</td></tr>') end if #subRows == 0 then return nil end return table.concat(subRows) end return p t8b77rh2jw1wrp9m5lelkn2l9aw5r54 392927 392914 2026-09-07T03:26:42Z MacTire02 219 ++ 392927 Scribunto text/plain local p = {} local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value):gsub("^%[%[", ""):gsub("%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end function p.main(frame, args) local capital = getManual(args, {"preeu-valley"}) local administrative = getManual(args, {"ynnyd_reiragh"}) local largest = getManual(args, {"balley_smoo"}) local capNote = getManual(args, {"noteyn_preeu-valley"}) local adminNote = getManual(args, {"noteyn_ynnyd_reiragh"}) local largeNote = getManual(args, {"noteyn_balley_smoo"}) local subRows = {} local isSame = false if largest then local cleanLargest = mw.ustring.lower(mw.text.trim(largest)) if cleanLargest == "preeu-valley" or cleanLargest == "preeu_valley" then isSame = true elseif capital and mw.ustring.lower(normaliseCityName(capital)) == mw.ustring.lower(normaliseCityName(largest)) then isSame = true end end if capital and mw.ustring.lower(mw.text.trim(capital)) ~= "none" then local label = args["sorçh_preeu-valley"] or "Preeu-valley" local displayLabel = '[[' .. label .. ']]' if isSame then displayLabel = '[[' .. label .. ']]<br/><small style="font-weight:normal;">(as y balley smoo)</small>' end local cleanCapName = normaliseCityName(capital) local text = '[[' .. cleanCapName .. '|' .. cleanCapName .. ']]' if capNote and capNote ~= "" then text = text .. frame:expandTemplate{ title = "efn", args = { capNote } } end table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">' .. displayLabel .. '</th><td style="vertical-align:top;">' .. text .. '</td></tr>') end if administrative and mw.ustring.lower(mw.text.trim(administrative)) ~= "none" then local label = args["sorçh_ynnyd_reiragh"] or "Ynnyd reiragh" local cleanAdminName = normaliseCityName(administrative) local text = '[[' .. cleanAdminName .. '|' .. cleanAdminName .. ']]' if adminNote and adminNote ~= "" then text = text .. frame:expandTemplate{ title = "efn", args = { adminNote } } end table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">[[' .. label .. ']]</th><td style="vertical-align:top;">' .. text .. '</td></tr>') end if largest and mw.ustring.lower(mw.text.trim(largest)) ~= "none" and not isSame then local cleanLargeName = normaliseCityName(largest) local text = '[[' .. cleanLargeName .. '|' .. cleanLargeName .. ']]' if largeNote and largeNote ~= "" then text = text .. frame:expandTemplate{ title = "efn", args = { largeNote } } end table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">Balley smoo</th><td style="vertical-align:top;">' .. text .. '</td></tr>') end if #subRows == 0 then return nil end return table.concat(subRows) end return p 3cd3kae9dsuhe94ddf52v0llbmb4pyl 392928 392927 2026-09-07T03:28:50Z MacTire02 219 ++ 392928 Scribunto text/plain local p = {} local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end local function normaliseCityName(value) if not value then return "" end value = mw.text.trim(value):gsub("^%[%[", ""):gsub("%]%]$", "") local pipe = mw.ustring.find(value, "|", 1, true) if pipe then value = mw.ustring.sub(value, 1, pipe - 1) end return mw.text.trim(value) end function p.main(frame, args) -- Safety check: If frame didn't pass in slot 1 due to orchestrator signature mismatches if not args and type(frame) == "table" then args = frame frame = mw.getCurrentFrame() elseif not frame then frame = mw.getCurrentFrame() end local capital = getManual(args, {"preeu-valley"}) local administrative = getManual(args, {"ynnyd_reiragh"}) local largest = getManual(args, {"balley_smoo"}) local capNote = getManual(args, {"noteyn_preeu-valley"}) local adminNote = getManual(args, {"noteyn_ynnyd_reiragh"}) local largeNote = getManual(args, {"noteyn_balley_smoo"}) local subRows = {} local isSame = false if largest then local cleanLargest = mw.ustring.lower(mw.text.trim(largest)) if cleanLargest == "preeu-valley" or cleanLargest == "preeu_valley" then isSame = true elseif capital and mw.ustring.lower(normaliseCityName(capital)) == mw.ustring.lower(normaliseCityName(largest)) then isSame = true end end -- 1. CAPITAL ROW if capital and mw.ustring.lower(mw.text.trim(capital)) ~= "none" then local label = args["sorçh_preeu-valley"] or "Preeu-valley" local displayLabel = '[[' .. label .. ']]' if isSame then displayLabel = '[[' .. label .. ']]<br/><small style="font-weight:normal;">(as y balley smoo)</small>' end local cleanCapName = normaliseCityName(capital) local text = '[[' .. cleanCapName .. '|' .. cleanCapName .. ']]' if capNote and capNote ~= "" then text = text .. frame:expandTemplate{ title = "efn", args = { capNote } } end table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">' .. displayLabel .. '</th><td style="vertical-align:top;">' .. text .. '</td></tr>') end -- 2. ADMINISTRATIVE CENTER ROW if administrative and mw.ustring.lower(mw.text.trim(administrative)) ~= "none" then local label = args["sorçh_ynnyd_reiragh"] or "Ynnyd reiragh" local cleanAdminName = normaliseCityName(administrative) local text = '[[' .. cleanAdminName .. '|' .. cleanAdminName .. ']]' if adminNote and adminNote ~= "" then text = text .. frame:expandTemplate{ title = "efn", args = { adminNote } } end table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">[[' .. label .. ']]</th><td style="vertical-align:top;">' .. text .. '</td></tr>') end -- 3. LARGEST CITY ROW if largest and mw.ustring.lower(mw.text.trim(largest)) ~= "none" and not isSame then local cleanLargeName = normaliseCityName(largest) local text = '[[' .. cleanLargeName .. '|' .. cleanLargeName .. ']]' if largeNote and largeNote ~= "" then text = text .. frame:expandTemplate{ title = "efn", args = { largeNote } } end table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">Balley smoo</th><td style="vertical-align:top;">' .. text .. '</td></tr>') end if #subRows == 0 then return nil end return table.concat(subRows) end return p 4pf7wzjg0bk2965whmnx8hs2e4tu6hi 392930 392928 2026-09-07T03:30:47Z MacTire02 219 ++ 392930 Scribunto text/plain local p = {} local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and value ~= "" then -- Safely use string trimming without relying on undefined sub-tables local trimmed = value:match("^%s*(.-)%s*$") if trimmed ~= "" then return trimmed end end end return nil end local function normaliseCityName(value) if not value then return "" end local clean = value:match("^%s*(.-)%s*$"):gsub("^%[%s*", ""):gsub("%]%s*$", "") local pipe = clean:find("|", 1, true) if pipe then clean = clean:sub(1, pipe - 1) end return clean:match("^%s*(.-)%s*$") end function p.main(frame, args) -- Fallback verification to catch argument slots accurately if not args and type(frame) == "table" then args = frame frame = mw.getCurrentFrame() elseif not frame then frame = mw.getCurrentFrame() end local capital = getManual(args, {"preeu-valley"}) local administrative = getManual(args, {"ynnyd_reiragh"}) local largest = getManual(args, {"balley_smoo"}) local capNote = getManual(args, {"noteyn_preeu-valley"}) local adminNote = getManual(args, {"noteyn_ynnyd_reiragh"}) local largeNote = getManual(args, {"noteyn_balley_smoo"}) local subRows = {} local isSame = false if largest then local cleanLargest = largest:match("^%s*(.-)%s*$"):lower() if cleanLargest == "preeu-valley" or cleanLargest == "preeu_valley" then isSame = true elseif capital and normaliseCityName(capital):lower() == normaliseCityName(largest):lower() then isSame = true end end -- 1. CAPITAL ROW if capital and capital:match("^%s*(.-)%s*$"):lower() ~= "none" then local label = args["sorçh_preeu-valley"] or "Preeu-valley" local displayLabel = '[[' .. label .. ']]' if isSame then displayLabel = '[[' .. label .. ']]<br/><small style="font-weight:normal;">(as y balley smoo)</small>' end local cleanCapName = normaliseCityName(capital) local text = '[[' .. cleanCapName .. '|' .. cleanCapName .. ']]' if capNote and capNote ~= "" then text = text .. frame:expandTemplate{ title = "efn", args = { capNote } } end table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">' .. displayLabel .. '</th><td style="vertical-align:top;">' .. text .. '</td></tr>') end -- 2. ADMINISTRATIVE CENTER ROW if administrative and administrative:match("^%s*(.-)%s*$"):lower() ~= "none" then local label = args["sorçh_ynnyd_reiragh"] or "Ynnyd reiragh" local cleanAdminName = normaliseCityName(administrative) local text = '[[' .. cleanAdminName .. '|' .. cleanAdminName .. ']]' if adminNote and adminNote ~= "" then text = text .. frame:expandTemplate{ title = "efn", args = { adminNote } } end table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">[[' .. label .. ']]</th><td style="vertical-align:top;">' .. text .. '</td></tr>') end -- 3. LARGEST CITY ROW if largest and largest:match("^%s*(.-)%s*$"):lower() ~= "none" and not isSame then local cleanLargeName = normaliseCityName(largest) local text = '[[' .. cleanLargeName .. '|' .. cleanLargeName .. ']]' if largeNote and largeNote ~= "" then text = text .. frame:expandTemplate{ title = "efn", args = { largeNote } } end table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">Balley smoo</th><td style="vertical-align:top;">' .. text .. '</td></tr>') end if #subRows == 0 then return nil end return table.concat(subRows) end return p 01zrpgbbuajof3a76opfevip8ukxg8b 392933 392930 2026-09-07T03:35:02Z MacTire02 219 -- 392933 Scribunto text/plain local p = {} -- Safely get manual parameters from priority list local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end -- Safely clean up link wrappers without risk of regex index errors local function normaliseCityName(value) if not value then return "" end local clean = mw.text.trim(value) clean = clean:gsub("^%[%[", ""):gsub("%]%]$", "") local pipe = clean:find("|", 1, true) if pipe then clean = clean:sub(1, pipe - 1) end return mw.text.trim(clean) end function p.main(frame, args) -- Fallback verification to catch argument slots accurately if frame context shifts if not args then args = frame frame = mw.getCurrentFrame() end local capital = getManual(args, {"preeu-valley"}) local administrative = getManual(args, {"ynnyd_reiragh"}) local largest = getManual(args, {"balley_smoo"}) local capNote = getManual(args, {"noteyn_preeu-valley"}) local adminNote = getManual(args, {"noteyn_ynnyd_reiragh"}) local largeNote = getManual(args, {"noteyn_balley_smoo"}) local subRows = {} -- Verify if capital and largest city match local isSame = false if largest then local cleanLargest = mw.text.trim(largest):lower() if cleanLargest == "preeu-valley" or cleanLargest == "preeu_valley" then isSame = true elseif capital and normaliseCityName(capital):lower() == normaliseCityName(largest):lower() then isSame = true end end -- 1. CAPITAL ROW if capital and mw.text.trim(capital):lower() ~= "none" then local label = args["sorçh_preeu-valley"] or "Preeu-valley" local displayLabel = '[[' .. label .. ']]' if isSame then displayLabel = '[[' .. label .. ']]<br/><small style="font-weight:normal;">(as y balley smoo)</small>' end local cleanCapName = normaliseCityName(capital) local text = '[[' .. cleanCapName .. '|' .. cleanCapName .. ']]' if capNote and capNote ~= "" then text = text .. frame:expandTemplate{ title = "efn", args = { capNote } } end table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">' .. displayLabel .. '</th><td style="vertical-align:top;">' .. text .. '</td></tr>') end -- 2. ADMINISTRATIVE CENTER ROW if administrative and mw.text.trim(administrative):lower() ~= "none" then local label = args["sorçh_ynnyd_reiragh"] or "Ynnyd reiragh" local cleanAdminName = normaliseCityName(administrative) local text = '[[' .. cleanAdminName .. '|' .. cleanAdminName .. ']]' if adminNote and adminNote ~= "" then text = text .. frame:expandTemplate{ title = "efn", args = { adminNote } } end table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">[[' .. label .. ']]</th><td style="vertical-align:top;">' .. text .. '</td></tr>') end -- 3. LARGEST CITY ROW if largest and mw.text.trim(largest):lower() ~= "none" and not isSame then local cleanLargeName = normaliseCityName(largest) local text = '[[' .. cleanLargeName .. '|' .. cleanLargeName .. ']]' if largeNote and largeNote ~= "" then text = text .. frame:expandTemplate{ title = "efn", args = { largeNote } } end table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">Balley smoo</th><td style="vertical-align:top;">' .. text .. '</td></tr>') end if #subRows == 0 then return nil end return table.concat(subRows) end return p kwx4lgbyj3f8eq7du7t1xmnf0pyd0xv Module:Kishtey fys çheer/bratteeyn 828 55831 392907 2026-09-07T02:50:53Z MacTire02 219 fo-voddyl noa 392907 Scribunto text/plain local p = {} local enmynCheerey = require("Module:Enmyn çheerey") local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end local function getWikidataImage(property) local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements(property) if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end local NON_RECTANGULAR_FLAGS = { ["Flag of Nepal.svg"] = true, ["Flag of Ohio.svg"] = true, ["Flag of Switzerland.svg"] = true, } local function needsFlagBorder(flagFile) if not flagFile then return true end if NON_RECTANGULAR_FLAGS[flagFile] then return false end if mw.ustring.find(mw.ustring.lower(flagFile), "nepal") then return false end return true end function p.main(frame, args) local flag = getManual(args, {"jalloo_brattagh"}) if flag and mw.ustring.lower(flag) == "none" then flag = nil elseif not flag then flag = getWikidataImage("P41") end local flag2 = getManual(args, {"jalloo_brattagh_2", "jalloo_brattagh_elley"}) if flag2 and mw.ustring.lower(flag2) == "none" then flag2 = nil elseif not flag2 then flag2 = getWikidataImage("P163") end local arms = getManual(args, {"jalloo_armys", "jalloo_cleinney", "jalloo_cowrey"}) if arms and mw.ustring.lower(arms) == "none" then arms = nil elseif not arms then arms = getWikidataImage("P94") end local arms2 = getManual(args, {"jalloo_armys_2", "jalloo_cleinney_2"}) if arms2 and mw.ustring.lower(arms2) == "none" then arms2 = nil elseif not arms2 then arms2 = getWikidataImage("P237") end if not flag and not flag2 and not arms and not arms2 then return nil end local nameRaw = getManual(args, {"ennym_gienneydagh", "ennym", "ennym_çheerey", "ennym_çheer"}) or (mw.title.getCurrentTitle() and mw.title.getCurrentTitle().text) or "" local name = enmynCheerey.genitive(nameRaw) local data = { flags = {}, armses = {} } if flag then table.insert(data.flags, { image = flag, width = getManual(args, {"lheead_brattagh"}) or "125px", hasBorder = needsFlagBorder(flag), link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh"}) or "Brattagh" }) end if flag2 then table.insert(data.flags, { image = flag2, width = getManual(args, {"lheead_brattagh_2", "lheead_brattagh"}) or "100px", hasBorder = needsFlagBorder(flag2), link = "Brattagh " .. name, label = getManual(args, {"fo-heidyl_brattagh_2"}) or "Brattagh elley" }) end if arms then local kind = getManual(args, {"art_sorçh_cowrey", "sorçh_cowrey"}) or "Armys" table.insert(data.armses, { image = arms, width = getManual(args, {"lheead_armys", "lheead_cleinney", "lheead_cowrey"}) or "85px", link = kind .. " " .. name, label = getManual(args, {"sorçh_cowrey"}) or "Armys" }) end if arms2 then table.insert(data.armses, { image = arms2, width = getManual(args, {"lheead_armys_2", "lheead_cleinney_2"}) or "85px", link = "Armys " .. name, label = getManual(args, {"sorçh_cowrey_2"}) or "Armys" }) end local imageCells = {} local captionCells = {} local hasFlags = #data.flags > 0 local hasArms = #data.armses > 0 if hasFlags then local flagContent = {} for _, f in ipairs(data.flags) do local border = f.hasBorder and '|style="border:1px solid #a2a9b1;"' or "" table.insert(flagContent, '[[Coadan:' .. f.image .. '|' .. f.width .. border .. ']]') end table.insert(imageCells, '<td align="center" style="' .. (hasArms and "width:58%; " or "width:100%; ") .. 'vertical-align:middle;">' .. table.concat(flagContent, '<br/>') .. '</td>') local flagCaptions = {} for _, f in ipairs(data.flags) do table.insert(flagCaptions, '<small>[[' .. f.link .. '|' .. f.label .. ']]</small>') end table.insert(captionCells, '<td align="center">' .. table.concat(flagCaptions, '<br/>') .. '</td>') end if hasArms then local armsContent = {} for _, a in ipairs(data.armses) do table.insert(armsContent, '[[Coadan:' .. a.image .. '|' .. a.width .. ']]') end table.insert(imageCells, '<td align="center" style="width:auto; vertical-align:middle;">' .. table.concat(armsContent, '<br/>') .. '</td>') local armsCaptions = {} for _, a in ipairs(data.armses) do table.insert(armsCaptions, '<small>[[' .. a.link .. '|' .. a.label .. ']]</small>') end table.insert(captionCells, '<td align="center">' .. table.concat(armsCaptions, '<br/>') .. '</td>') end return '<tr><td colspan="2" align="center" style="padding:0.5em 0;"><table align="center" style="width:100%; background:none;"><tr>' .. table.concat(imageCells) .. '</tr><tr>' .. table.concat(captionCells) .. '</tr></table></td></tr>' end return p lgsiva6vyusq7sdv7kkghyeulv7myz4 Module:Kishtey fys çheer/cowraghyn 828 55832 392908 2026-09-07T02:51:46Z MacTire02 219 fo-voddyl noa 392908 Scribunto text/plain local p = {} local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end local function getMottoData(args) local motto = getManual(args, {"jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa"}) local reference = getManual(args, {"imraa_jarroo_raa", "imraa_jarroo-raa"}) local chyndaa = getManual(args, {"çhyndaa_jarroo-raa", "chyndaa_jarroo-raa", "çhyndaa_jarroo_raa", "chyndaa_jarroo_raa"}) local tessen = getManual(args, {"tessen-lettyraghey_jarroo-raa", "tessen-lettyraghey_jarroo_raa"}) local finalText, finalRef = nil, nil if motto and mw.ustring.lower(motto) ~= "none" then finalText = motto if reference then finalRef = "<ref>" .. reference .. "</ref>" end else local entity = mw.wikibase.getEntityObject() if entity then local statements = entity:getBestStatements("P1451") if statements and #statements > 0 then local value = statements[1].mainsnak.datavalue.value if value and value.text then finalText = value.text end end end end if finalText then return { text = finalText, reference = finalRef, chyndaa = chyndaa, tessenLettyraghey = tessen } end return nil end function p.main(frame, args) local motto = getMottoData(args) local rows = {} if motto then local baseText = mw.text.trim(motto.text):gsub('^["“]', ''):gsub('["”]$', '') if not mw.ustring.find(baseText, "%[%[") then baseText = "''" .. baseText .. "''" end if motto.tessenLettyraghey and motto.tessenLettyraghey ~= "" then baseText = baseText .. " (''" .. motto.tessenLettyraghey .. "'')" end if motto.chyndaa and motto.chyndaa ~= "" then baseText = baseText .. " <br/><small>“" .. motto.chyndaa .. "”</small>" end if motto.reference then baseText = baseText .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. baseText) end local function formatAnthem(label, key) local title = getManual(args, {key}) if not title or mw.ustring.lower(title) == "none" then return end local clean = mw.text.trim(title):gsub('^["“]', ''):gsub('["”]$', '') if not mw.ustring.find(clean, "%[%[") then clean = '[[' .. clean .. '|' .. clean .. ']]' end local display = '“' .. clean .. '”' local tessen = getManual(args, {"tessen-lettyraghey_" .. key}) if tessen and tessen ~= "" then display = display .. " (''" .. tessen .. "'')" end local chyndaa = getManual(args, {"çhyndaa_" .. key, "chyndaa_" .. key}) if chyndaa and chyndaa ~= "" then display = display .. " <br/><small>“" .. chyndaa .. "”</small>" end local note = getManual(args, {"noteyn_" .. key}) if note and note ~= "" then display = display .. frame:expandTemplate{ title = "efn", args = { note } } end local ref = getManual(args, {"imraa_" .. key}) if ref then display = display .. "<ref>" .. ref .. "</ref>" end local audio = getManual(args, {"coadan_" .. key}) if audio and audio ~= "" then display = display .. '<br/><div style="text-align:center; margin-top:0.3em;">[[Coadan:' .. audio .. '|center]]</div>' end table.insert(rows, "'''" .. label .. ":&nbsp;'''" .. display) end formatAnthem("[[Arrane ashoonagh]]", "arrane_ashoonagh") formatAnthem("Anthym", "arrane") formatAnthem("[[Arrane reeoil]]", "arrane_reeoil") if #rows == 0 then return nil end return '<tr><td colspan="2" style="padding:0.4em 0; line-height:1.2em; text-align:center;">' .. table.concat(rows, "<br/>") .. '</td></tr>' end return p ofhb3lclpsxl9szayan4ofncm2j9agp 392926 392908 2026-09-07T03:25:53Z MacTire02 219 ++ 392926 Scribunto text/plain local p = {} local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end local function getMottoData(args) local motto = getManual(args, {"jarroo-raa_ashoonagh", "jarroo_raa", "jarroo-raa"}) local reference = getManual(args, {"imraa_jarroo_raa", "imraa_jarroo-raa"}) local chyndaa = getManual(args, {"çhyndaa_jarroo-raa", "chyndaa_jarroo-raa", "çhyndaa_jarroo_raa", "chyndaa_jarroo_raa"}) local tessen = getManual(args, {"tessen-lettyraghey_jarroo-raa", "tessen-lettyraghey_jarroo_raa"}) local finalText, finalRef = nil, nil if motto and mw.ustring.lower(motto) ~= "none" then finalText = motto if reference then finalRef = "<ref>" .. reference .. "</ref>" end else local entity = mw.wikibase.getEntityObject() if entity then local statements = entity:getBestStatements("P1451") if statements and #statements > 0 then -- FIXED: Safely loops through statements array elements instead of tracking a nil mainsnak index for _, statement in ipairs(statements) do if statement.mainsnak and statement.mainsnak.datavalue then local value = statement.mainsnak.datavalue.value if value and value.text then finalText = value.text break end end end end end end if finalText then return { text = finalText, reference = finalRef, chyndaa = chyndaa, tessenLettyraghey = tessen } end return nil end function p.main(frame, args) local motto = getMottoData(args) local rows = {} if motto then local baseText = mw.text.trim(motto.text):gsub('^["“]', ''):gsub('["”]$', '') if not mw.ustring.find(baseText, "%[%[") then baseText = "''" .. baseText .. "''" end if motto.tessenLettyraghey and motto.tessenLettyraghey ~= "" then baseText = baseText .. " (''" .. motto.tessenLettyraghey .. "'')" end if motto.chyndaa and motto.chyndaa ~= "" then baseText = baseText .. " <br/><small>“" .. motto.chyndaa .. "”</small>" end if motto.reference then baseText = baseText .. motto.reference end table.insert(rows, "'''[[Jarroo-raa]]:&nbsp;'''" .. baseText) end local function formatAnthem(label, key) local title = getManual(args, {key}) if not title or mw.ustring.lower(title) == "none" then return end local clean = mw.text.trim(title):gsub('^["“]', ''):gsub('["”]$', '') if not mw.ustring.find(clean, "%[%[") then clean = '[[' .. clean .. '|' .. clean .. ']]' end local display = '“' .. clean .. '”' local tessen = getManual(args, {"tessen-lettyraghey_" .. key}) if tessen and tessen ~= "" then display = display .. " (''" .. tessen .. "'')" end local chyndaa = getManual(args, {"çhyndaa_" .. key, "chyndaa_" .. key}) if chyndaa and chyndaa ~= "" then display = display .. " <br/><small>“" .. chyndaa .. "”</small>" end local note = getManual(args, {"noteyn_" .. key}) if note and note ~= "" then display = display .. frame:expandTemplate{ title = "efn", args = { note } } end local ref = getManual(args, {"imraa_" .. key}) if ref then display = display .. "<ref>" .. ref .. "</ref>" end local audio = getManual(args, {"coadan_" .. key}) if audio and audio ~= "" then display = display .. '<br/><div style="text-align:center; margin-top:0.3em;">[[Coadan:' .. audio .. '|center]]</div>' end table.insert(rows, "'''" .. label .. ":&nbsp;'''" .. display) end formatAnthem("[[Arrane ashoonagh]]", "arrane_ashoonagh") formatAnthem("Anthym", "arrane") formatAnthem("[[Arrane reeoil]]", "arrane_reeoil") if #rows == 0 then return nil end return '<tr><td colspan="2" style="padding:0.4em 0; line-height:1.2em; text-align:center;">' .. table.concat(rows, "<br/>") .. '</td></tr>' end return p 2szhmpyeautxgp9pghpi4wiw3yk7aj6 Module:Kishtey fys çheer/çhengaghyn 828 55833 392909 2026-09-07T02:52:28Z MacTire02 219 fo-voddyl noa 392909 Scribunto text/plain local p = {} local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end local function manxSort(a, b) local function norm(text) return mw.ustring.lower(text):gsub("çh", "ch") end return norm(a) < norm(b) end local function buildLanguageValue(raw, ref, note, frame) if not raw or mw.ustring.lower(mw.text.trim(raw)) == "none" then return nil, 0 end local names = {} for part in mw.text.gsplit(raw:gsub("<ref[^>]*>.-</ref>", ""):gsub("<ref[^>]*/>", ""), ",", true) do local trimmed = mw.text.trim(part) if trimmed ~= "" then table.insert(names, trimmed) end end table.sort(names, manxSort) local parts = {} for _, name in ipairs(names) do table.insert(parts, '[[' .. name .. '|' .. name .. ']]') end local display = '<div class="hlist">' .. table.concat(parts, '&nbsp;· ') .. '</div>' if note and note ~= "" and frame then display = display .. frame:expandTemplate{ title = "efn", args = { note } } end if ref then display = display .. "<ref>" .. ref .. "</ref>" end return display, #names end function p.main(frame, args) local officialRaw = getManual(args, {"çhengaghyn_oikoil", "çhengey_oikoil"}) local regionalRaw = getManual(args, {"çhengaghyn_ardjynagh", "çhengey_ardjynagh"}) local minorityRaw = getManual(args, {"mynçhengaghyn", "mynçhengey"}) local otherRaw = getManual(args, {"çhengaghyn", "çhengey"}) local official, offCount = buildLanguageValue(officialRaw, getManual(args, {"imraa_çhengaghyn_oikoil", "imraa_çhengey_oikoil"}), getManual(args, {"noteyn_çhengaghyn_oikoil", "noteyn_çhengey_oikoil"}), frame) local regional, regCount = buildLanguageValue(regionalRaw, getManual(args, {"imraa_çhengaghyn_ardjynagh", "imraa_çhengey_ardjynagh"}), getManual(args, {"noteyn_çhengaghyn_ardjynagh", "noteyn_çhengey_ardjynagh"}), frame) local minority, minCount = buildLanguageValue(minorityRaw, getManual(args, {"imraa_mynçhengaghyn", "imraa_mynçhengey"}), getManual(args, {"noteyn_mynçhengaghyn", "noteyn_mynçhengey"}), frame) local other, othCount = buildLanguageValue(otherRaw, getManual(args, {"imraa_çhengaghyn", "imraa_çhengey"}), getManual(args, {"noteyn_çhengaghyn", "noteyn_çhengey"}), frame) local subRows = {} if official then local label = offCount > 1 and "[[Çhengey oikoil\|Çhengaghyn oikoil]]" or "[[Çhengey oikoil]]" table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">' .. label .. '</th><td style="vertical-align:top;">' .. official .. '</td></tr>') if regional then local rLabel = regCount > 1 and "Çhengaghyn&nbsp;ardjynagh er&nbsp;enney" or "Çhengey&nbsp;ardjynagh er&nbsp;enney" table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:normal;">[[Çhengey ardjynagh|' .. rLabel .. ']]</th><td style="vertical-align:top;">' .. regional .. '</td></tr>') end elseif regional then local rLabel = regCount > 1 and "Çhengaghyn ardjynagh er enney" or "Çhengey ardjynagh er enney" table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">[[Çhengey ardjynagh|' .. rLabel .. ']]</th><td style="vertical-align:top;">' .. regional .. '</td></tr>') end if minority then local mLabel = minCount > 1 and "[[Mynçhengey\|Mynçhengaghyn]]" or "[[Mynçhengey]]" table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">' .. mLabel .. '</th><td style="vertical-align:top;">' .. minority .. '</td></tr>') end if other then local oLabel = args["sorçh_çhengaghyn"] or (othCount > 1 and "Çhengaghyn" or "Çhengey") table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">' .. oLabel .. '</th><td style="vertical-align:top;">' .. other .. '</td></tr>') end if #subRows == 0 then return nil end return table.concat(subRows) end return p 37dsrlzjnjgxa1xxrnsp485my6q36f2 392929 392909 2026-09-07T03:29:25Z MacTire02 219 ++ 392929 Scribunto text/plain local p = {} local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end local function manxSort(a, b) local function norm(text) return mw.ustring.lower(text):gsub("çh", "ch") end return norm(a) < norm(b) end local function buildLanguageValue(raw, ref, note, frame) if not raw or mw.ustring.lower(mw.text.trim(raw)) == "none" then return nil, 0 end local names = {} for part in mw.text.gsplit(raw:gsub("<ref[^>]*>.-</ref>", ""):gsub("<ref[^>]*/>", ""), ",", true) do local trimmed = mw.text.trim(part) if trimmed ~= "" then table.insert(names, trimmed) end end table.sort(names, manxSort) local parts = {} for _, name in ipairs(names) do table.insert(parts, '[[' .. name .. '|' .. name .. ']]') end local display = '<div class="hlist">' .. table.concat(parts, '&nbsp;· ') .. '</div>' if note and note ~= "" and frame then display = display .. frame:expandTemplate{ title = "efn", args = { note } } end if ref then display = display .. "<ref>" .. ref .. "</ref>" end return display, #names end function p.main(frame, args) -- Safety check: If frame didn't pass in slot 1 due to orchestrator signature mismatches if not args and type(frame) == "table" then args = frame frame = mw.getCurrentFrame() elseif not frame then frame = mw.getCurrentFrame() end local officialRaw = getManual(args, {"çhengaghyn_oikoil", "çhengey_oikoil"}) local regionalRaw = getManual(args, {"çhengaghyn_ardjynagh", "çhengey_ardjynagh"}) local minorityRaw = getManual(args, {"mynçhengaghyn", "mynçhengey"}) local otherRaw = getManual(args, {"çhengaghyn", "çhengey"}) local official, offCount = buildLanguageValue(officialRaw, getManual(args, {"imraa_çhengaghyn_oikoil", "imraa_çhengey_oikoil"}), getManual(args, {"noteyn_çhengaghyn_oikoil", "noteyn_çhengey_oikoil"}), frame) local regional, regCount = buildLanguageValue(regionalRaw, getManual(args, {"imraa_çhengaghyn_ardjynagh", "imraa_çhengey_ardjynagh"}), getManual(args, {"noteyn_çhengaghyn_ardjynagh", "noteyn_çhengey_ardjynagh"}), frame) local minority, minCount = buildLanguageValue(minorityRaw, getManual(args, {"imraa_mynçhengaghyn", "imraa_mynçhengey"}), getManual(args, {"noteyn_mynçhengaghyn", "noteyn_mynçhengey"}), frame) local other, othCount = buildLanguageValue(otherRaw, getManual(args, {"imraa_çhengaghyn", "imraa_çhengey"}), getManual(args, {"noteyn_çhengaghyn", "noteyn_çhengey"}), frame) local subRows = {} if official then local label = offCount > 1 and "[[Çhengey oikoil\|Çhengaghyn oikoil]]" or "[[Çhengey oikoil]]" table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">' .. label .. '</th><td style="vertical-align:top;">' .. official .. '</td></tr>') if regional then local rLabel = regCount > 1 and "Çhengaghyn&nbsp;ardjynagh er&nbsp;enney" or "Çhengey&nbsp;ardjynagh er&nbsp;enney" table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:normal;">[[Çhengey ardjynagh|' .. rLabel .. ']]</th><td style="vertical-align:top;">' .. regional .. '</td></tr>') end elseif regional then local rLabel = regCount > 1 and "Çhengaghyn ardjynagh er enney" or "Çhengey ardjynagh er enney" table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">[[Çhengey ardjynagh|' .. rLabel .. ']]</th><td style="vertical-align:top;">' .. regional .. '</td></tr>') end if minority then local mLabel = minCount > 1 and "[[Mynçhengey\|Mynçhengaghyn]]" or "[[Mynçhengey]]" table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">' .. mLabel .. '</th><td style="vertical-align:top;">' .. minority .. '</td></tr>') end if other then local oLabel = args["sorçh_çhengaghyn"] or (othCount > 1 and "Çhengaghyn" or "Çhengey") table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">' .. oLabel .. '</th><td style="vertical-align:top;">' .. other .. '</td></tr>') end if #subRows == 0 then return nil end return table.concat(subRows) end return p mmxhi9ef1r53jx2mc0ncd2j13k4nan6 392931 392929 2026-09-07T03:31:56Z MacTire02 219 ++ 392931 Scribunto text/plain local p = {} local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and value ~= "" then local trimmed = value:match("^%s*(.-)%s*$") if trimmed ~= "" then return trimmed end end end return nil end local function manxSort(a, b) local function norm(text) return text:lower():gsub("çh", "ch") end return norm(a) < norm(b) end local function buildLanguageValue(raw, ref, note, frame) if not raw or raw:match("^%s*(.-)%s*$"):lower() == "none" then return nil, 0 end -- Clean inline refs safely with clean, basic string logic patterns local cleaned = raw:gsub("<ref[^>]*>.-</ref>", ""):gsub("<ref[^>]*/>", "") local names = {} -- Safe tokenization via basic loop structures for part in string.gmatch(cleaned, "[^,]+") do local trimmed = part:match("^%s*(.-)%s*$") if trimmed ~= "" then table.insert(names, trimmed) end end if #names == 0 then return nil, 0 end table.sort(names, manxSort) local parts = {} for _, name in ipairs(names) do table.insert(parts, '[[' .. name .. '|' .. name .. ']]') end local display = '<div class="hlist">' .. table.concat(parts, '&nbsp;· ') .. '</div>' if note and note ~= "" and frame then display = display .. frame:expandTemplate{ title = "efn", args = { note } } end if ref then display = display .. "<ref>" .. ref .. "</ref>" end return display, #names end function p.main(frame, args) if not args and type(frame) == "table" then args = frame frame = mw.getCurrentFrame() elseif not frame then frame = mw.getCurrentFrame() end local officialRaw = getManual(args, {"çhengaghyn_oikoil", "çhengey_oikoil"}) local regionalRaw = getManual(args, {"çhengaghyn_ardjynagh", "çhengey_ardjynagh"}) local minorityRaw = getManual(args, {"mynçhengaghyn", "mynçhengey"}) local otherRaw = getManual(args, {"çhengaghyn", "çhengey"}) local official, offCount = buildLanguageValue(officialRaw, getManual(args, {"imraa_çhengaghyn_oikoil", "imraa_çhengey_oikoil"}), getManual(args, {"noteyn_çhengaghyn_oikoil", "noteyn_çhengey_oikoil"}), frame) local regional, regCount = buildLanguageValue(regionalRaw, getManual(args, {"imraa_çhengaghyn_ardjynagh", "imraa_çhengey_ardjynagh"}), getManual(args, {"noteyn_çhengaghyn_ardjynagh", "noteyn_çhengey_ardjynagh"}), frame) local minority, minCount = buildLanguageValue(minorityRaw, getManual(args, {"imraa_mynçhengaghyn", "imraa_mynçhengey"}), getManual(args, {"noteyn_mynçhengaghyn", "noteyn_mynçhengey"}), frame) local other, othCount = buildLanguageValue(otherRaw, getManual(args, {"imraa_çhengaghyn", "imraa_çhengey"}), getManual(args, {"noteyn_çhengaghyn", "noteyn_çhengey"}), frame) local subRows = {} if official then local label = offCount > 1 and "[[Çhengey oikoil\|Çhengaghyn oikoil]]" or "[[Çhengey oikoil]]" table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">' .. label .. '</th><td style="vertical-align:top;">' .. official .. '</td></tr>') if regional then local rLabel = regCount > 1 and "Çhengaghyn&nbsp;ardjynagh er&nbsp;enney" or "Çhengey&nbsp;ardjynagh er&nbsp;enney" table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:normal;">[[Çhengey ardjynagh|' .. rLabel .. ']]</th><td style="vertical-align:top;">' .. regional .. '</td></tr>') end elseif regional then local rLabel = regCount > 1 and "Çhengaghyn ardjynagh er enney" or "Çhengey ardjynagh er enney" table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">[[Çhengey ardjynagh|' .. rLabel .. ']]</th><td style="vertical-align:top;">' .. regional .. '</td></tr>') end if minority then local mLabel = minCount > 1 and "[[Mynçhengey\|Mynçhengaghyn]]" or "[[Mynçhengey]]" table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">' .. mLabel .. '</th><td style="vertical-align:top;">' .. minority .. '</td></tr>') end if other then local oLabel = args["sorçh_çhengaghyn"] or (othCount > 1 and "Çhengaghyn" or "Çhengey") table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">' .. oLabel .. '</th><td style="vertical-align:top;">' .. other .. '</td></tr>') end if #subRows == 0 then return nil end return table.concat(subRows) end return p 1ulwzl9o1jpdo28apslmglbyz5uz8qg 392934 392931 2026-09-07T03:35:29Z MacTire02 219 ++ 392934 Scribunto text/plain local p = {} local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end local function manxSort(a, b) local function norm(text) return text:lower():gsub("çh", "ch") end return norm(a) < norm(b) end local function buildLanguageValue(raw, ref, note, frame) if not raw or mw.text.trim(raw):lower() == "none" then return nil, 0 end -- Safe tokenization using native text utilities instead of fragile match strings local cleaned = raw:gsub("<ref[^>]*>.-</ref>", ""):gsub("<ref[^>]*/>", "") local names = mw.text.split(cleaned, ",", true) local filteredNames = {} for _, part in ipairs(names) do local trimmed = mw.text.trim(part) if trimmed ~= "" then table.insert(filteredNames, trimmed) end end if #filteredNames == 0 then return nil, 0 end table.sort(filteredNames, manxSort) local parts = {} for _, name in ipairs(filteredNames) do table.insert(parts, '[[' .. name .. '|' .. name .. ']]') end local display = '<div class="hlist">' .. table.concat(parts, '&nbsp;· ') .. '</div>' if note and note ~= "" and frame then display = display .. frame:expandTemplate{ title = "efn", args = { note } } end if ref then display = display .. "<ref>" .. ref .. "</ref>" end return display, #filteredNames end function p.main(frame, args) if not args then args = frame frame = mw.getCurrentFrame() end local officialRaw = getManual(args, {"çhengaghyn_oikoil", "çhengey_oikoil"}) local regionalRaw = getManual(args, {"çhengaghyn_ardjynagh", "çhengey_ardjynagh"}) local minorityRaw = getManual(args, {"mynçhengaghyn", "mynçhengey"}) local otherRaw = getManual(args, {"çhengaghyn", "çhengey"}) local official, offCount = buildLanguageValue(officialRaw, getManual(args, {"imraa_çhengaghyn_oikoil", "imraa_çhengey_oikoil"}), getManual(args, {"noteyn_çhengaghyn_oikoil", "noteyn_çhengey_oikoil"}), frame) local regional, regCount = buildLanguageValue(regionalRaw, getManual(args, {"imraa_çhengaghyn_ardjynagh", "imraa_çhengey_ardjynagh"}), getManual(args, {"noteyn_çhengaghyn_ardjynagh", "noteyn_çhengey_ardjynagh"}), frame) local minority, minCount = buildLanguageValue(minorityRaw, getManual(args, {"imraa_mynçhengaghyn", "imraa_mynçhengey"}), getManual(args, {"noteyn_mynçhengaghyn", "noteyn_mynçhengey"}), frame) local other, othCount = buildLanguageValue(otherRaw, getManual(args, {"imraa_çhengaghyn", "imraa_çhengey"}), getManual(args, {"noteyn_çhengaghyn", "noteyn_çhengey"}), frame) local subRows = {} if official then local label = offCount > 1 and "[[Çhengey oikoil\|Çhengaghyn oikoil]]" or "[[Çhengey oikoil]]" table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">' .. label .. '</th><td style="vertical-align:top;">' .. official .. '</td></tr>') if regional then local rLabel = regCount > 1 and "Çhengaghyn&nbsp;ardjynagh er&nbsp;enney" or "Çhengey&nbsp;ardjynagh er&nbsp;enney" table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:normal;">[[Çhengey ardjynagh|' .. rLabel .. ']]</th><td style="vertical-align:top;">' .. regional .. '</td></tr>') end elseif regional then local rLabel = regCount > 1 and "Çhengaghyn ardjynagh er enney" or "Çhengey ardjynagh er enney" table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">[[Çhengey ardjynagh|' .. rLabel .. ']]</th><td style="vertical-align:top;">' .. regional .. '</td></tr>') end if minority then local mLabel = minCount > 1 and "[[Mynçhengey\|Mynçhengaghyn]]" or "[[Mynçhengey]]" table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">' .. mLabel .. '</th><td style="vertical-align:top;">' .. minority .. '</td></tr>') end if other then local oLabel = args["sorçh_çhengaghyn"] or (othCount > 1 and "Çhengaghyn" or "Çhengey") table.insert(subRows, '<tr><th style="vertical-align:top; white-space:nowrap; text-align:left; font-weight:bold;">' .. oLabel .. '</th><td style="vertical-align:top;">' .. other .. '</td></tr>') end if #subRows == 0 then return nil end return table.concat(subRows) end return p eafcn7yanhzc8uu915dh020nww0l59e Module:Kishtey fys çheer/caslyssyn-çheerey 828 55834 392911 2026-09-07T02:55:01Z MacTire02 219 fo-voddyl noa 392911 Scribunto text/plain local p = {} local function getManual(args, names) for _, name in ipairs(names) do local value = args[name] if value and mw.text.trim(value) ~= "" then return mw.text.trim(value) end end return nil end local function getWikidataLocatorMap() local entity = mw.wikibase.getEntityObject() if not entity then return nil end local statements = entity:getBestStatements("P242") if not statements or #statements == 0 then return nil end for _, statement in ipairs(statements) do local mainsnak = statement.mainsnak if mainsnak and mainsnak.snaktype == "value" and mainsnak.datavalue and mainsnak.datavalue.type == "string" then local file = mainsnak.datavalue.value if file and file ~= "" then return file end end end return nil end function p.main(frame, args) local map = getManual(args, {"jalloo_caslys-çheerey", "jalloo_caslys"}) if map and mw.ustring.lower(map) == "none" then return nil end if not map then map = getWikidataLocatorMap() end if not map then return nil end local width = getManual(args, {"lheead_caslys-çheerey", "lheead_caslys"}) or "250px" local caption = getManual(args, {"fo-heidyl_caslys-çheerey", "fo-heidyl_caslys"}) local mapHtml = '[[Coadan:' .. map .. '|' .. width .. '|center]]' if caption then mapHtml = mapHtml .. '<div style="position:relative; top:0.3em;"><small>' .. caption .. '</small></div>' end return '<tr><td colspan="2" style="text-align:center; padding:0.2em 0em;">' .. mapHtml .. '</td></tr>' end return p 3klibvkdqchzdtn68gp4z4h9s0d99zy