Template talk:Langcode

From OpenStreetMap Wiki
Jump to navigation Jump to search

Revert

The change in early September has not been as successful as intended. It is beneficial for Zh-hans:Map Features and Zh-hant:Map Features where the large processor node count for pages with this language syntax was blowing up rendering but, instead, pages not in Chinese are made more complicated and Map Features in some languages and several project pages cannot be rendered. It did not tackle the underlying problem that the {{langcode|{{{lang|}}}}} syntax, far from being the optimisation that several edits adding it to templates claimed it was in their edit summaries, switches off Mediawiki’s cache and evaluates the template repeatedly instead of once.

As such, I suggest reverting the change for the present.--Andrew (talk) 12:32, 19 September 2018 (UTC)

Thank you for sharing this information and investing your time and effort into that. I do not fully understand this template, so I do have no objections, just the question whether you found out anything that would affect my revision of Template:Relation? --Tigerfell This user is member of the wiki team of OSM (Let's talk) 13:59, 19 September 2018 (UTC)
The Relation template, which cannot be cached because of the relation id argument, includes {{LangSwitch}} (also uncachable) in the Route Manager link, which then calls {{langcode|{{{lang|}}}}} twice. Breaking that chain would be worth doing separately from any bigger rewrite.
Thanks for clarifying.
If you call Lua many times on the same page the page renderer might give up. It may be possible to change the limits set in Mediawiki if there are no undesirable side-effects.--Andrew (talk) 20:57, 19 September 2018 (UTC)
Talking about the "manage" link, I actually planned to remove it, as I can not access this address. I just emailed the webmaster of the domain to check the current status. Thank you again, I will test this a bit more intensively on long pages then. --Tigerfell This user is member of the wiki team of OSM (Let's talk) 21:53, 19 September 2018 (UTC)


I am going to reuse some of the module's code for the lang-switch in the other template as I can not use the template itself. Just that you know. --Tigerfell This user is member of the wiki team of OSM (Let's talk) 18:16, 22 September 2018 (UTC)

Hello @Dragomaniaca:. Unfortunately your change breaks some templates. I saw its effect on Template:Dir and Template:Country
(screenshot - translations are broken and also words are reversed).
I don't know if any other thing would be affected by that change. iriman (talk) 05:56, 3 October 2019 (UTC)

No. None other thing would be affected by this change. It’s approved. We shouldn’t use the {{#if:{{{1|}}}|{{{1}}} parser function, instead we would use {{{1|. Dragomaniaca (talk) 14:37, 3 October 2019 (UTC)
Thanks for clarifying. I'm not a template pro. It would be greate and I would appreciate if you could also update related templates accordingly (esp. dir and country). iriman (talk) 16:17, 3 October 2019 (UTC)
What you mean by "It’s approved"? Mateusz Konieczny (talk) 19:27, 6 October 2019 (UTC)
The screenshot you showed is consistent with a nonsense value of the lang= parameter to {{Place}}. I don’t see how a change here would trigger it unless the weird markup in {{Place}} is responsible. --Andrew (talk) 21:26, 3 October 2019 (UTC)
The change to this template definitely breaks a number of pages that use it. The #invoke command is exceptionally sensitive to formatting, which has caught me out a number of times. --Andrew (talk) 17:23, 6 October 2019 (UTC)

More robust implementation

Module:Langcode relies on passing in a blacklist of prefixes that aren't namespaces. By contrast, Module:Languages's languageFromTitle() and Module:OsmPageTitleParser's parseTitleToObj() both rely on a whitelist of namespaces maintained at Module:OSM Constants and Module:Languages/config, respectively. A whitelist-based approach is more maintainable because the set of language namespaces is more predictable – we can even piggyback on MediaWiki's language list. Perhaps we could migrate this template to either of the whitelist-based functions instead. The other modules and their config modules do add a modest amount to the page size, but the config module gets loaded as data, which means it only gets transcluded into the page once. – Minh Nguyễn 💬 04:47, 28 November 2019 (UTC)

Yes you would appear to be right. There’s also {{Pagelanguage}} with its own whitelist.--Andrew (talk) 07:24, 28 November 2019 (UTC)
This could also return the page content language set in Mediawiki if set to something other than the default of English. Templates that are confident that page languages have been tagged and any pages with a page content language set to English really are in English can use {{PAGELANGUAGE}} instead. --Andrew (talk) 07:39, 28 November 2019 (UTC)

Proposed change: use page content language if set

I propose to change this template to:

{{#if:{{{1|}}}|{{{1}}}|{{#ifeq:{{PAGELANGUAGE}}|en|{{#invoke:langcode|langcode
      |Key=en|POI=en|Tag=en|Relation=en|Canada=en|Iran=en}} }}|{{PAGELANGUAGE}} }}<noinclude>{{Documentation}}</noinclude>

This means that the language returned is the page content language set in Mediawiki if it doesn’t remain defaulted to English, for instance Zoo Osnabrück is reported as German. Note that if you are confident that page content languages are set thoroughly and any page still set to English really is in English you can just use {{PAGELANGUAGE}} instead of {{langcode}}.

--Andrew (talk) 19:11, 18 June 2020 (UTC)