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

Commit 058d462

Browse files
committedJul 27, 2015
revert: refactor($locale): use en-us as generic built-in locale
This reverts commit 70ce425. There are internal projects in Google that generate their own version of angular.js and so this commit caused those projects to break. We are going to look into a more satisfactory way of getting this change in.
1 parent f91eb0e commit 058d462

File tree

7 files changed

+145
-33
lines changed

7 files changed

+145
-33
lines changed
 

‎Gruntfile.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,7 @@ module.exports = function(grunt) {
175175
},
176176
angular: {
177177
dest: 'build/angular.js',
178-
src: util.wrap([files['angularSrc']], 'angular')
179-
.concat('src/ngLocale/angular-locale_en-us.js'),
178+
src: util.wrap([files['angularSrc']], 'angular'),
180179
styles: {
181180
css: ['css/angular.css'],
182181
generateCspCssFile: true,

‎angularFiles.js

+6-10
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var angularFiles = {
2525
'src/ng/httpBackend.js',
2626
'src/ng/interpolate.js',
2727
'src/ng/interval.js',
28+
'src/ng/locale.js',
2829
'src/ng/location.js',
2930
'src/ng/log.js',
3031
'src/ng/parse.js',
@@ -181,8 +182,7 @@ var angularFiles = {
181182
'src/publishExternalApis.js',
182183
'@angularSrcModules',
183184
'@angularScenario',
184-
'@angularTest',
185-
'src/ngLocale/angular-locale_en-us.js' // we need an ngLocale module
185+
'@angularTest'
186186
],
187187

188188
'karmaExclude': [
@@ -193,13 +193,12 @@ var angularFiles = {
193193

194194
'karmaScenario': [
195195
'build/angular-scenario.js',
196-
'build/docs/docs-scenario.js',
197-
'src/ngLocale/angular-locale_en-us.js' // we need an ngLocale module
196+
'build/docs/docs-scenario.js'
198197
],
199198

200199
"karmaModules": [
201200
'build/angular.js',
202-
'@angularSrcModules',,
201+
'@angularSrcModules',
203202
'src/ngScenario/browserTrigger.js',
204203
'test/helpers/*.js',
205204
'test/ngMessageFormat/*.js',
@@ -209,8 +208,7 @@ var angularFiles = {
209208
'test/ngResource/*.js',
210209
'test/ngSanitize/**/*.js',
211210
'test/ngTouch/**/*.js',
212-
'test/ngAria/*.js',
213-
'src/ngLocale/angular-locale_en-us.js' // we need an ngLocale module
211+
'test/ngAria/*.js'
214212
],
215213

216214
'karmaJquery': [
@@ -220,9 +218,7 @@ var angularFiles = {
220218
'src/publishExternalApis.js',
221219
'@angularSrcModules',
222220
'@angularScenario',
223-
'@angularTest',
224-
'src/ngLocale/angular-locale_en-us.js' // we need an ngLocale module
225-
221+
'@angularTest'
226222
],
227223

228224
'karmaJqueryExclude': [

‎docs/content/guide/i18n.ngdoc

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ directive}. Additionally, you can use {@link guide/i18n#messageformat-extension
2323
`$interpolate` for localizable pluralization and gender support in all interpolations via the
2424
`ngMessageFormat` module.
2525

26-
All localizable Angular components depend on locale-specific rule sets managed by the
27-
{@link ngLocale `$locale` service}.
26+
All localizable Angular components depend on locale-specific rule sets managed by the {@link
27+
ng.$locale `$locale` service}.
2828

2929
There a few examples that showcase how to use Angular filters with various locale rule sets in the
3030
[`i18n/e2e` directory](https://github.com/angular/angular.js/tree/master/i18n/e2e) of the Angular
@@ -99,7 +99,7 @@ develop your app.
9999
### Currency symbol
100100

101101
Angular's {@link ng.filter:currency currency filter} allows you to use the default currency symbol
102-
from the {@link ngLocale `locale` service}, or you can provide the filter with a custom currency
102+
from the {@link ng.$locale locale service}, or you can provide the filter with a custom currency
103103
symbol.
104104

105105
<div class="alert alert-success">

‎src/AngularPublic.js

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/* global angularModule: true,
44
version: true,
55
6+
$LocaleProvider,
67
$CompileProvider,
78
89
htmlAnchorDirective,
@@ -150,6 +151,11 @@ function publishExternalAPI(angular) {
150151
});
151152

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

154160
angularModule('ng', ['ngLocale'], ['$provide',
155161
function ngModule($provide) {

‎src/ng/locale.js

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
'use strict';
2+
3+
/**
4+
* @ngdoc service
5+
* @name $locale
6+
*
7+
* @description
8+
* $locale service provides localization rules for various Angular components. As of right now the
9+
* only public api is:
10+
*
11+
* * `id` – `{string}` – locale id formatted as `languageId-countryId` (e.g. `en-us`)
12+
*/
13+
function $LocaleProvider() {
14+
this.$get = function() {
15+
return {
16+
id: 'en-us',
17+
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+
}

‎src/ngLocale/index.js

-18
This file was deleted.

‎test/ng/localeSpec.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
'use strict';
2+
3+
describe('$locale', function() {
4+
/* global $LocaleProvider: false */
5+
6+
var $locale = new $LocaleProvider().$get();
7+
8+
it('should have locale id set to en-us', function() {
9+
expect($locale.id).toBe('en-us');
10+
});
11+
12+
13+
it('should have NUMBER_FORMATS', function() {
14+
var numberFormats = $locale.NUMBER_FORMATS;
15+
expect(numberFormats).toBeDefined();
16+
expect(numberFormats.PATTERNS.length).toBe(2);
17+
angular.forEach(numberFormats.PATTERNS, function(pattern) {
18+
expect(pattern.minInt).toBeDefined();
19+
expect(pattern.minFrac).toBeDefined();
20+
expect(pattern.maxFrac).toBeDefined();
21+
expect(pattern.posPre).toBeDefined();
22+
expect(pattern.posSuf).toBeDefined();
23+
expect(pattern.negPre).toBeDefined();
24+
expect(pattern.negSuf).toBeDefined();
25+
expect(pattern.gSize).toBeDefined();
26+
expect(pattern.lgSize).toBeDefined();
27+
});
28+
});
29+
30+
31+
it('should have DATETIME_FORMATS', function() {
32+
var datetime = $locale.DATETIME_FORMATS;
33+
expect(datetime).toBeDefined();
34+
expect(datetime.DAY.length).toBe(7);
35+
expect(datetime.SHORTDAY.length).toBe(7);
36+
expect(datetime.SHORTMONTH.length).toBe(12);
37+
expect(datetime.MONTH.length).toBe(12);
38+
expect(datetime.AMPMS.length).toBe(2);
39+
});
40+
41+
42+
it('should return correct plural types', function() {
43+
expect($locale.pluralCat(-1)).toBe('other');
44+
expect($locale.pluralCat(0)).toBe('other');
45+
expect($locale.pluralCat(2)).toBe('other');
46+
expect($locale.pluralCat(1)).toBe('one');
47+
});
48+
});

0 commit comments

Comments
 (0)
This repository has been archived.