Constructors
************************************/
- function Language(config) {
- var prop, i;
- for (i in config) {
- prop = config[i];
- if (typeof prop === 'function') {
- this[i] = prop;
- } else {
- this['_' + i] = prop;
- }
- }
+ function Language() {
+
}
// Moment prototype object
Language.prototype = {
+ set : function (config) {
+ var prop, i;
+ for (i in config) {
+ prop = config[i];
+ if (typeof prop === 'function') {
+ this[i] = prop;
+ } else {
+ this['_' + i] = prop;
+ }
+ }
+ },
+
_months : "January_February_March_April_May_June_July_August_September_October_November_December".split("_"),
months : function (m) {
return this._months[m.month()];
// this function also returns the language values.
function loadLang(key, values) {
values.abbr = key;
- languages[key] = new Language(values);
+ if (!languages[key]) {
+ languages[key] = new Language();
+ }
+ languages[key].set(values);
return languages[key];
}
test.done();
},
-/*
- // the following tests should be removed after the 2.0.0 release as they will be deprecated
- "lang accessors on the global object should exist < 2.0.0" : function (test) {
- moment.lang('en');
-
- var a = 'months|monthsShort|monthsParse|weekdays|weekdaysShort|weekdaysMin|longDateFormat|calendar|relativeTime|ordinal|meridiem'.split('|');
- var i;
-
- test.expect(a.length);
-
- for (i = 0; i < a.length; i++) {
- test.ok(moment[a[i]], "moment." + a[i] + " should exist");
- }
-
- test.done();
- },
-
- // the following tests should be removed after the 2.0.0 release as they will be deprecated
- "lang accessors on the global object should change < 2.0.0" : function (test) {
- moment.lang('en');
-
- var a = 'months|monthsShort|weekdays|weekdaysShort|weekdaysMin|longDateFormat|calendar|relativeTime|ordinal'.split('|');
- var i;
- var en = {};
-
- test.expect(a.length);
-
- for (i = 0; i < a.length; i++) {
- en[a[i]] = moment[a[i]];
- }
-
- moment.lang('fr');
-
- for (i = 0; i < a.length; i++) {
- test.notDeepEqual(en[a[i]], moment[a[i]], "the " + a[i] + " lang data should change on the global object");
- }
+ "changing parts of a language config" : function (test) {
+ test.expect(2);
- test.done();
- },
+ moment.lang('partial-lang', {
+ months : 'a b c d e f g h i j k l'.split(' ')
+ });
- "manip lang accessors on the global object < 2.0.0" : function (test) {
- test.expect(1);
- moment.lang('en');
+ test.equal(moment([2011, 0, 1]).format('MMMM'), 'a', 'should be able to set language values when creating the language');
- moment.months = ["test"];
- test.equal(moment([2011, 0]).format('MMMM'), "test", "Should be able to manipulate the objects on the global object");
+ moment.lang('partial-lang', {
+ monthsShort : 'A B C D E F G H I J K L'.split(' ')
+ });
- moment.lang('en');
+ test.equal(moment([2011, 0, 1]).format('MMMM MMM'), 'a A', 'should be able to set language values after creating the language');
test.done();
}
-*/
};