meta=siteinfo&prop=langlinks should indicate whether a language is RTL
Open, LowPublic

Description

https://en.m.wikipedia.org/w/api.php?action=query&format=jsonfm&meta=siteinfo&siprop=general%7Clanguages&prop=langlinks&llurl=true&lllimit=max&titles=Tofu

This returns language names and article titles in many languages (which is used to construct a language switcher interface on the mobile web interface). To do that properly, mobile we need to identify which languages are RTL and which are not.

Expected: Return an rtl property when a language is RTL.

Details

Reference
bz72153
bzimport raised the priority of this task from to Needs Triage.
bzimport set Reference to bz72153.
bzimport added a subscriber: Unknown Object (MLST).

At a glance, it seems this would require fetching a Language object for every single language. That may be prohibitive from a performance perspective.

Pulling in some i18n experts.

Even if we can skip that part (as with Language::getFallbacksFor()), it would still require loading language info for every language which has the same concerns.

I said on IRC that many people use jquery.uls.data for getting the direction of a language. I do not know if that is possible for you.

I don't understand the bug summary.
https://he.wikipedia.org/w/api.php?action=query&meta=siteinfo&siprop=general
lang="he" rtl=""
WORKSFORME

He is asking for rtl="" for all supported languages, not for the content language (where the flag exists).

https://he.wikipedia.org/w/api.php?action=query&meta=siteinfo&siprop=languages

For what the dir is needed in this context?

Another solutation maybe where to add the dir (rtl or ltr) to each language link from the prop=langlinks, than there is no need to fetch all languages and just use the one which are needed.

By the way:
For performance you can actually change meta=siteinfo&siprop=languages by llprop=autonym

The goal is to render a list of all available languages and align them right to left or left to right depending on the language script.

Aklapper triaged this task as Low priority.Mar 23 2015, 8:56 PM
Amire80 moved this task from Backlog to MediaWiki-core on the RTL board.Jul 16 2015, 6:29 PM

This proposal is selected for the Developer-Wishlist voting round and will be added to a MediaWiki page very soon. To the subscribers, or proposer of this task: please help modify the task description: add a brief summary (10-12 lines) of the problem that this proposal raises, topics discussed in the comments, and a proposed solution (if there is any yet). Remember to add a header with a title "Description," to your content. Please do so before February 5th, 12:00 pm UTC.

Tgr updated the task description. (Show Details)Feb 5 2017, 7:54 AM
Krinkle renamed this task from meta=siteinfo should allow client to identify RTL languages to meta=siteinfo&prop=langlinks should indicate whether a language is RTL.Feb 6 2017, 7:36 PM
Krinkle removed a subscriber: wikibugs-l-list.
Krinkle added a subscriber: Krinkle.Feb 6 2017, 7:41 PM

Note that meta=siteinfo already exposes a siteinfo.rtl property on sites that have an RTL content language. I've updated the summary to specify that this task is specifically about the langlist, not the main siteinfo itself.

As for the actual task, I'm not entirely sure that this is the most adequate solution to the problem at hand. It is not the responsibility of this data module to know whether a language is RTL or not. If we add this we could be opening the way to add lots of unrelated information to API modules that consumers may need at the same time.

However from what I can tell, distinguishing an RTL language is a much more common need in general. A simple isRTL() method on mw.language (client-side) and Language.php (server-side) might solve this need in a more maintainable way that also more re-usable and performant.

In the Intuition tool I solved this by providing a cached index of known RTL language-codes (which is a fairly short list), and the checks do a cheap in_array/indexOf lookup.

Anomie added a comment.Feb 6 2017, 9:45 PM

@Krinkle changed the title from "meta=siteinfo should allow client to identify RTL languages" to "meta=siteinfo&prop=langlinks should indicate whether a language is RTL".

This title makes little sense. meta=siteinfo and prop=langlinks are two completely separate modules. I believe the intention of the original request was that meta=siteinfo&siprop=languages should indicate directionality, which would then be cross-referenced with the language of each link output by prop=langlinks.