-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
List loaded locales #2932
List loaded locales #2932
Conversation
70c067e
to
5bd2afb
Compare
LGTM. Staging for next release. Thanks! |
@@ -152,6 +152,10 @@ test('defineLocale', function (assert) { | |||
assert.equal(moment().locale('dude').locale(), 'dude', 'defineLocale defines a locale'); | |||
}); | |||
|
|||
test('locales', function (assert) { | |||
assert.equal(moment.locales().length > 0, true, 'locales returns an array of defined locales'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to see a smarter test here. Test for content, at least for English, and perhaps include one custom locale (like dude
shown in the test above)
Merged in c0519b5 |
Should this be in the docs too? I'm asking because I wasn't able to find any references to it |
The method is let locales = moment.locales(); // ['en', 'ru', 'pl'] |
For me, it only returns |
@devondahon when you try yo change the locale with It could be that your other locales are not importing properly.... |
The locales() function just return ["en"]. It doesn't work for me. Any one know the reason? |
@anhkhoi how are you loading your secondary locales? |
@mhornbacher I just created custom script https://gist.github.com/StefansArya/1a9423fab2b966a08ea672a864a98333 |
@StefansArya nice script! Is something broken with it? |
@mhornbacher I just tested on jsbin and working as expected. You can use any locale format like It also has additional fallback, for the example The first argument on the callback will return If you call Also tested and working on IE11. |
I think that the listing of all the supported/available locales (even if there were not loaded yet) should be included in the moment core itself, and not hardcoded in the client code, what do you think? It would be nice to have a method e.g. like import moment from "moment";
console.log(moment.allSupportedLocales()); // ["en", "it", "de", ..., "ja", ...] |
Fixes #843
This adds the method
moment.locales()
to get an array of the locales that have been loaded (ie, bundled with moment.js or manually required in node.)It does not list or
require
available (but unloaded) locales in node. I think that should be a separate feature if needed at all.