Skip to content

Commit

Permalink
refactor($locale): use en-us as generic built-in locale
Browse files Browse the repository at this point in the history
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 angular#12134
Closes angular#8174
  • Loading branch information
lgalfaso committed Jul 29, 2015
1 parent addb1ae commit 0037fd4
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 94 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ module.exports = function(grunt) {
files: { src: 'test/**/*.js' },
},
ng: {
files: { src: files['angularSrc'] },
files: { src: files['angularSrc'].concat('!src/angular.bind') },
},
ngAnimate: {
files: { src: 'src/ngAnimate/**/*.js' },
Expand Down
11 changes: 6 additions & 5 deletions angularFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ var angularFiles = {
'src/ng/httpBackend.js',
'src/ng/interpolate.js',
'src/ng/interval.js',
'src/ng/locale.js',
'src/ng/location.js',
'src/ng/log.js',
'src/ng/parse.js',
Expand Down Expand Up @@ -76,7 +75,10 @@ var angularFiles = {
'src/ng/directive/script.js',
'src/ng/directive/select.js',
'src/ng/directive/style.js',
'src/ng/directive/validators.js'
'src/ng/directive/validators.js',
'src/angular.bind',
'src/publishExternalApis.js',
'src/ngLocale/angular-locale_en-us.js'
],

'angularLoader': [
Expand Down Expand Up @@ -179,7 +181,6 @@ var angularFiles = {
'bower_components/jquery/dist/jquery.js',
'test/jquery_remove.js',
'@angularSrc',
'src/publishExternalApis.js',
'@angularSrcModules',
'@angularScenario',
'@angularTest'
Expand All @@ -188,7 +189,8 @@ var angularFiles = {
'karmaExclude': [
'test/jquery_alias.js',
'src/angular-bootstrap.js',
'src/ngScenario/angular-bootstrap.js'
'src/ngScenario/angular-bootstrap.js',
'src/angular.bind'
],

'karmaScenario': [
Expand All @@ -215,7 +217,6 @@ var angularFiles = {
'bower_components/jquery/dist/jquery.js',
'test/jquery_alias.js',
'@angularSrc',
'src/publishExternalApis.js',
'@angularSrcModules',
'@angularScenario',
'@angularTest'
Expand Down
6 changes: 0 additions & 6 deletions src/AngularPublic.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
/* global angularModule: true,
version: true,
$LocaleProvider,
$CompileProvider,
htmlAnchorDirective,
Expand Down Expand Up @@ -151,11 +150,6 @@ function publishExternalAPI(angular) {
});

angularModule = setupModuleLoader(window);
try {
angularModule('ngLocale');
} catch (e) {
angularModule('ngLocale', []).provider('$locale', $LocaleProvider);
}

angularModule('ng', ['ngLocale'], ['$provide',
function ngModule($provide) {
Expand Down
10 changes: 10 additions & 0 deletions src/angular.bind
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
if (window.angular.bootstrap) {
//AngularJS is already loaded, so we can return here...
console.log('WARNING: Tried to load angular more than once.');
return;
}

//try to bind to jquery now so that one can write jqLite(document).ready()
//but we will rebind on bootstrap again.
bindJQuery();

12 changes: 0 additions & 12 deletions src/angular.suffix
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
if (window.angular.bootstrap) {
//AngularJS is already loaded, so we can return here...
console.log('WARNING: Tried to load angular more than once.');
return;
}

//try to bind to jquery now so that one can write jqLite(document).ready()
//but we will rebind on bootstrap again.
bindJQuery();

publishExternalAPI(angular);

jqLite(document).ready(function() {
angularInit(document, bootstrap);
});
Expand Down
70 changes: 1 addition & 69 deletions src/ng/locale.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';
"use strict";

/**
* @ngdoc service
Expand All @@ -10,72 +10,4 @@
*
* * `id` – `{string}` – locale id formatted as `languageId-countryId` (e.g. `en-us`)
*/
function $LocaleProvider() {
this.$get = function() {
return {
id: 'en-us',

NUMBER_FORMATS: {
DECIMAL_SEP: '.',
GROUP_SEP: ',',
PATTERNS: [
{ // Decimal Pattern
minInt: 1,
minFrac: 0,
maxFrac: 3,
posPre: '',
posSuf: '',
negPre: '-',
negSuf: '',
gSize: 3,
lgSize: 3
},{ //Currency Pattern
minInt: 1,
minFrac: 2,
maxFrac: 2,
posPre: '\u00A4',
posSuf: '',
negPre: '-\u00A4',
negSuf: '',
gSize: 3,
lgSize: 3
}
],
CURRENCY_SYM: '$'
},

DATETIME_FORMATS: {
MONTH:
'January,February,March,April,May,June,July,August,September,October,November,December'
.split(','),
SHORTMONTH: 'Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec'.split(','),
DAY: 'Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday'.split(','),
SHORTDAY: 'Sun,Mon,Tue,Wed,Thu,Fri,Sat'.split(','),
AMPMS: ['AM','PM'],
medium: 'MMM d, y h:mm:ss a',
'short': 'M/d/yy h:mm a',
fullDate: 'EEEE, MMMM d, y',
longDate: 'MMMM d, y',
mediumDate: 'MMM d, y',
shortDate: 'M/d/yy',
mediumTime: 'h:mm:ss a',
shortTime: 'h:mm a',
ERANAMES: [
"Before Christ",
"Anno Domini"
],
ERAS: [
"BC",
"AD"
]
},

pluralCat: function(num) {
if (num === 1) {
return 'one';
}
return 'other';
}
};
};
}
5 changes: 4 additions & 1 deletion test/ng/localeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
describe('$locale', function() {
/* global $LocaleProvider: false */

var $locale = new $LocaleProvider().$get();
var $locale;
beforeEach(inject(function(_$locale_) {
$locale = _$locale_;
}));

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

0 comments on commit 0037fd4

Please sign in to comment.