From 5fb4720c05cd8a1f3f616d3467d687d95126f997 Mon Sep 17 00:00:00 2001 From: Iskren Chernev Date: Thu, 29 Jan 2015 22:51:10 -0800 Subject: [PATCH] Put back node hack for lazily loading locales --- lib/locale/locales.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/locale/locales.js b/lib/locale/locales.js index 12034457e..d085b271d 100644 --- a/lib/locale/locales.js +++ b/lib/locale/locales.js @@ -38,16 +38,18 @@ function chooseLocale(names) { } function loadLocale(name) { - // var oldLocale = null; + var oldLocale = null; // TODO: Find a better way to register and load all the locales in Node - // if (!locales[name] && hasModule) { - // try { - // oldLocale = moment.locale(); - // require('./locale/' + name); - // // because defineLocale currently also sets the global locale, we want to undo that for lazy loaded locales - // moment.locale(oldLocale); - // } catch (e) { } - // } + if (!locales[name] && typeof module !== 'undefined' && + module && module.exports) { + try { + oldLocale = moment.locale(); + require('./locale/' + name); + // because defineLocale currently also sets the global locale, we + // want to undo that for lazy loaded locales + moment.locale(oldLocale); + } catch (e) { } + } return locales[name]; } -- 2.47.2