Replace hardcoded RTL list with detected language lookup from dataLocales

This commit is contained in:
Bryan Housel
2016-11-28 00:12:50 -05:00
parent fc0b8a6a90
commit 3f024d0b95
2 changed files with 5 additions and 3 deletions

View File

@@ -307,7 +307,7 @@ export function coreContext() {
};
context.loadLocale = function(callback) {
if (locale && locale !== 'en' && dataLocales.indexOf(locale) !== -1) {
if (locale && locale !== 'en' && dataLocales.hasOwnProperty(locale)) {
localePath = localePath || context.asset('locales/' + locale + '.json');
d3.json(localePath, function(err, result) {
if (!err) {
@@ -351,7 +351,7 @@ export function coreContext() {
context.projection = geoRawMercator();
locale = utilDetect().locale;
if (locale && dataLocales.indexOf(locale) === -1) {
if (locale && !dataLocales.hasOwnProperty(locale)) {
locale = locale.split('-')[0];
}

View File

@@ -1,4 +1,5 @@
import { currentLocale, setTextDirection } from './locale';
import { dataLocales } from '../../data/index';
import { utilStringQs } from './index';
var detected;
@@ -70,7 +71,8 @@ export function utilDetect(force) {
// detect text direction
var q = utilStringQs(window.location.hash.substring(1));
if (['ar', 'fa', 'iw', 'he', 'dv'].indexOf(detected.locale.split('-')[0]) > -1 || q.hasOwnProperty('rtl')) {
var lang = dataLocales[detected.locale];
if ((lang && lang.rtl) || q.hasOwnProperty('rtl')) {
detected.textDirection = 'rtl';
} else {
detected.textDirection = 'ltr';