-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: checks navigator language for rtl enabling (#253)
- RTL is now set from the configuration by priority. If no configuration for rtl or language is provided - navigator language is checked. - getEffectiveRTL module is added as an util.
- Loading branch information
Showing
7 changed files
with
56 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export default () => { | ||
const browserLanguages = navigator.languages; | ||
|
||
const navigatorLanguage = () => { | ||
return navigator.language; | ||
}; | ||
|
||
const rawLocale = (browserLanguages && browserLanguages[0]) || navigatorLanguage() || navigator.userLanguage || navigator.browserLanguage; | ||
|
||
return rawLocale || "en"; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export default value => { | ||
const m = /\$([-a-z0-9A-Z._]+)(?::([^$]*))?\$/.exec(value); | ||
return m && m[2] ? m[2].split(/,/) : null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { getRTL, getLanguage } from "../Configuration"; | ||
import getDesigntimePropertyAsArray from "./getDesigntimePropertyAsArray"; | ||
import detectNavigatorLanguage from "./detectNavigatorLanguage"; | ||
|
||
const M_ISO639_OLD_TO_NEW = { | ||
"iw": "he", | ||
"ji": "yi", | ||
"in": "id", | ||
"sh": "sr", | ||
}; | ||
|
||
const A_RTL_LOCALES = getDesigntimePropertyAsArray("$cldr-rtl-locales:ar,fa,he$") || []; | ||
|
||
const impliesRTL = language => { | ||
language = (language && M_ISO639_OLD_TO_NEW[language]) || language; | ||
|
||
return A_RTL_LOCALES.indexOf(language) >= 0; | ||
}; | ||
|
||
const getEffectiveRTL = () => { | ||
const configurationRTL = getRTL(); | ||
|
||
if (configurationRTL !== null) { | ||
return !!configurationRTL; | ||
} | ||
|
||
return impliesRTL(getLanguage() || detectNavigatorLanguage()); | ||
}; | ||
|
||
export default getEffectiveRTL; |