Jump to content

Topic on Project:Support desk

Why brackets ([]) are flipped (][) in an RTL website?

13
49.230.87.239 (talkcontribs)

I have an RTL (Hebrew) 1.34.0, principally all-core MediaWiki website with the following Template:Cite:

<includeonly>{{#if:{{{refname|}}}
| {{#tag:ref|{{{content|}}}|name={{{refname}}}}}
| {{#tag:ref|{{{content|}}}}}
}}</includeonly>

It works fine both for unnamed calls and named calls (calls that don't have an HTML name attribute, or, calls that do have it) and it also works well for calls by name.


And yet I have the problem that brackets ([]) appear flipped (][);

Output examples:

בדיקה:Cite with parameter calls WITHOUT English naming

First check]1[ Second check]2[ Third check]3[

  1. ^ First check
  2. ^ Second check
  3. ^ Third check

בדיקה:Cite with parameter calls WITH English naming

First check]1[ Second check]2[ Third check]2[

  1. ^ First check
  2. ^ לקפוץ מעלה אל:2.0 2.1 Second check


This front-end problem persists even with the radical JavaScript executed in browser console:

document.querySelectorAll("*").forEach(
    (element)=>{
        element.setAttribute('dir', 'ltr')
    }
)

Why brackets ([]) are flipped (][) in an RTL website?

Malyacko (talkcontribs)
Bawolff (talkcontribs)

you dont include any examples of input here. For template questions, we need to know the template, its input, and the corresponding output.

Most likely answer is the input has brackets flipped, perhsps accidentally, due to bidi.

49.230.87.239 (talkcontribs)

@Malyacko The term "brackets" isn't mentioned in the linked article; there are brackets there, yes, but they are brought in a specific code example and not about any specific problem with brackets.

My browser is latest Chrome: Version 83.0.4103.61 (Official Build) (64-bit)

49.230.87.239 (talkcontribs)

Per Bawolff's comment, this is the input:

Cite with parameter calls without English naming

First check{{Cite|content=First check}}
Second check{{Cite|content=Second check}}
Third check{{Cite|content=Third check}}

<references />

Cite with parameter calls with English naming

First check{{Cite|content=First check}}
Second check{{Cite|content=Second check|refname=First_name}}
Third check {{Cite|refname=First_name}}

<references />

As can be read; there are no brackets in the input at all; the flipping is not from input.

49.230.87.239 (talkcontribs)

@Amire80

In all your years as a bidi developer (if that's an accurate term to describe your work at Wikimedia foundation) you might came across this "RTL-English" problem and perhaps could suffice an insight.

49.230.87.239 (talkcontribs)
Bawolff (talkcontribs)

Works totoally fine for me: https://he.wikipedia.org/wiki/%D7%9E%D7%A9%D7%AA%D7%9E%D7%A9:Bawolff/sandbox (I also tested on my own computer with a fresh version of MediaWiki, to make sure that hebrew wikipedia did not have any customizations). Only issue is the [3] is slightly in wrong place (Which could be solved by ending with a &lrm; or putting the whole thing in a <div dir="auto">...</div>.

So it seems very likely this issue is due to some customization you made to your wiki.

49.230.87.239 (talkcontribs)

@Bawolff I think I was confused myself but I still encounter a similar problem even in the test page you created in Hebrew Wikipedia

משתמש:Bawolff/sandbox


In RTL-English state I do get [] but in LTR-English state (which I get with the following JS) I get ][:

document.querySelectorAll("*").forEach(
    (element)=>{
        element.setAttribute('dir', 'ltr')
    }
)


In other words; I can have an RTL-English state just fine but I can't have LTR-English state for English pages just fine.

Bawolff (talkcontribs)

I don't think that's a good way to set LTR mode. It would probably be better to just enable $wgPageLanguageUseDB and use Special:PageLanguage to set a specific page to english, or just wrap the whole page in <div dir="ltr">...content here</div> (or maybe dir=auto).

That said, your JS snippet does not cause the behaviour you describe when i tested it.

49.230.87.239 (talkcontribs)

@Bawolff

  • If I understood the first solution correctly than personally wouldn't want to create an array at LocalSettings.php in which I will manually refer to every webpage which is primarily in English
  • Wrapping everything inside a <div> with dir=ltr actually solved the problem but it doesn't flip the heading, let along, generally all other ("boilerplate") structures of the webpage as a whole.


I tested the JS snippet several times and I just double checked it in משתמש:Bawolff/sandbox and I still got the same behavior; it might do with Operating system or configuration. I agree it's not a good way to go; I just wanted to describe this wired behavior here in the posts to perhaps get an insight on why it happened (I guess it might do with operating system as well as browsers).


Anyway, for me personally this is no longer a problem; my main problem was and is creating a template working for Hebrew and I have created a hopefully last post about it:

How to translate this Cite template to Hebrew?

Bawolff (talkcontribs)

> If I understood the first solution correctly than personally wouldn't want to create an array at LocalSettings.php in which I will manually refer to every webpage which is primarily in English

No, you can just set $wgPageLanguageUseDB = true; and then You can visit the page Special:PageLanguage to adjust the language of individual pages. You don't have to list each page individually in LocalSettings.php

> Wrapping everything inside a <div> with dir=ltr actually solved the problem but it doesn't flip the heading, let along, generally all other ("boilerplate") structures of the webpage as a whole.

Yes that true. I think lots of people do use JS when they want that. You can also add ?uselang=en (or &uselang=en depending on the url) to force the interface into english (e.g. ), or set that in Special:Preferences. However that does a bit more than just changing the directionality of the interface

49.230.87.239 (talkcontribs)

I thank you for this detailing @Bawolff

Reply to "Why brackets ([]) are flipped (][) in an RTL website?"