Page MenuHomePhabricator

Add a {{USERLANGUAGE}} magic word
Open, Stalled, LowestPublic

Description

mw.getContentLanguage().code -- Returns the content language.
mw.getCurrentFrame():preprocess("{{PAGELANGUAGE}}") -- Returns the page language.
mw.getCurrentFrame():preprocess( "{{int:Lang}}" ) -- Returns the user language.

Author: gangleri

Description:
Halló,

The benefits of a variable returning the language code of the selected user interface can not be foreseen and all "applications" can not be described here.

Hopefully it should be easy to implement and be available soon.

Regards Reinhardt


Version: unspecified
Severity: enhancement
URL: https://commons.wikimedia.org/wiki/MediaWiki:Lang?uselang=eo
See Also:

Workarounds available:

  • For system administrators, installing the UILangCode extension which provides the {{UILANGCODE}} variable
  • For system administrators, installing the MyVariables extension which provides the {{USERLANGUAGECODE}} variable
  • For system administrators, installing the LanguageCode extension which provides the {{USERLANGUAGE}} variable
  • For wiki administrators, using {{int:lang}} after creating all MediaWiki:Lang subpages.
  • I'm looking for how to use this task
  • but I do not find in this task how to use it
  • I tried :
  • langs.page_lang = modes.frame:preprocess( "PAGELANGUAGE")
  • and langs.page_lang = modes.frame:preprocess( title = "PAGELANGUAGE")
  • and langs.user_lang = modes.frame:preprocess( title = "USERLANGUAGECODE")
  • But none worked
  • You should provide in the description of the task itself the right way to use it
  • Thanks in advance for all coders

Related Objects

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes

I'm sorry but per comment 14 this is considered a lowest priority bug and nobody is working on it; don't mislead users.
I'd like to have it, too, but voting is how to express it.

By the way:

(In reply to comment #16)

Note comment 13: it could be enough to enable Translate extension on Commons.

That magic word is a local hack, but for templates et al. see:
[[mw:Help:Extension:Translate/Unstructured element translation]]
[[Help:Extension:Translate/Page_translation_administration#Markup_examples]]

(In reply to comment #18)

I'm sorry but per comment 14 this is considered a lowest priority bug and
nobody is working on it; don't mislead users.
I'd like to have it, too, but voting is how to express it.

Hard to argue with the beautiful words of the Brion The Great and Chad H.

But thing is that this feature is _really_ needed, and still _really_ used all these years. Okay, "we hardly want to encourage the behavior" - we want to encourage creating of large sets of faked MediaWiki messages?

(In reply to comment #18)

I'm sorry but per comment 14 this is considered a lowest priority bug and
nobody is working on it; don't mislead users.

Note that the comment was made before the time every page on Commons used the {{int:lang}} hack. After that, and especially after bug 14404 was fixed, I don’t see the reason why the {{int:lang}} hack shouldn’t be implemented properly instead of abusing a different construction. The cache coherence issues should have been resolved by bug 14404, AFAICS. So, there is no need why this should be a WONTFIX. (See also http://lists.wikimedia.org/pipermail/wikitech-l/2012-January/057763.html (corrected link from comment #15).)

As for “nobody is working on it”: this is not difficult to implement, programming-wise. Just to make sure it gets accepted to core.

NB: I inform of Amir E. Aharoni (from Language engineering team) about this issue. He seems willing to do it soon.

(In reply to comment #21)

NB: I inform of Amir E. Aharoni (from Language engineering team) about this
issue. He seems willing to do it soon.

More precisely, I suggested opening a bug about this issue in a private chat. I didn't know that this one is open already, but it makes sense.

That's the kind of thing that the Language engineering team does, but just as Mormegil says: the important part is getting the consensus to accept it into core.

Also one reason for this feature: using in the URLs as in the http://www.wikidata.org/wiki/MediaWiki:Sitesupport-url

In the multilang. Wikimedia projects (Meta, Commons, Wikidata, Wikispecies, Wikimania, WMF wiki, ...), fundraising's URL was generated with English-language option "&uselang=en".

With using {{USERLANG}} variable, will be able to direct users to the donation page on the language that they use in the his interface.

(In reply to comment #23)

Also one reason for this feature: using in the URLs as in the
http://www.wikidata.org/wiki/MediaWiki:Sitesupport-url

In this example, however, you have the non-hacky workaround of creating the subpages with correct uselang. We should do it by bot at least on Meta, Commons and Wikidata, perhaps. (Better to discuss on Meta though.)

  • Bug 46372 has been marked as a duplicate of this bug. ***

ziggy wrote:

For those who'd like this feature, I've hacked a new magic word as part of my copy of UniversalLanguageSelector: {{USERLANG}}

New UniversalLanguageSelector.i18n.magic.php file:
$magicWords = array();
$magicWords['en'] = array('userlang' => array(0,'USERLANG'));

Added to UniversalLanguageSelector.php, below last hook:
$wgHooks['ParserGetVariableValueSwitch'][] =
'UniversalLanguageSelectorHooks::getLanguageMagic';
$wgHooks['MagicWordwgVariableIDs'][] =
'UniversalLanguageSelectorHooks::getLanguageMagicDeclareVarIds';

Added to UniversalLanguageSelector.hooks.php, above getLanguage(...):
public static function getLanguageMagicDeclareVarIds( &$customVariableIds ) {

$customVariableIds[] = 'userlang'; return true; }

public static function getLanguageMagic(&$parser, &$cache, &$magicWordId, &$ret
) { if ( 'userlang' == $magicWordId ) {

  $context = RequestContext::getMain();
  $code = $context->getLanguage()->getCode();
  $ret = self::getLanguage($context->getUser(), $code) ? $code : '';
  if($ret != $wgLanguageCode) $parser->disableCache(); }
return true; }

Works like charm, although heeding the warnings of the previous posters the cache gets disabled if the userlang is different than the wgLanguageCode :-) It now behaves very much like the dynamic results obtained from a database (e.g. WikiDB)

(In reply to ziggy from comment #26)

For those who'd like this feature, I've hacked a new magic word as part of
my copy of UniversalLanguageSelector: {{USERLANG}}

New UniversalLanguageSelector.i18n.magic.php file:
$magicWords = array();
$magicWords['en'] = array('userlang' => array(0,'USERLANG'));

Added to UniversalLanguageSelector.php, below last hook:
$wgHooks['ParserGetVariableValueSwitch'][] =
'UniversalLanguageSelectorHooks::getLanguageMagic';
$wgHooks['MagicWordwgVariableIDs'][] =
'UniversalLanguageSelectorHooks::getLanguageMagicDeclareVarIds';

Added to UniversalLanguageSelector.hooks.php, above getLanguage(...):
public static function getLanguageMagicDeclareVarIds( &$customVariableIds ) {

$customVariableIds[] = 'userlang'; return true; }

public static function getLanguageMagic(&$parser, &$cache, &$magicWordId,
&$ret
) { if ( 'userlang' == $magicWordId ) {

  $context = RequestContext::getMain();
  $code = $context->getLanguage()->getCode();
  $ret = self::getLanguage($context->getUser(), $code) ? $code : '';
  if($ret != $wgLanguageCode) $parser->disableCache(); }
return true; }

Works like charm, although heeding the warnings of the previous posters the
cache gets disabled if the userlang is different than the wgLanguageCode :-)
It now behaves very much like the dynamic results obtained from a database
(e.g. WikiDB)

Could you please commit this to Gerrit?

(In reply to Melancholie from comment #13)

Note: On Betawiki (translatewiki.net) there is such a magic word; but they
call it {{UILANGCODE}}

That's https://git.wikimedia.org/blob/translatewiki.git/HEAD/nikext.php btw.

(In reply to Nemo from comment #28)

(In reply to Melancholie from comment #13)

Note: On Betawiki (translatewiki.net) there is such a magic word; but they
call it {{UILANGCODE}}

That's https://git.wikimedia.org/blob/translatewiki.git/HEAD/nikext.php btw.

Does it support caching correctly? Is there any reason not to use this?

(In reply to PiRSquared17 from comment #29)

Does it support caching correctly? Is there any reason not to use this?

It would if it used $parser->getOptions()->getUserLang().

demon removed a subscriber: demon.Dec 8 2014, 10:42 PM
He7d3r updated the task description. (Show Details)Apr 8 2015, 10:49 PM
He7d3r set Security to None.
Nemo_bis updated the task description. (Show Details)Apr 22 2015, 7:02 PM
Rical added a subscriber: Rical.Jul 13 2015, 4:09 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptNov 11 2015, 11:51 AM
kaldari added a comment.EditedFeb 10 2016, 11:35 PM

No one has commented on this bug in a couple years. It was closed twice as WONTFIX and it doesn't seem like there is developer support for implementing it. Is there any reason it should be kept open?

This task is needed as part of central modules T121470#1880317
The goal is to show arguments names, categories, error messages in the helper language when he helps a small wiki which has not enough specialists of modules.
See also T122086

No one has commented on this bug in a couple years. It was closed twice as WONTFIX and it doesn't seem like there is developer support for implementing it. Is there any reason it should be kept open?

All reasons is present. This is still needed. Template "Uselang" (tghrough "hacked" way) is still used widely.

The problem with this task is that it asks for a specific solution (which is unlikely to be implemented) instead of focussing the discussion on what are the use cases and how those cases could be best solved.

@Nikerabbit: That's a good point. The only use cases I know of currently are:

More use cases would be helpful.

V111P added a subscriber: V111P.May 6 2016, 11:25 PM
Rical added a comment.EditedMay 7 2016, 7:42 AM

In at least 3 cases we need adaptations of translations depending not only from the wiki language or the user language :

  • The genre of the user in his preferences
  • The format of date-time in some régions or sub-languages
  • In mw.language.convertPlural() "if your language has several plural forms"

Can we, and is it adapted, to group all these cases in a same translations adapter with some parameters linked to the user : gender, sub-language, rights(sysop, bureaucrat...), plural forms?

Rical added a comment.Aug 15 2017, 1:23 PM

That permit to really try the user language for central modules.
user_lang = modes.frame:preprocess( "{{int:Lang}}" )
creating https://fr.wikisource.org/wiki/MediaWiki:Lang/en
creating https://fr.wikisource.org/wiki/MediaWiki:Lang/es
creating https://fr.wikisource.org/wiki/MediaWiki:Lang/fr
also in some other wikis if needed.
Thanks

Rical added a comment.Aug 15 2017, 2:37 PM

Create a page to permit each language seems to me very strange.
Another way could be to define the basic language of the wiki on the first line.
Then, on the second line, a list of all other languages to permit.
This way could permit to administrators to easy know or change this list without long researches.

Verdy_p added a subscriber: Verdy_p.EditedSep 7 2017, 4:24 PM

Any way used by {{int:Lang}} and implemented internally by the {{int:}} parserfunction that will always need to get the correct user language should be still be made available even if we don't manually create the MediaWiki:Lang/* resources (because the "int:" extension can already internally recognize the resource name and does not need to query the database to retrieve these fake pages, all it has to do is still to get the correct user language code for any kind of {{int:*}} message needed by the Mediawiki core itself; I think it also adds some work to also mark specially the expanded pages so that they will be cached separately according to the user language)
The same should then be made for Lua, by adding into Scribunto supporting the {{#invoke:}} extension a basic module that will do the same thing as what the {{int:}} extension does, using the same logic for cache management and to return the same language code: it should then be exposed into Lua by a "mw:userLanguage()" that won't require any use of "frame:prepropress()" with its unbelieavable, and undocumented side-effects (notably the fact it fully expands prematurely all text in parent frames instead of just the wikitext given in its single string parameter !)

So Scribunto now really needs to be fixed. Demon,station has been done that this was really needed:

  • add "mw:getUserLanguage()" or "frame:getUserLanguage()" : I don't know which class is the best place to add this API.
  • provide immediately a workaround in "frame:preprocess(text)" so that it will not preprocess the given text when it just matches /^\{\{[ *[Ii][Nn][Tn]: *[Ll]ang *\}\}$/ : it will use the previous function instead
  • fix "frame:preprocess(text)" to avoid full expansion of everything in parent frames as much as possible (wikicode parsing and expansion should only be made lazily for only what was demended)
  • investigate the other bugs (related to Wikidata client retrieveing only full objects instead of just the selected properties)
  • other bugs related to exceptions for memory exhaustion in PHP->Lua->PHP is independant but still needs a better fix than what is currently worked on (which is a real hack if it just consist in increasing or relaxing the memory constraints, and will not solve any problem if the exception is handled correctly but it still causes unexpected HTTP 500 failures on the server in other modules not expecting the new exception or if it causes them to return a dummy expanded error text instead)

Now, the page language come from frame:preprocess("{{PAGELANGUAGE}}").
For the same reasons as the user language, the page language could use the new way to give it to Scribunto modules.

Verdy_p added a comment.EditedSep 16 2017, 1:36 PM

PAGELANGUAGE is NOT the correct one. It was the user language that was expected (we won't have per-language categories, category pages won't be translated, the navbox was intended to provide coherent international navigation independantly of the English name of the categories, and without having to create and edit many translations within the page itself (this is about tens of thousands of categories). This PAGELANGUAGE would be a severe return backward where only English will be displayed on Commons.

frame:preprocess( "{{int:Lang}}" ) is far better than frame:preprocess( "{{PAGELANGUAGE}}" ) which is really different. We are still needing a simpler way in Lua to get the user language directly within a variable from the PHP environment (i.e. available as a string property in mw or frame, without needing any additional preprocessing for its expansion).

In summary do not confuse the three distinct languages:

  • default language of the wiki (English only in Commons or Meta or "old Wikisource", or the language of the project wiki when it has separate linguistic editions, such as French for French Wikipedia)
  • page language (only works for pages using the translate extension, or pages that would use some magic keyword to design to indicate in which language a monolingual page is effectively written, or some wiki specific hook parsing some pagename or namespace convention, notably for beta wikis like Incubator, or like OpenStreetMap wiki). Useful for multilingual wikis that still have language-specific pages (possibly translated, but this is not always the case and their language is NOT necessarily the same as the default wiki language; translated pages can come later using some wiki-specific naming convention that "page language" would detect with some hooks, such as the hook used by the "Translate" extension, which expects languages codes to be found as the last subpage name). If a page is not detected by the special hook as being marked/tagged/named to be in a specific language, the page language will be assumed to be the default language of the wiki (not necessarily English as said above). For example an "English Embassy" community page on the French Wikipedia could be marked/tagged as having "page language = en" even if the default language of the wiki is French. The page language also will afftect how the layout will be generated (notably there will be CSS classes or styles for RTL languages, and cells of tables will render in different order, and paragraphs will be aligned on a different margin, thumb images will float by default on another side... The "English Embassy" page on the Arabic Wikipedia would have a radically different layout than most ofther pages of the Arabic wiki; the "side bars" on the opposite will have a layout based on the user language, but will not be affected by the page language or the wiki default language)
  • user prefered language (at set by the Universal Language selector, or in user preferences or when using "uselang=code" in query strings (part of the URL), to be used typically in navboxes transcluded in pages (such as categories) that will never be translated directly. It is the same language used by the Mediawiki UI (translations come from the "int:" parser function that uses translations imported into the special namespace from translatewiki.net or added locally by local wiki admins). This is always independant of the two previous languages, any user can set its own language preference or view any page with "uselang=code" parameter in the query string. This means that the same page will render differently depending on language, and MediaWiki already has separate caches for pages rendered with different user language (each version is cached inpendantly, the lifetime of these server-side caches are also independant: you can "purge" the version in English this does not purge the French version, and caches will expire or will be cleaned also independantly of any explicit purge action, if storage space gets exhausted, by using a LRU algorithm where the oldest retreived pages from the cache will be purged first to make space)
Rical added a comment.Sep 16 2017, 2:05 PM

Many thanks for this overview of languages.
For 2 days, I made the function form2en() dedicated to tests many functions, always in english, to increase the stability of central modules, using ClassNameTests.

Kghbln added a subscriber: Kghbln.Jun 19 2018, 8:07 PM

There is the MyVariables extension around which provides the {{USERLANGUAGECODE}} variable. This is only available for third party instances though.

Kghbln updated the task description. (Show Details)Jun 20 2018, 7:21 AM
Kghbln updated the task description. (Show Details)

Why did you cross nikext? It's still available, the vcs link just needs updating.

Nikerabbit updated the task description. (Show Details)Jun 20 2018, 7:25 AM

Why did you cross nikext? It's still available, the vcs link just needs updating.

Sorry, I did not find it so I assumed it is gone. You are welcome to do the honors.

Dvorapa added a subscriber: Dvorapa.May 6 2019, 7:18 AM
Restricted Application added a subscriber: Liuxinyu970226. · View Herald TranscriptMay 6 2019, 7:18 AM

Change 508295 had a related patch set uploaded (by Dvorapa; owner: Dvorapa):
[mediawiki/core@master] Add a new {{USERLANGUAGE}} variable for use in wikitext

https://gerrit.wikimedia.org/r/508295

Change 507328 had a related patch set uploaded (by Dvorapa; owner: Want):
[mediawiki/core@master] Add system message MediaWiki:Langcode

https://gerrit.wikimedia.org/r/507328

Verdy_p added a comment.EditedMay 6 2019, 2:08 PM

An we still lack the possibility of marking a specific page (with a margic syntax generating metadata, not content, like "[[Category:...]]") as being primarily in a specific language (independant of the user language, but that should NOT be inserted in pages marked for translations with the translation tools, which are marked automatically by the Translation tool and uses a specific page naming convention using "/langcode" suffixes/subpages, or some "langcode:" prefix or namespace, like on the OpenStreemap wiki).

This magic metadata keyword to insert in the wikicode of pages (or in transcluded templates), such as:

  • {{PAGELANGUAGE:langcode}} or
  • [[PAGELANGUAGE:langcode]] (like categories), or
  • <meta name="lang" value="langcode"/> (using a generic metadata system for pages, not limited to languages)

should be natively implemented. It should also properly set the HTML metadata in the page header and/or in the MIME headers of HTTP query replies.

And the page language metadata would be overriden by a wiki-specific hook if there's a naming convention enforced by the translation tool: this hook would then detect the presence of the keyword in the wikipage content, and any difference would generate a warning (at least on the preview) and mark the parsed page with a tracking maintenance category, if language code set by the magic keyword is different from the language code set by the translation tool or enforced naming convention; so that we can either:

  • remove the magic keyword from the page content (or its transcluded templates) so that the wiki-specific hook or translation extension will set the expected language itself; or
  • keep this magic keyword, but move the page to use a different full pagename (with the correct language code or none) so that the wiki-specific hook or translation extension will not imply a different language.

The need of this keyword is for all other cases where a translation tool is not applicable (e.g. talk pages like "embassies", or because the page is not intended to be itself translated, or because its content is generated by templates using the user's prefered language only and is then completely "autotranslated", with the page possibly embedding a custom "View this page in..." language chooser to render it in one of the supported languages, independantly of the universal language selector which autoselects the prefered user's language throughout his navigation on the wiki, this custom language chooser also setting the correct HTML or HTTP headers in the current session, but not changing the user's prefered language for his navigation on the wiki site)

There is Special:PageLanguage. Anything on the page itself doesn't work, as the language needs to be known to parse the page, so it would be chicken and egg situation.

Verdy_p added a comment.EditedMay 6 2019, 2:58 PM

I'm not convinced this is needed to parse the page, only to generate its content. But is this related to conditional code like #if and #switch and with transclusion of Lua generated contents (that would then need to generate all lingusitic versions until a laguage filter is applied at end to purge the excluded section) ?

Anyway, there's still no evident way in the UI to mark a page with this special page (which is also too much restricted). Marking an individual page to use a specific language should be as open to anyone as being able to create or rename/move a page with a correct title in that language.

So the menu at top of pages that allows renaming a page should also include the option to change its language (this change should be also visible in the history and can be reverted by reviewers if needed)

An alternative is to integrate the language setting of a page in the same dialog for renaming/moving a page. And in the page editing dialog notably when creating one (insert that option just above the comment line before the submit button). In the same place we could also have other selectors for setting other page metadata (that may be needed for some wiki extensions, e.g. pages that contain input forms or that run some scripts, or for setting specific CSS stylesheets applicable to the page).

Kghbln updated the task description. (Show Details)May 8 2019, 2:17 PM
Kghbln updated the task description. (Show Details)May 8 2019, 2:20 PM

Change 507328 abandoned by Krinkle:
Add system message MediaWiki:Langcode

Reason:
This is not a stable implementation for the software and will be hard to maintain and verify over time. Also something about appropriate fallback for new languages and insurance that this exists for every recognised language (including those without translations), which would require a structure test at the very least.

I don't think we can improve this approach to a version that is acceptable, as such closing in favour of <https://gerrit.wikimedia.org/r/#/c/mediawiki/core/ /508295/> - which, if this is a feature we can support, offers a more maintainable implementation.

https://gerrit.wikimedia.org/r/507328

Krinkle renamed this task from Add a {{USERLANGUAGE}}/{{USERLANG}} magic word to Add a {{USERLANGUAGE}} magic word.May 9 2019, 4:07 PM
Krinkle changed the task status from Open to Stalled.May 9 2019, 4:09 PM
Krinkle edited projects, added Performance-Team (Radar); removed Performance Issue.
Krinkle removed a subscriber: wikibugs-l-list.
Krinkle added a subscriber: Krinkle.

Marking as stalled as this feature request should first be reviewed and approved by the Parsing Team and evaluated in terms of cost, complexity, maintenance, compatibility, roadmap etc.

Once approved, please ping Performance Team so we can take a look at the implementation before it goes live.

Krinkle moved this task from Limbo to Watching on the Performance-Team (Radar) board.

Change 507328 abandoned by Krinkle:

Just an afterthought, that maybe the combination of both possibilities could be beneficial as Urbanecm suggested in the abandoned change. Generate the message Want suggested for all languages by (translate? separate?) extension could be a second approach alternative to the magic word. Anyway this is a thing for performance and parsoid teams to decide

Kaganer added a comment.EditedNov 5 2019, 1:13 PM

Please note: I'm seen https://www.mediawiki.org/wiki/Extension:LanguageCode that a realize two magic Words:

  • {{USERLANGUAGE}} - for a display the user language
  • {{PAGELANGUAGE}} - for a display the page language

I have not reviewed the source code, but maybe this is a solution for this issue.

By way, {{PAGELANGUAGE}} is also a very needed feature! See T59603 and T161976 about this issue.

It's listed in the description :) The issue is not having code that implements this, the issue is whether this feature is suitable (now and in the future) for MediaWiki core and/or deployment to Wikimedia sites.

Kghbln awarded a token.Nov 5 2019, 2:07 PM

Of cource ;) This is notice only. And also this is marker, that this issue still important and very needed.

Rical updated the task description. (Show Details)Mar 20 2020, 7:49 AM
Verdy_p added a comment.EditedMar 20 2020, 8:38 AM

There should not be any need to call the wiki parser from Lua just to get an information which is built in the Wikimedia API (in PHP) itself. The best way would be to expose this value directly in the environment offered by Scribunto.

Now for the access from wikipages, it should also not be ncessary to call a Lua module. But using the template expansion of "{{int:Lang}}" [which works if there are resources loaded in pages of a special namespace intended for storing translated texts, but that is non sense here as this is NOT translatable and it is just returning a rewriting of the page name that does not need to be stored as a page and its content should not be modifiable at all] should be deprecated.

However, there's not necessarily a need for a new magic keyword, if the "int:" parser function hook implements it internally instead of performing a template expansion from loaded pages. Here the parseer function hook implementing the "'int:" special namespace is written in PHP and can instantly use the Mediawiki API (in PHP) which exposes a PHP variable (which should have been "cleaned", i.e. should return already a canonicalized and validated code, that should then map to a supported code, even if the user is querying a page with an invalid value for the "?uselang=*" parameter; that varaible should also already canonicalize some known aliased codes, such as "zh-min-nan" to "nan", or "fra" and "fre" to "fr", using BCP47 rules, or "EN" to "en"; invalid codes specified in query parameters may be replaced by another "guessed" language, from the browser's "prefered language" environment, or at least the default language code of the wiki).

The whole code for getting and validating the user language (from HTTP query parameters, otherwise from user's preferences, otherwise from the browser's environment in the "AcceptLanguage:" MIME header, which also specifies a list of user-prefered fallbacks that coulmd be exposed as well as a separate variable containing an ordered array of validated codes) is part of Mediawiki core. It is at the root even before parsing any page (and there's not always a wiki page to parse when the user requests a page in the "Special:" namespace, which is implemented by Mediawiki hooks that won't parse any wiki code from any actually stored page; this is also true when rendering pages from the "api.php" endpoint). Then only, the wiki code of wiki pages is parsed and expanded (and later cached by this validated user language). The core will recompose the final page containing the cached parsed page and the rest of the UI. In all cases, the Mediawiki parser and the Lua parsers are only plugins loaded from the Mediawiki internal environemnt where all is ready:

It's up to the MediaWiki API to expose this variable (or varaibles, it it exposes not just the prefered user language, but also his own prefered fallbacks, which could also be stored in user preferences, as an ordered array of language codes that will however need to be revalidated by the core when it will load the user's preferences from the database if the user is logged in; the user preferences, users may not even need to set these preferences which should by default use the browser's settings exposed in the standard "AcceptLanguages:" header of HTTP but with an order specified by "q=*" numeric values qualifiers rather than just an ordered list; we don't need these values, just an ordered list of validated codes usable for the Mediawiki UI). So expose the main prefered language in the PHP implementation of the "int:" special namespace, and in Scribunto, and all is done! No need to load extra pages in wikis, and no longer any need for users to configure the prefered language for each wiki, as the Mediawiki UI by default will honor the browser's settings (in fact users may also want to REMOVE this language setting from their stored preferences, with the option "user language preferences of the current browser", or "application" if he's using a detected Mediawiki mobile app).

And there will be no need for admins to manage special pages on each wiki. users will still be able to use another language using the universal Language Selector (ULS), temporarily, or persistantly on a specific wiki if they wish to do so and are logged in. Users without accounts are not required to create an account to view and navigate anywhere on a wiki in their prefered language, using simply the language settings of their browser or app, and the server will never need to store anything (except in server logs whose access is highly restricted for privacy reasons) for non-logged in user.

For this reason, I think that exposing wgUserLanguage of PHP (or a subvariable in the MediaWiki environment) is the solution to go: simplest, fastest, most efficient (no need to cross multiple language parser barriers: PHP is already at the root of everything in Mediawiki, for the Scribunto extension and for the "int:" namespace hook if it implements "int:Lang" internally without loading any page from the database with an unnecessarily complex mechanism of fallbacks that should not be needed at all if the exposed variable is already canonicalized).

cscott added a subscriber: cscott.Mar 20 2020, 3:00 PM

In general we would like to separate "page content" (in the "page content language") from user interface (in the "user interface language"). Currently much of that user interface is expressed in wikitext on sites like commons, but we'd like to reduce that over time. As mentioned before, wikitext in the user interface language complicates caching.

As a separate note, I'd like to encourage any new parser functions/magic words to use the {{#....}} syntax, as described in T204370: Behavior switch/magic word uniformity.

Krinkle removed a subscriber: bzimport.
Rical updated the task description. (Show Details)Mar 25 2020, 11:05 AM

"As mentioned before, wikitext in the user interface language complicates caching."

But this is not new and this task won't change it! Caching is already performed by user language (if there's any use of it in the content, including when using the "{{int:*}}" syntax or using any parser function that requires it, or in most special pages when their content is cachable).

Caching is also controled by an expiration date that already depends as well on the use of current date functions and magic keyword (depending on their precision: "{{CURRENTYEAR}}" will limit the expiration date to the end of the year, "{{CURRENTDAY}}" will limit it to the end of the day ; "{{CURRENTMINUTE}}" would limit it to the end of the current minute, but caches also define a minimum caching period, probably set to a few minutes, to avoid too fast refreshes which could be costly for rendering servers, but whose exact duration will depend on the administrative settings of each wiki).