Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 7b8a16b

Browse files
committed
refactor($locale): use en-us as generic built-in locale
Previously there was a custom built en-us locale that was included with angular.js. This made likely that it would get out of sync with the real en-us locale that is generated from the closure library. This change removes that custom one and uses the generated one instead. This also has the benefit of preventing the unwanted caught error on trying to load `ngLocale` during angular bootstrap. Closes #12462 Closes #12444 Closes #12134 Closes #8174
1 parent d2695b0 commit 7b8a16b

7 files changed

+23
-93
lines changed

Gruntfile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ module.exports = function(grunt) {
115115
files: { src: 'test/**/*.js' },
116116
},
117117
ng: {
118-
files: { src: files['angularSrc'] },
118+
files: { src: files['angularSrc'].concat('!src/angular.bind') },
119119
},
120120
ngAnimate: {
121121
files: { src: 'src/ngAnimate/**/*.js' },

angularFiles.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ var angularFiles = {
7676
'src/ng/directive/script.js',
7777
'src/ng/directive/select.js',
7878
'src/ng/directive/style.js',
79-
'src/ng/directive/validators.js'
79+
'src/ng/directive/validators.js',
80+
'src/angular.bind',
81+
'src/publishExternalApis.js',
82+
'src/ngLocale/angular-locale_en-us.js'
8083
],
8184

8285
'angularLoader': [
@@ -179,7 +182,6 @@ var angularFiles = {
179182
'bower_components/jquery/dist/jquery.js',
180183
'test/jquery_remove.js',
181184
'@angularSrc',
182-
'src/publishExternalApis.js',
183185
'@angularSrcModules',
184186
'@angularScenario',
185187
'@angularTest'
@@ -188,7 +190,8 @@ var angularFiles = {
188190
'karmaExclude': [
189191
'test/jquery_alias.js',
190192
'src/angular-bootstrap.js',
191-
'src/ngScenario/angular-bootstrap.js'
193+
'src/ngScenario/angular-bootstrap.js',
194+
'src/angular.bind'
192195
],
193196

194197
'karmaScenario': [
@@ -215,7 +218,6 @@ var angularFiles = {
215218
'bower_components/jquery/dist/jquery.js',
216219
'test/jquery_alias.js',
217220
'@angularSrc',
218-
'src/publishExternalApis.js',
219221
'@angularSrcModules',
220222
'@angularScenario',
221223
'@angularTest'
@@ -224,7 +226,8 @@ var angularFiles = {
224226
'karmaJqueryExclude': [
225227
'src/angular-bootstrap.js',
226228
'src/ngScenario/angular-bootstrap.js',
227-
'test/jquery_remove.js'
229+
'test/jquery_remove.js',
230+
'src/angular.bind'
228231
]
229232
};
230233

src/AngularPublic.js

-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
/* global angularModule: true,
44
version: true,
55
6-
$LocaleProvider,
76
$CompileProvider,
87
98
htmlAnchorDirective,
@@ -151,11 +150,6 @@ function publishExternalAPI(angular) {
151150
});
152151

153152
angularModule = setupModuleLoader(window);
154-
try {
155-
angularModule('ngLocale');
156-
} catch (e) {
157-
angularModule('ngLocale', []).provider('$locale', $LocaleProvider);
158-
}
159153

160154
angularModule('ng', ['ngLocale'], ['$provide',
161155
function ngModule($provide) {

src/angular.bind

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
if (window.angular.bootstrap) {
2+
//AngularJS is already loaded, so we can return here...
3+
console.log('WARNING: Tried to load angular more than once.');
4+
return;
5+
}
6+
7+
//try to bind to jquery now so that one can write jqLite(document).ready()
8+
//but we will rebind on bootstrap again.
9+
bindJQuery();
10+

src/angular.suffix

-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
if (window.angular.bootstrap) {
2-
//AngularJS is already loaded, so we can return here...
3-
console.log('WARNING: Tried to load angular more than once.');
4-
return;
5-
}
6-
7-
//try to bind to jquery now so that one can write jqLite(document).ready()
8-
//but we will rebind on bootstrap again.
9-
bindJQuery();
10-
11-
publishExternalAPI(angular);
12-
131
jqLite(document).ready(function() {
142
angularInit(document, bootstrap);
153
});

src/ng/locale.js

-68
Original file line numberDiff line numberDiff line change
@@ -10,72 +10,4 @@
1010
*
1111
* * `id` – `{string}` – locale id formatted as `languageId-countryId` (e.g. `en-us`)
1212
*/
13-
function $LocaleProvider() {
14-
this.$get = function() {
15-
return {
16-
id: 'en-us',
1713

18-
NUMBER_FORMATS: {
19-
DECIMAL_SEP: '.',
20-
GROUP_SEP: ',',
21-
PATTERNS: [
22-
{ // Decimal Pattern
23-
minInt: 1,
24-
minFrac: 0,
25-
maxFrac: 3,
26-
posPre: '',
27-
posSuf: '',
28-
negPre: '-',
29-
negSuf: '',
30-
gSize: 3,
31-
lgSize: 3
32-
},{ //Currency Pattern
33-
minInt: 1,
34-
minFrac: 2,
35-
maxFrac: 2,
36-
posPre: '\u00A4',
37-
posSuf: '',
38-
negPre: '-\u00A4',
39-
negSuf: '',
40-
gSize: 3,
41-
lgSize: 3
42-
}
43-
],
44-
CURRENCY_SYM: '$'
45-
},
46-
47-
DATETIME_FORMATS: {
48-
MONTH:
49-
'January,February,March,April,May,June,July,August,September,October,November,December'
50-
.split(','),
51-
SHORTMONTH: 'Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec'.split(','),
52-
DAY: 'Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday'.split(','),
53-
SHORTDAY: 'Sun,Mon,Tue,Wed,Thu,Fri,Sat'.split(','),
54-
AMPMS: ['AM','PM'],
55-
medium: 'MMM d, y h:mm:ss a',
56-
'short': 'M/d/yy h:mm a',
57-
fullDate: 'EEEE, MMMM d, y',
58-
longDate: 'MMMM d, y',
59-
mediumDate: 'MMM d, y',
60-
shortDate: 'M/d/yy',
61-
mediumTime: 'h:mm:ss a',
62-
shortTime: 'h:mm a',
63-
ERANAMES: [
64-
"Before Christ",
65-
"Anno Domini"
66-
],
67-
ERAS: [
68-
"BC",
69-
"AD"
70-
]
71-
},
72-
73-
pluralCat: function(num) {
74-
if (num === 1) {
75-
return 'one';
76-
}
77-
return 'other';
78-
}
79-
};
80-
};
81-
}

test/ng/localeSpec.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
describe('$locale', function() {
44
/* global $LocaleProvider: false */
55

6-
var $locale = new $LocaleProvider().$get();
6+
var $locale;
7+
beforeEach(inject(function(_$locale_) {
8+
$locale = _$locale_;
9+
}));
710

811
it('should have locale id set to en-us', function() {
912
expect($locale.id).toBe('en-us');

0 commit comments

Comments
 (0)