hnaseri
(Hosein Naseri)
9 Febbraio 2022, 10:15am
1
Ho un forum in lingua RTL. Recentemente le citazioni mostrano il testo in direzione LTR invece che RTL.
pmusaraj
(Penar Musaraj)
9 Febbraio 2022, 11:32am
2
Sei sull’ultima versione di Discourse? Non riesco a riprodurlo localmente quando imposto la mia lingua sull’arabo, ad esempio.
hnaseri
(Hosein Naseri)
9 Febbraio 2022, 1:40pm
3
Mi sono aggiornato all’ultima versione proprio ora. Non ha risolto il problema.
pmusaraj
(Penar Musaraj)
9 Febbraio 2022, 3:41pm
4
Succede su più post o solo su quello specifico? Hai provato anche in modalità provvisoria?
1 Mi Piace
hnaseri
(Hosein Naseri)
10 Febbraio 2022, 6:44am
5
Sì, succede in più post. E succede anche in modalità provvisoria.
1 Mi Piace
pmusaraj
(Penar Musaraj)
10 Febbraio 2022, 7:58am
6
Puoi pubblicare un link al tuo sito in modo che possiamo dare un’occhiata?
pmusaraj
(Penar Musaraj)
10 Febbraio 2022, 9:40am
8
Grazie, a giudicare dal codice sorgente, le virgolette lì hanno un attributo dir="ltr". Suppongo che tu abbia abilitato l’impostazione mixed text direction. Infatti, posso riprodurre il tuo problema quando abilito quell’impostazione localmente.
Non sono sicuro se questo sia “funzionante come previsto” o se si tratti di un bug piccolo/grande qui. @Osama hai familiarità con questa parte dell’app?
3 Mi Piace
Osama
10 Febbraio 2022, 9:48am
9
Sembra proprio che ci sia un bug qui. Mi aspetterei che la direzione della citazione corrisponda alla direzione del sito. Approfondirò per scoprire cosa sta causando questo!
4 Mi Piace
Osama
20 Febbraio 2022, 8:07pm
11
Dopo aver esaminato la questione, sono un po’ confuso, sei sicuro che questo venisse visualizzato correttamente in passato? Perché non ho visto nulla nel codice per gestire il testo citato RTL con un nome utente in una lingua LTR. Ho anche provato una versione di Discourse di oltre un anno fa e la citazione non veniva visualizzata correttamente neanche allora.
Ad ogni modo, ecco una PR per gestire correttamente questo problema:
main ← fix/quoted-rtl-text
opened 08:02PM - 20 Feb 22 UTC
Meta topic: https://meta.discourse.org/t/rtl-direction-is-broken-in-quotes/21763… 9?u=osama.
Posts in Discourse are by default always rendered in the same direction as the rest of site, for example if the site is RTL, a post in that site is always rendered RTL even if it's made of an LTR language entirely. However, this behavior can be changed by enabling the `support mixed text direction` site setting which makes our posts rendering engine consider each "paragraph" in the post and apply an appropriate direction (using the `dir` attribute) on it based on its content/language.
I put paragraph in quotes because technically we only loop through the immediate children of the HTML element that contains the post cooked HTML and do this direction check on them. Most of the time the immediate children are actually paragraphs, but not always. The direction of an element is determined by checking its `textContent` property against a regular expression that checks all characters are RTL characters and based on the regular expression result the `dir` attribute is set on the element.
This technique doesn't work so well on quotes because they may contain multiple paragraphs which may be in different languages/directions. For example:

In this screenshot, the site's language is Arabic (RTL language) and the `support mixed text direction` setting is enabled. The paragraphs outside the quotes are rendered as expected with the right direction, however the paragraphs within the quote aren't; both the Arabic and English paragraphs are rendered LTR. Additionally, the avatar in the quote is misplaced; it should always be on the right hand site in RTL sites.
The reason for this is that when we're determining the direction for the quote, it's considered as one element and the direction is set on the whole quote. But for complex quotes like the one above, we need to be more surgical and apply direction on elements within the quote.
This PR adds special handling for quotes to ensure that:
* the quote title (the avatar plus the chevron and arrow) always match the site direction
* each immediate paragraph (`<p>` elements) under `<blockquote>` in the quote gets a direction based on its content.
Screenshot of the above quote with this PR:

5 Mi Piace
pmusaraj
(Penar Musaraj)
Chiuso
28 Febbraio 2022, 7:00am
12
Questo argomento è stato chiuso automaticamente dopo 3 giorni. Non sono più consentite nuove risposte.