Skip to content

Commit

Permalink
s/lang/locale
Browse files Browse the repository at this point in the history
 * Deprecated moment.lang(), moment.langData(), moment#lang, and
 duration#lang

 * Added moment.locale(), moment.localeData(), moment#localeData, and
 druation#localeData

 * Added moment.defineLocale() that defines a locale but doesn't set it
 as the global locale (#1750)

 * Removed the hack in the language concatenator that set the language
 to English.

 * Refactored internal code to use moment#localeData instead of local
 functions, and set the language directly on the moment instance at
 creation.

 * Moved all the files and changed the build scripts so that everything
 lives is named "locale" instead of "lang", e.g. the locale files under
 the "locale" directory.

 * I did *not* include build-generated changes like component.json and
 the concated locale files, but I did inspect them to see that they look
 right.
  • Loading branch information
icambron committed Jul 14, 2014
1 parent 2733206 commit 961faff
Show file tree
Hide file tree
Showing 179 changed files with 1,109 additions and 16,028 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ min/moment+customlangs.min.js
min/tests.js
sauce_connect.log
.sauce-labs.creds
npm-debug.log
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Submitting issues
Submitting Issues
=================

If you are submitting a bug, please create a [jsfiddle](http:https://jsfiddle.net/) demonstrating the issue.
Expand All @@ -21,7 +21,7 @@ Very important notes
====================

* **Pull pull requests to the `master` branch will be closed.** Please submit all pull requests to the `develop` branch.
* **Language translations will not be merged without unit tests.** See [the British English unit tests](https://github.com/moment/moment/blob/develop/test/lang/en-gb.js) for an example.
* **Locale translations will not be merged without unit tests.** See [the British English unit tests](https://github.com/moment/moment/blob/develop/test/locale/en-gb.js) for an example.
* **Do not include the minified files in your pull request.** Don't worry, we'll build them when we cut a release.

Grunt tasks
Expand All @@ -32,5 +32,5 @@ We use Grunt for managing the build. Here are some useful Grunt tasks:
* `grunt` The default task lints the code and runs the tests. You should make sure you do this before submitting a PR.
* `grunt nodeunit:all` Just run the tests.
* `grunt release` Build everything, including minified files
* `grunt release --embedLanguages=fr,ru` Build everything, and also create `moment-with-customLangs.js` and `moment-with-customLangs.min.js` containing just French and Russian.
* `grunt release --embedLocales=fr,ru` Build everything, and also create `moment-with-customLocales.js` and `moment-with-customLocales.min.js` containing just French and Russian.
* `grunt size` Print size statistics.
54 changes: 27 additions & 27 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
module.exports = function (grunt) {
var embedOption = grunt.option('embedLanguages'),
embedLanguageDest = embedOption ?
'min/moment-with-customlangs.js' :
'min/moment-with-langs.js',
embedLanguageLangs = 'lang/*.js';
var embedOption = grunt.option('embedLocales'),
embedLocaleDest = embedOption ?
'min/moment-with-customlocales.js' :
'min/moment-with-locales.js',
embedLocaleSrc = 'locale/*.js';

if (embedOption && embedOption.match(/,/)) {
embedLanguageLangs = 'lang/{' + embedOption + '}.js';
embedLocaleSrc = 'locale/{' + embedOption + '}.js';
}
else if (embedOption) {
embedLanguageLangs = 'lang/' + embedOption + '.js';
embedLocaleSrc = 'locale/' + embedOption + '.js';
}

grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat : {
langs: {
src: 'lang/*.js',
dest: 'min/langs.js'
locales: {
src: 'locale/*.js',
dest: 'min/locales.js'
},
tests: {
src: [
'test/browser-prefix.js',
'test/moment/*.js',
'test/lang/*.js',
'test/locale/*.js',
'test/browser-suffix.js'
],
dest: 'min/tests.js'
Expand All @@ -37,7 +37,7 @@ module.exports = function (grunt) {
options: {
frameworks: ['nodeunit'],
files: [
'min/moment-with-langs.js',
'min/moment-with-locales.js',
'min/tests.js',
'test/browser.js'
],
Expand Down Expand Up @@ -102,9 +102,9 @@ module.exports = function (grunt) {
uglify : {
target: {
files: {
'min/moment-with-langs.min.js' : 'min/moment-with-langs.js',
'min/moment-with-customlangs.min.js' : 'min/moment-with-customlangs.js',
'min/langs.min.js' : 'min/langs.js',
'min/moment-with-locales.min.js' : 'min/moment-with-locales.js',
'min/moment-with-customlocales.min.js' : 'min/moment-with-customlocales.js',
'min/locales.min.js' : 'min/locales.js',
'min/moment.min.js' : 'moment.js'
}
},
Expand All @@ -121,11 +121,11 @@ module.exports = function (grunt) {
}
},
nodeunit : {
all : ["test/moment/**/*.js", "test/lang/**/*.js"]
all : ["test/moment/**/*.js", "test/locale/**/*.js"]
},
jshint: {
all: [
"Gruntfile.js", "moment.js", "lang/**/*.js", "test/**/*.js",
"Gruntfile.js", "moment.js", "locale/**/*.js", "test/**/*.js",
"!test/browser*.js"
],
options: {
Expand Down Expand Up @@ -161,7 +161,7 @@ module.exports = function (grunt) {
},
jscs: {
all: [
"Gruntfile.js", "moment.js", "lang/**/*.js",
"Gruntfile.js", "moment.js", "locale/**/*.js",
"test/**/*.js", "!test/browser*.js"
],
options: {
Expand All @@ -172,7 +172,7 @@ module.exports = function (grunt) {
test : {
files : [
'moment.js',
'lang/*.js',
'locale/*.js',
'test/**/*.js'
],
tasks: ['nodeunit']
Expand All @@ -182,10 +182,10 @@ module.exports = function (grunt) {
tasks: ['jshint']
}
},
embedLanguages: {
embedLocales: {
moment: 'moment.js',
dest: embedLanguageDest,
targetLangs: embedLanguageLangs
dest: embedLocaleDest,
targetLocales: embedLocaleSrc
}
});

Expand All @@ -200,10 +200,10 @@ module.exports = function (grunt) {
// test tasks
grunt.registerTask('test', ['test:node', 'test:browser']);
grunt.registerTask('test:node', ['nodeunit']);
grunt.registerTask('test:server', ['concat', 'embedLanguages', 'karma:server']);
grunt.registerTask('test:browser', ['concat', 'embedLanguages', 'karma:chrome', 'karma:firefox']);
grunt.registerTask('test:sauce-browser', ['concat', 'embedLanguages', 'env:sauceLabs', 'karma:sauce']);
grunt.registerTask('test:travis-sauce-browser', ['concat', 'embedLanguages', 'karma:sauce']);
grunt.registerTask('test:server', ['concat', 'embedLocales', 'karma:server']);
grunt.registerTask('test:browser', ['concat', 'embedLocales', 'karma:chrome', 'karma:firefox']);
grunt.registerTask('test:sauce-browser', ['concat', 'embedLocales', 'env:sauceLabs', 'karma:sauce']);
grunt.registerTask('test:travis-sauce-browser', ['concat', 'embedLocales', 'karma:sauce']);

// travis build task
grunt.registerTask('build:travis', [
Expand All @@ -215,7 +215,7 @@ module.exports = function (grunt) {

// Task to be run when releasing a new version
grunt.registerTask('release', [
'jshint', 'nodeunit', 'concat', 'embedLanguages',
'jshint', 'nodeunit', 'concat', 'embedLocales',
'component', 'uglify'
]);
};
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
],
"files": [
"min/*.js",
"lang/*.js"
"locale/*.js"
]
}
}
Expand Down
6 changes: 3 additions & 3 deletions lang/ar-ma.js → locale/ar-ma.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// moment.js language configuration
// language : Moroccan Arabic (ar-ma)
// moment.js locale configuration
// locale : Moroccan Arabic (ar-ma)
// author : ElFadili Yassine : https://github.com/ElFadiliY
// author : Abdel Said : https://github.com/abdelsaid

Expand All @@ -12,7 +12,7 @@
factory(window.moment); // Browser global
}
}(function (moment) {
return moment.lang('ar-ma', {
return moment.defineLocale('ar-ma', {
months : "يناير_فبراير_مارس_أبريل_ماي_يونيو_يوليوز_غشت_شتنبر_أكتوبر_نونبر_دجنبر".split("_"),
monthsShort : "يناير_فبراير_مارس_أبريل_ماي_يونيو_يوليوز_غشت_شتنبر_أكتوبر_نونبر_دجنبر".split("_"),
weekdays : "الأحد_الإتنين_الثلاثاء_الأربعاء_الخميس_الجمعة_السبت".split("_"),
Expand Down
6 changes: 3 additions & 3 deletions lang/ar-sa.js → locale/ar-sa.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// moment.js language configuration
// language : Arabic Saudi Arabia (ar-sa)
// moment.js locale configuration
// locale : Arabic Saudi Arabia (ar-sa)
// author : Suhail Alkowaileet : https://github.com/xsoh

(function (factory) {
Expand Down Expand Up @@ -35,7 +35,7 @@
'٠': '0'
};

return moment.lang('ar-sa', {
return moment.defineLocale('ar-sa', {
months : "يناير_فبراير_مارس_أبريل_مايو_يونيو_يوليو_أغسطس_سبتمبر_أكتوبر_نوفمبر_ديسمبر".split("_"),
monthsShort : "يناير_فبراير_مارس_أبريل_مايو_يونيو_يوليو_أغسطس_سبتمبر_أكتوبر_نوفمبر_ديسمبر".split("_"),
weekdays : "الأحد_الإثنين_الثلاثاء_الأربعاء_الخميس_الجمعة_السبت".split("_"),
Expand Down
6 changes: 3 additions & 3 deletions lang/ar.js → locale/ar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// moment.js language configuration
// language : Arabic (ar)
// moment.js locale configuration
// locale : Arabic (ar)
// author : Abdel Said : https://github.com/abdelsaid
// changes in months, weekdays : Ahmed Elkhatib

Expand Down Expand Up @@ -36,7 +36,7 @@
'٠': '0'
};

return moment.lang('ar', {
return moment.defineLocale('ar', {
months : "يناير/ كانون الثاني_فبراير/ شباط_مارس/ آذار_أبريل/ نيسان_مايو/ أيار_يونيو/ حزيران_يوليو/ تموز_أغسطس/ آب_سبتمبر/ أيلول_أكتوبر/ تشرين الأول_نوفمبر/ تشرين الثاني_ديسمبر/ كانون الأول".split("_"),
monthsShort : "يناير/ كانون الثاني_فبراير/ شباط_مارس/ آذار_أبريل/ نيسان_مايو/ أيار_يونيو/ حزيران_يوليو/ تموز_أغسطس/ آب_سبتمبر/ أيلول_أكتوبر/ تشرين الأول_نوفمبر/ تشرين الثاني_ديسمبر/ كانون الأول".split("_"),
weekdays : "الأحد_الإثنين_الثلاثاء_الأربعاء_الخميس_الجمعة_السبت".split("_"),
Expand Down
6 changes: 3 additions & 3 deletions lang/az.js → locale/az.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// moment.js language configuration
// language : azerbaijani (az)
// moment.js locale configuration
// locale : azerbaijani (az)
// author : topchiyev : https://github.com/topchiyev

(function (factory) {
Expand Down Expand Up @@ -36,7 +36,7 @@
60: "-ıncı",
90: "-ıncı"
};
return moment.lang('az', {
return moment.defineLocale('az', {
months : "yanvar_fevral_mart_aprel_may_iyun_iyul_avqust_sentyabr_oktyabr_noyabr_dekabr".split("_"),
monthsShort : "yan_fev_mar_apr_may_iyn_iyl_avq_sen_okt_noy_dek".split("_"),
weekdays : "Bazar_Bazar ertəsi_Çərşənbə axşamı_Çərşənbə_Cümə axşamı_Cümə_Şənbə".split("_"),
Expand Down
6 changes: 3 additions & 3 deletions lang/bg.js → locale/bg.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// moment.js language configuration
// language : bulgarian (bg)
// moment.js locale configuration
// locale : bulgarian (bg)
// author : Krasen Borisov : https://github.com/kraz

(function (factory) {
Expand All @@ -11,7 +11,7 @@
factory(window.moment); // Browser global
}
}(function (moment) {
return moment.lang('bg', {
return moment.defineLocale('bg', {
months : "януари_февруари_март_април_май_юни_юли_август_септември_октомври_ноември_декември".split("_"),
monthsShort : "янр_фев_мар_апр_май_юни_юли_авг_сеп_окт_ное_дек".split("_"),
weekdays : "неделя_понеделник_вторник_сряда_четвъртък_петък_събота".split("_"),
Expand Down
6 changes: 3 additions & 3 deletions lang/bn.js → locale/bn.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// moment.js language configuration
// language : Bengali (bn)
// moment.js locale configuration
// locale : Bengali (bn)
// author : Kaushik Gandhi : https://github.com/kaushikgandhi

(function (factory) {
Expand Down Expand Up @@ -36,7 +36,7 @@
'০': '0'
};

return moment.lang('bn', {
return moment.defineLocale('bn', {
months : 'জানুয়ারী_ফেবুয়ারী_মার্চ_এপ্রিল_মে_জুন_জুলাই_অগাস্ট_সেপ্টেম্বর_অক্টোবর_নভেম্বর_ডিসেম্বর'.split("_"),
monthsShort : 'জানু_ফেব_মার্চ_এপর_মে_জুন_জুল_অগ_সেপ্ট_অক্টো_নভ_ডিসেম্'.split("_"),
weekdays : 'রবিবার_সোমবার_মঙ্গলবার_বুধবার_বৃহস্পত্তিবার_শুক্রুবার_শনিবার'.split("_"),
Expand Down
6 changes: 3 additions & 3 deletions lang/br.js → locale/br.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// moment.js language configuration
// language : breton (br)
// moment.js locale configuration
// locale : breton (br)
// author : Jean-Baptiste Le Duigou : https://github.com/jbleduigou

(function (factory) {
Expand Down Expand Up @@ -59,7 +59,7 @@
return mutationTable[text.charAt(0)] + text.substring(1);
}

return moment.lang('br', {
return moment.defineLocale('br', {
months : "Genver_C'hwevrer_Meurzh_Ebrel_Mae_Mezheven_Gouere_Eost_Gwengolo_Here_Du_Kerzu".split("_"),
monthsShort : "Gen_C'hwe_Meu_Ebr_Mae_Eve_Gou_Eos_Gwe_Her_Du_Ker".split("_"),
weekdays : "Sul_Lun_Meurzh_Merc'her_Yaou_Gwener_Sadorn".split("_"),
Expand Down
6 changes: 3 additions & 3 deletions lang/bs.js → locale/bs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// moment.js language configuration
// language : bosnian (bs)
// moment.js locale configuration
// locale : bosnian (bs)
// author : Nedim Cholich : https://github.com/frontyard
// based on (hr) translation by Bojan Marković

Expand Down Expand Up @@ -65,7 +65,7 @@
}
}

return moment.lang('bs', {
return moment.defineLocale('bs', {
months : "januar_februar_mart_april_maj_juni_juli_avgust_septembar_oktobar_novembar_decembar".split("_"),
monthsShort : "jan._feb._mar._apr._maj._jun._jul._avg._sep._okt._nov._dec.".split("_"),
weekdays : "nedjelja_ponedjeljak_utorak_srijeda_četvrtak_petak_subota".split("_"),
Expand Down
6 changes: 3 additions & 3 deletions lang/ca.js → locale/ca.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// moment.js language configuration
// language : catalan (ca)
// moment.js locale configuration
// locale : catalan (ca)
// author : Juan G. Hurtado : https://github.com/juanghurtado

(function (factory) {
Expand All @@ -11,7 +11,7 @@
factory(window.moment); // Browser global
}
}(function (moment) {
return moment.lang('ca', {
return moment.defineLocale('ca', {
months : "gener_febrer_març_abril_maig_juny_juliol_agost_setembre_octubre_novembre_desembre".split("_"),
monthsShort : "gen._febr._mar._abr._mai._jun._jul._ag._set._oct._nov._des.".split("_"),
weekdays : "diumenge_dilluns_dimarts_dimecres_dijous_divendres_dissabte".split("_"),
Expand Down
6 changes: 3 additions & 3 deletions lang/cs.js → locale/cs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// moment.js language configuration
// language : czech (cs)
// moment.js locale configuration
// locale : czech (cs)
// author : petrbela : https://github.com/petrbela

(function (factory) {
Expand Down Expand Up @@ -71,7 +71,7 @@
}
}

return moment.lang('cs', {
return moment.defineLocale('cs', {
months : months,
monthsShort : monthsShort,
monthsParse : (function (months, monthsShort) {
Expand Down
6 changes: 3 additions & 3 deletions lang/cv.js → locale/cv.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// moment.js language configuration
// language : chuvash (cv)
// moment.js locale configuration
// locale : chuvash (cv)
// author : Anatoly Mironov : https://github.com/mirontoli

(function (factory) {
Expand All @@ -11,7 +11,7 @@
factory(window.moment); // Browser global
}
}(function (moment) {
return moment.lang('cv', {
return moment.defineLocale('cv', {
months : "кăрлач_нарăс_пуш_ака_май_çĕртме_утă_çурла_авăн_юпа_чӳк_раштав".split("_"),
monthsShort : "кăр_нар_пуш_ака_май_çĕр_утă_çур_ав_юпа_чӳк_раш".split("_"),
weekdays : "вырсарникун_тунтикун_ытларикун_юнкун_кĕçнерникун_эрнекун_шăматкун".split("_"),
Expand Down
6 changes: 3 additions & 3 deletions lang/cy.js → locale/cy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// moment.js language configuration
// language : Welsh (cy)
// moment.js locale configuration
// locale : Welsh (cy)
// author : Robert Allen

(function (factory) {
Expand All @@ -11,7 +11,7 @@
factory(window.moment); // Browser global
}
}(function (moment) {
return moment.lang("cy", {
return moment.defineLocale("cy", {
months: "Ionawr_Chwefror_Mawrth_Ebrill_Mai_Mehefin_Gorffennaf_Awst_Medi_Hydref_Tachwedd_Rhagfyr".split("_"),
monthsShort: "Ion_Chwe_Maw_Ebr_Mai_Meh_Gor_Aws_Med_Hyd_Tach_Rhag".split("_"),
weekdays: "Dydd Sul_Dydd Llun_Dydd Mawrth_Dydd Mercher_Dydd Iau_Dydd Gwener_Dydd Sadwrn".split("_"),
Expand Down
6 changes: 3 additions & 3 deletions lang/da.js → locale/da.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// moment.js language configuration
// language : danish (da)
// moment.js locale configuration
// locale : danish (da)
// author : Ulrik Nielsen : https://github.com/mrbase

(function (factory) {
Expand All @@ -11,7 +11,7 @@
factory(window.moment); // Browser global
}
}(function (moment) {
return moment.lang('da', {
return moment.defineLocale('da', {
months : "januar_februar_marts_april_maj_juni_juli_august_september_oktober_november_december".split("_"),
monthsShort : "jan_feb_mar_apr_maj_jun_jul_aug_sep_okt_nov_dec".split("_"),
weekdays : "søndag_mandag_tirsdag_onsdag_torsdag_fredag_lørdag".split("_"),
Expand Down
Loading

0 comments on commit 961faff

Please sign in to comment.