From e606f4713f5a9ed2b2752316c8420360bbc77869 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Thu, 10 Nov 2016 15:14:27 -0500 Subject: [PATCH] Force utilDetect() to re-detect after setting the locale (closes #3574) --- modules/core/context.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/modules/core/context.js b/modules/core/context.js index a0c8ee52a..2a773cefe 100644 --- a/modules/core/context.js +++ b/modules/core/context.js @@ -1,6 +1,6 @@ import * as d3 from 'd3'; import _ from 'lodash'; -import { t, addTranslation, setLocale } from '../util/locale'; +import { t, currentLocale, addTranslation, setLocale } from '../util/locale'; import { coreHistory } from './history'; import { dataLocales, dataEn } from '../../data/index'; import { geoRawMercator } from '../geo/raw_mercator'; @@ -22,12 +22,7 @@ export function setAreaKeys(value) { } -export function coreContext(root) { - if (!root.locale) { - root.locale = { - current: function(_) { this._current = _; } - }; - } +export function coreContext() { addTranslation('en', dataEn); setLocale('en'); @@ -310,9 +305,14 @@ export function coreContext(root) { return context.asset('img/' + _); }; + + /* locales */ + // `locale` variable contains a "requested locale". + // It won't become the `currentLocale` until after loadLocale() is called. var locale, localePath; + context.locale = function(loc, path) { - if (!arguments.length) return locale; + if (!arguments.length) return currentLocale; locale = loc; localePath = path; return context; @@ -325,12 +325,17 @@ export function coreContext(root) { if (!err) { addTranslation(locale, result[locale]); setLocale(locale); + utilDetect(true); } if (callback) { callback(err); } }); } else { + if (locale) { + setLocale(locale); + utilDetect(true); + } if (callback) { callback(); }