// TODO: Find a better way to register and load all the locales in Node
if (!locales[name] && (typeof module !== 'undefined') &&
module && module.exports) {
+ oldLocale = globalLocale._abbr;
try {
- oldLocale = globalLocale._abbr;
- require('./locale/' + name);
- // because defineLocale currently also sets the global locale, we
- // want to undo that for lazy loaded locales
- getSetGlobalLocale(oldLocale);
- } catch (e) { }
+ require('moment/locale/' + name);
+ } catch (e) {
+ // In the test environment, the external module 'moment'
+ // can't be resolved because we're running inside it.
+ // Fallback to using the old relative import
+ try {
+ require('./locale/' + name);
+ } catch (e) { }
+ }
+
+ // because defineLocale currently also sets the global locale, we
+ // want to undo that for lazy loaded locales
+ getSetGlobalLocale(oldLocale);
}
return locales[name];
}