]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
[misc] Print console warning when setting non-existent locales (#4085)
authorasulaiman <asulaimanificent@gmail.com>
Fri, 2 Mar 2018 18:54:40 +0000 (13:54 -0500)
committerKunal Marwaha <marwahaha@berkeley.edu>
Fri, 2 Mar 2018 18:54:40 +0000 (10:54 -0800)
* Dont silently fail setting new locale when it isnt available

Right now if the new locale being set is not available then it fails silently and just uses the existing global locale. A console warning would be useful to notify the user of such a failure.

* added missing semicolon

* Added console warn check.

* Fixed if condition.

* Add space

src/lib/locale/locales.js

index 7d8fb26e0317f604445f5f69206367918c4a68db..131d87e4ca12bc2b6463e4f043f46c5d54646c92 100644 (file)
@@ -77,6 +77,12 @@ export function getSetGlobalLocale (key, values) {
             // moment.duration._locale = moment._locale = data;
             globalLocale = data;
         }
+        else {
+            if ((typeof console !==  'undefined') && console.warn) {
+                //warn user if arguments are passed but the locale could not be set
+                console.warn('Locale ' + key +  ' not found. Did you forget to load it?');
+            }
+        }
     }
 
     return globalLocale._abbr;