Home

# Library goog.i18n.bidi

Function Summary
| `detectRtlDirectionality(string str, boolean= opt_isHtml) ⇒ boolean` Check the directionality of a piece of text, return true if the piece of text should be laid out in RTL direction.
| `endsWithLtr(string str, boolean= opt_isHtml) ⇒ boolean` Check if the exit directionality a piece of text is LTR, i.e. if the last strongly-directional character in the string is LTR.
| `endsWithRtl(string str, boolean= opt_isHtml) ⇒ boolean` Check if the exit directionality a piece of text is RTL, i.e. if the last strongly-directional character in the string is RTL.

`enforceLtrInHtml(string html) ⇒ string`

Enforce the html snippet in RTL directionality regardless overall context. If the html piece was enclosed by tag, dir will be applied to existing tag, otherwise a span tag will be added as wrapper. For this reason, if html snippet start with with tag, this tag must enclose the whole piece. If the tag already has a dir specified, this new one will override existing one in behavior (tested on FF and IE).

| `enforceLtrInText(string text) ⇒ string` Enforce LTR on both end of the given text piece using unicode BiDi formatting characters LRE and PDF.

`enforceRtlInHtml(string html) ⇒ string`

Enforce the html snippet in RTL directionality regardless overall context. If the html piece was enclosed by tag, dir will be applied to existing tag, otherwise a span tag will be added as wrapper. For this reason, if html snippet start with with tag, this tag must enclose the whole piece. If the tag already has a dir specified, this new one will override existing one in behavior (tested on FF and IE).

| `enforceRtlInText(string text) ⇒ string` Enforce RTL on both end of the given text piece using unicode BiDi formatting characters RLE and PDF.

`estimateDirection(string str, boolean= opt_isHtml) ⇒ ?goog.i18n.bidi.Dir`

Estimates the directionality of a string based on relative word counts. If the number of RTL words is above a certain percentage of the total number of strongly directional words, returns RTL. Otherwise, if any words are strongly or weakly LTR, returns LTR. Otherwise, returns UNKNOWN, which is used to mean "neutral". Numbers are counted as weakly LTR.

| `guardBracketInHtml(string s, boolean= opt_isRtlContext) ⇒ string` Apply bracket guard using html span tag. This is to address the problem of messy bracket display frequently happens in RTL layout.
| `guardBracketInText(string s, boolean= opt_isRtlContext) ⇒ string` Apply bracket guard using LRM and RLM. This is to address the problem of messy bracket display frequently happens in RTL layout. This version works for both plain text and html. But it does not work as good as guardBracketInHtml in some cases.
| `hasAnyLtr(string str, boolean= opt_isHtml) ⇒ boolean` Test whether the given string has any LTR characters in it.
| `hasAnyRtl(string str, boolean= opt_isHtml) ⇒ boolean` Test whether the given string has any RTL characters in it.
| `isLtrChar(string str) ⇒ boolean` Check if the first character in the string is LTR or not.
| `isNeutralChar(string str) ⇒ boolean` Check if the first character in the string is neutral or not.
| `isNeutralText(string str, boolean= opt_isHtml) ⇒ boolean` Check whether the input string either contains no strongly directional characters or looks like a url.
| `isRtlChar(string str) ⇒ boolean` Check if the first character in the string is RTL or not.

`isRtlLanguage(string lang) ⇒ boolean`

Check if a BCP 47 / III language code indicates an RTL language, i.e. either: - a language code explicitly specifying one of the right-to-left scripts, e.g. "az-Arab", or

- a language code specifying one of the languages normally written in a right-to-left script, e.g. "fa" (Farsi), except ones explicitly specifying Latin or Cyrillic script (which are the usual LTR alternatives).

The list of right-to-left scripts appears in the 100-199 range in http://www.unicode.org/iso15924/iso15924-num.html, of which Arabic and Hebrew are by far the most widely used. We also recognize Thaana, N'Ko, and Tifinagh, which also have significant modern usage. The rest (Syriac, Samaritan, Mandaic, etc.) seem to have extremely limited or no modern usage and are not recognized to save on code size. The languages usually written in a right-to-left script are taken as those with Suppress-Script: Hebr|Arab|Thaa|Nkoo|Tfng in http://www.iana.org/assignments/language-subtag-registry, as well as Sindhi (sd) and Uyghur (ug). Other subtags of the language code, e.g. regions like EG (Egypt), are ignored.

| `mirrorCSS(string cssStr) ⇒ string` Swap location parameters and 'left'/'right' in CSS specification. The processed string will be suited for RTL layout. Though this function can cover most cases, there are always exceptions. It is suggested to put those exceptions in separate group of CSS string.
| `normalizeHebrewQuote(string str) ⇒ string` Replace the double and single quote directly after a Hebrew character with GERESH and GERSHAYIM. In such case, most likely that's user intention.
| `setElementDirAndAlign(?Element element, (boolean|goog.i18n.bidi.Dir|null|number) dir)` Sets text input element's directionality and text alignment based on a given directionality.
| `startsWithLtr(string str, boolean= opt_isHtml) ⇒ boolean` Check whether the first strongly directional character (if any) is LTR.
| `startsWithRtl(string str, boolean= opt_isHtml) ⇒ boolean` Check whether the first strongly directional character (if any) is RTL.

`stripHtmlIfNeeded_(string str, boolean= opt_isStripNeeded) ⇒ string`

Returns the input text with spaces instead of HTML tags or HTML escapes, if opt_isStripNeeded is true. Else returns the input as is. Useful for text directionality estimation. Note: the function should not be used in other contexts; it is not 100% correct, but rather a good-enough implementation for directionality estimation purposes.

| `toDir((boolean|goog.i18n.bidi.Dir|null|number) givenDir) ⇒ ?goog.i18n.bidi.Dir` Convert a directionality given in various formats to a goog.i18n.bidi.Dir constant. Useful for interaction with different standards of directionality representation.