globalizejs / globalizejs/globalize

Message formatting dependant on base text direction (Bidi support)

Open
#539 28 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
4.8k
Forks
585
PR merge metrics
No merged PRs in 30d

Description

Issue of message formatting constitutes quite a challenge from Bidi perspective.
The primary consideration is, in which text direction message is supposed to be displayed.(in DOM model, the HTML element text direction is controlled either by 'dir' attribute or by 'direction' css style)

For detailed explanation of what base text direction term means please see, for instance, pages 5-9 of the following reference document.
https://docs.google.com/document/d/1dDrSwimrQbpbXybhMYDEiJXLeeqvelnY4cc8HeCP1Nk/edit?usp=sharing
1. Let us consider for illustration the parametrized message:
Globalize.loadMessages({he: {
error: "THE FILE {0} HASN'T BEEN FOUND",
}});
where upper case stands for Arabic/Hebrew.
Now if file pathe which is going to substitute parameter {0} is in English (like c:\file.txt) and this whole formatted message is supposed to be displayed in left-to-right text direction, the display will be senceless - the reading will be unintelligible.
Globalize("he").messageFormatter("error")("c:\file.txt");
2. In addition to the aforementioned 'use case', there is another typical usage of message formatting (let us call it bread crumb pattern) that may constitute a problem from base text direction prespective, although it may be viewed as a particular sub-case of parametric message.
Let us consider the following message (as is expected to be displayed):
Globalize.loadMessages({he: {
breadcrumb: "{0} >> {1} >> {2}",
}});

Even if formatted message with substitutions is supposed to be displayed in left-to-right text direction, the outcome will be rather unpredictable depending on substituting text as follows: (upper case stands for Arabic/Hebrew characters, lower for English)

Globalize("he").messageFormatter("breadcrumb")([ "first", "second", "third" ])
will produce on left-to-right display: "first >> second >> third"

Globalize("he").messageFormatter("breadcrumb")([ "FIRST", "SECOND", "THIRD" ])
will produce on left-to-right display: "THIRD << SECOND << FIRST"

Globalize("he").messageFormatter("breadcrumb")([ "first", "SECOND", "THIRD" ])
will produce on left-to-right display: "first >> SECOND << THIRD"
(please note the order of substitutions on display as well as hectic directionality of <<)
In case like 'breadcrumb' the proper segment isolation is required, which may be only achived by using Unicode control characters (aka. UCC)
UCC are to be used in order to cope with the first kind of problems described above.

The proposal is to augment the 'messageFormatter' (and 'formatMessage') API with
additional parameter - base text direction, and insert appropriate UCC into resultant
formatted string in order to resolve 2 kinds of above mentioned problems.
The base text direction parameter (either 'ltr' or 'rtl') will match the text direction in which the returned string is supposed o be displayed.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.