From 22249c40fa7f6d32130f0f3569271f9cdb5dae62 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 3 May 2013 13:32:28 -0700 Subject: [PATCH] Configurable locale --- js/id/id.js | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/js/id/id.js b/js/id/id.js index 7703b527f..1352c56b5 100644 --- a/js/id/id.js +++ b/js/id/id.js @@ -1,6 +1,6 @@ window.iD = function () { - locale.en = iD.data.en; - locale.current('en'); + window.locale.en = iD.data.en; + window.locale.current('en'); var context = {}, storage; @@ -22,7 +22,13 @@ window.iD = function () { container, ui = iD.ui(context), map = iD.Map(context), - connection = iD.Connection(); + connection = iD.Connection(), + locale = iD.detect().locale, + localePath; + + if (locale && iD.data.locales.indexOf(locale) === -1) { + locale = locale.split('-')[0]; + } connection.on('load.context', function loadContext(err, result) { history.merge(result); @@ -33,20 +39,21 @@ window.iD = function () { return context; }; + context.locale = function(_, path) { + locale = _; + localePath = path; + return context; + }; + context.ui = function() { return function(container) { context.container(container); - var detectedLocale = iD.detect().locale; - - if (detectedLocale && iD.data.locales.indexOf(detectedLocale) === -1) { - detectedLocale = detectedLocale.split('-')[0]; - } - - if (detectedLocale && detectedLocale !== 'en' && iD.data.locales.indexOf(detectedLocale) !== -1) { - d3.json(context.assetPath() + 'locales/' + detectedLocale + '.json', function(err, result) { - locale[detectedLocale] = result; - locale.current(detectedLocale); + if (locale && locale !== 'en' && iD.data.locales.indexOf(locale) !== -1) { + localePath = localePath || context.assetPath() + 'locales/' + locale + '.json'; + d3.json(localePath, function(err, result) { + window.locale[locale] = result; + window.locale.current(locale); container.call(ui); }); } else {