Page MenuHomePhabricator

Implement Lua alternative to {{int:Lang}} / wgUserLanguage
Open, HighPublic

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 (if the wiki has created the messages needed to support this feature).

Central modules can help users and helpers, in their own languages and the wiki languages, using errors, warnings, categories, reports and tests.

Example: display a category in the helper language and link to the category in wiki language.

A module could find the user language from mw.uri.new().userLanguage

See in examples and the draft proposition of Central modules.

Details

Reference
bz66051

Event Timeline

bzimport raised the priority of this task from to Lowest.Nov 22 2014, 3:25 AM
bzimport set Reference to bz66051.
bzimport added a subscriber: Unknown Object (MLST).
Rical created this task.Jun 2 2014, 9:30 PM
Anomie added a comment.Jun 2 2014, 9:48 PM

The user language is not likely to be available in Scribunto, as it would cause cache fragmentation issues.

Rical added a comment.Jun 2 2014, 11:01 PM

The ask is only to read the user language code by a value or a function getUserLanguageCode() which return "en" or "fr"... Then the module can choose the right table in its own i18n tables. Then the module can display its messages in the best language for the user or the admin who maintains the page or the module.

Anomie added a comment.Jun 3 2014, 4:18 PM

Bottom line: this isn't going to happen unless the feature requested in bug 2085 gets implemented, for all the reasons that feature hasn't been implemented yet.

Rical added a subscriber: Rical.Dec 12 2014, 8:03 PM
Rical renamed this task from Get and use the user language to help to maintain a module or a template to Get the user language to help admins to maintain a module or a template.Jul 12 2015, 9:05 AM
Rical set Security to None.
Rical updated the task description. (Show Details)Dec 1 2015, 5:30 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptDec 1 2015, 5:30 PM
Rical renamed this task from Get the user language to help admins to maintain a module or a template to Give at modules the user language to display errors and categories names for him.Apr 26 2016, 7:16 AM
Rical updated the task description. (Show Details)
Rical renamed this task from Give at modules the user language to display errors and categories names for him to Central modules need the user language to display errors and categories names for him.May 23 2016, 2:53 PM
Rical updated the task description. (Show Details)
Multichill raised the priority of this task from Lowest to High.Feb 18 2017, 2:50 PM

Bumping this one to high as T158470 got closed with a comment that it should happen here.

On https://www.mediawiki.org/wiki/Extension:Wikibase_Client/Lua the user language is already offered, but always in combination with something else.
Currently things like "args.lang = frame:callParserFunction( "int", "lang" ) -- get user's chosen language" are being used to achieve this result.

IMO, it was a bad idea for {{int:}} to ever work on user language instead of on content/page/site language. I don't think we should extend that mistake.

Rical added a comment.EditedFeb 19 2017, 5:39 PM

For 2 months I use translate.init_wiki_user_page_lang() for your ask of 3 languages.
For this, central modules need T68051 and T142906.
I have also a marginal task to create:
T20170211 : in mw.language.fetchLanguageNames( 'fr' ) some languages names are not in French.
Search "versioning_tasks_report()" in Central-s-fr.

IMO, it was a bad idea for {{int:}} to ever work on user language instead of on content/page/site language. I don't think we should extend that mistake.

What you're saying is that we should only display Wikimedia Commons in English. Judging from your English Wikipedia user page you're a monolingual speaker of English. So you probably don't need it, but we have many other users for which we would like to display the interface in another language.

What you're saying is that we should only display Wikimedia Commons in English.

No. I just meant that a parser function is too early in the parse for internationalization to happen. I think it should happen later in the parse, like the language converter does.

Nemo_bis renamed this task from Central modules need the user language to display errors and categories names for him to Central modules need the user language to display errors and category names.Feb 27 2017, 9:44 AM
Rical added a comment.Apr 7 2017, 5:11 PM

We could have mw.language.getUserLanguage() with getContentLanguage() and getPageLanguage() to complete languages needs of any modules. See T161976

Lydia_Pintscher moved this task from incoming to monitoring on the Wikidata board.May 5 2017, 3:07 PM
Anomie renamed this task from Central modules need the user language to display errors and category names to Implement Lua alternative to {{int:Lang}} / wgUserLanguage.May 6 2019, 1:34 PM
Anomie added subscribers: Ricordisamoa, daniel.
Krinkle changed the status of subtask T4085: Add a {{USERLANGUAGE}} magic word from Open to Stalled.May 9 2019, 4:11 PM
Dvorapa added a subscriber: Dvorapa.May 9 2019, 4:34 PM

Is there any progress in this task?

IKhitron added a subscriber: IKhitron.
Rical updated the task description. (Show Details)Mar 25 2020, 11:03 AM
Anomie updated the task description. (Show Details)Mar 25 2020, 2:53 PM

At the moment most modules on Commons use frame:callParserFunction("int","lang") call to get users language. It is a solution that works fine on multilingual projects like Commons and Wikidata, but I am not sure if it is accessible on other projects. I assume that the purpose of this task to come up a way which is guaranteed to work on the projects.

frame:callParserFunction("int","lang") is the same as {{int:Lang}}. It is just a workaround, created by admins on projects which need this functionality. On other projects where admins did not create int:Lang message map none of these workarounds work.

Multichill updated the task description. (Show Details)Mar 25 2020, 8:20 PM

Can we just use _, lang = mw.wikibase.getLabelWithLang( 'Q1' ) ? That line seems to always return the language of the viewer. I do not know if Q1 has a label for all supported languages, but if not than we can add some.

Can we just use _, lang = mw.wikibase.getLabelWithLang( 'Q1' ) ? That line seems to always return the language of the viewer. I do not know if Q1 has a label for all supported languages, but if not than we can add some.

I like this workaround! Good idea. This doesn't solve anything for wikis outside WMF wikis, but can solve much trouble with maintaining those int:Lang pages by admins on WMF wikis.

Dvorapa added a subscriber: Want.Apr 20 2020, 8:21 AM

I checked and _, lang = mw.wikibase.getLabelWithLang( 'Q2' ) is a better approach, since Q2 had labels in 287 langiuages and Q1 "only" in 189. So is this an acceptable way to look up language of the user? Every template on Commons calls {{int:Lang}}, often many times per page. If we switch from lang=frame:callParserFunction("int","lang") to _, lang = mw.wikibase.getLabelWithLang( 'Q2' ) than suddenly 50M pages will be querying Q2's label. Maybe there is a better way.

Dvorapa added a comment.EditedApr 23 2020, 9:11 PM

suddenly 50M pages will be querying Q2's label

Yes, but only during saving an edit, so this should be ok from my perspective. I just still have doubts about whether this will work correctly.

suddenly 50M pages will be querying Q2's label

Yes, but only during saving an edit, so this should be ok from my perspective. I just still have doubts about whether this will work correctly.

During parsing a page. Which can be every other page view. Also, this will create 50M "links" to the item in the database of Commons, so a potential performance problem.

If this way of getting the language works for you, then perhaps it could be moved to a new function to work independently of Wikidata...

If this way of getting the language works for you, then ...

@matej_suchanek This approach seems to work in limited test I was able to perform. Q2 has labels for 287 languages and I believe MediaWiki supports over 450, so this approach would not work for users of 160 languages, but there again those are probably the languages we do not have any content in anyway. Function mw.wikibase.getLabelWithLang does on document what the language output is. By observation it seem to be the language of the viewer, but it is unclear how many languages can be returned. Mw.language library recognizes language codes which are ValidBuiltIn, Known, or supported, It would be nice to know which set the outputs of this function fall into.

perhaps it could be moved to a new function to work independently of Wikidata...

A new function to work independently of Wikidata would be great. Perhaps mw.language.getUserLanguage() (aka mw.getUserLanguage()) to get "language object" with getCode() property to get the actual language code.

Also, this will create 50M "links" to the item in the database of Commons, so a potential performance problem.

Yes, we would like to avoid that. Once Commons SQL database have 50M links, they do not seem to ever go away. As I reported in T243602, we still have 13M links to some modules and templates which are not being used for over a year.

Function mw.wikibase.getLabelWithLang does on document what the language output is.

It says

Like mw.wikibase.getLabel, but has the language the returned label is in as an additional second return parameter.

which leads to

The label will either be in the Wiki's language (on monolingual wikis) or the user's language (on multilingual Wikis), furthermore language fallbacks will be applied

(yet another overhead)

@matej_suchanek Sorry for nit-picking but that second sentence is in documentation of mw.wikibase.getLabel function, and I did not noticed it when I was reading documentation of mw.wikibase.getLabelWithLang. There is a link to the other function, so it should not have been hard to find.

So if mw.wikibase.getLabelWithLang function returns " Wiki's language (on monolingual wikis) or the user's language (on multilingual Wikis)", we would have to decide on behavior of our hypothetical new mw.language.getUserLanguage() function on monolingual wikis. I do not have strong opinions one way or the other. In one hand If I am looking at a page in some wiki, where I do not know the language, it is nice if some parts show up in languages I know, but on the other hand other wiki's templates might not be handling such cases correctly.

Jarekt added a comment.May 4 2020, 3:43 AM

There is an API to get languages users speak: https://commons.wikimedia.org//w/api.php?action=query&meta=babel&babuser=Jarekt. Maybe it would be possible to get babel preferences of the current user.