Skip to content

Commit bb5bc50

Browse files
feat(chapter7): chapter 7 1st draft
1 parent 6a32d0d commit bb5bc50

File tree

11 files changed

+216
-0
lines changed

11 files changed

+216
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!doctype html>
2+
<html ng-app="locale">
3+
<head>
4+
<meta charset="utf-8">
5+
<script src="../../lib/angular/1.0.2/angular.js"></script>
6+
<script src="../../lib/angular/1.0.2/angular-locale_fr-ca.js"></script>
7+
<script src="locale.js"></script>
8+
</head>
9+
<body ng-controller="LocaleCtrl">
10+
<div>
11+
Locale id: {{localeid}}
12+
</div>
13+
<div>
14+
Months: {{months}}
15+
</div>
16+
</body>
17+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
angular.module('locale', ['ngLocale'])
2+
.controller('LocaleCtrl', function ($scope, $locale) {
3+
4+
$scope.localeid = $locale.id;
5+
6+
$scope.months = $locale.DATETIME_FORMATS.MONTH;
7+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
angular.module('filters', ['ngLocale'])
2+
3+
.controller('FiltersCtrl', function ($scope) {
4+
5+
$scope.now = new Date();
6+
7+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!doctype html>
2+
<html ng-app="filters">
3+
<head>
4+
<meta charset="utf-8">
5+
<script src="../../lib/angular/1.0.2/angular.js"></script>
6+
<script src="filters.js"></script>
7+
</head>
8+
<body ng-controller="FiltersCtrl">
9+
<div>Now: {{now | date:'fullDate'}}</div>
10+
<div>100: {{100 | currency}}</div>
11+
<div>100: {{100 | currency:'EUR'}}</div>
12+
<div>1000.5: {{1000.5 | number}}</div>
13+
</body>
14+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!doctype html>
2+
<html ng-app="filters">
3+
<head>
4+
<meta charset="utf-8">
5+
<script src="../../lib/angular/1.0.2/angular.js"></script>
6+
<script src="../../lib/angular/1.0.2/angular-locale_fr-fr.js"></script>
7+
<script src="filters.js"></script>
8+
</head>
9+
<body ng-controller="FiltersCtrl">
10+
<div>Now: {{now | date:'fullDate'}}</div>
11+
<div>100: {{100 | currency}}</div>
12+
<div>100: {{1000.5 | number}}</div>
13+
</body>
14+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
angular.module('i18nmessages', [])
2+
.value('i18nmessages', {
3+
'greetings.hello': 'Hello'
4+
});
5+
6+
angular.module('i18nfilter', ['i18nmessages'])
7+
.filter('i18n', function (i18nmessages) {
8+
return function (input) {
9+
if (!angular.isString(input)) {
10+
return input;
11+
}
12+
return i18nmessages[input] || '?'+input+'?';
13+
};
14+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!doctype html>
2+
<html ng-app="i18nfilter">
3+
<head>
4+
<meta charset="utf-8">
5+
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js"></script>
6+
<script src="i18nfilter.js"></script>
7+
</head>
8+
<body ng-init="name='World'">
9+
<span>{{'greetings.hello' | i18n}}, {{name}}!</span>
10+
</body>
11+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
angular.module('filterCustomization', [])
2+
.config(function ($provide) {
3+
var customFormats = {
4+
'fr-ca': {
5+
'fullDate': 'y'
6+
}
7+
};
8+
9+
$provide.decorator('dateFilter', function ($delegate, $locale) {
10+
return function (input, format) {
11+
return $delegate(input, customFormats[$locale.id][format] || format);
12+
};
13+
});
14+
})
15+
16+
.controller('DateCtrl', function ($scope) {
17+
$scope.now = new Date();
18+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html>
2+
<html ng-app="filterCustomization">
3+
<head>
4+
<meta charset="utf-8">
5+
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js"></script>
6+
<script src="../../lib/angular/1.0.2/angular-locale_fr-ca.js"></script>
7+
<script src="filterCustomization.js"></script>
8+
</head>
9+
<body ng-controller="DateCtrl">
10+
{{now | date:'fullDate'}}
11+
</body>
12+
</html>

lib/angular/1.0.2/angular-locale_fr-ca.js

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
angular.module("ngLocale", [], ["$provide", function($provide) {
2+
var PLURAL_CATEGORY = {ZERO: "zero", ONE: "one", TWO: "two", FEW: "few", MANY: "many", OTHER: "other"};
3+
$provide.value("$locale", {
4+
"DATETIME_FORMATS": {
5+
"AMPMS": {
6+
"0": "AM",
7+
"1": "PM"
8+
},
9+
"DAY": {
10+
"0": "dimanche",
11+
"1": "lundi",
12+
"2": "mardi",
13+
"3": "mercredi",
14+
"4": "jeudi",
15+
"5": "vendredi",
16+
"6": "samedi"
17+
},
18+
"MONTH": {
19+
"0": "janvier",
20+
"1": "février",
21+
"2": "mars",
22+
"3": "avril",
23+
"4": "mai",
24+
"5": "juin",
25+
"6": "juillet",
26+
"7": "août",
27+
"8": "septembre",
28+
"9": "octobre",
29+
"10": "novembre",
30+
"11": "décembre"
31+
},
32+
"SHORTDAY": {
33+
"0": "dim.",
34+
"1": "lun.",
35+
"2": "mar.",
36+
"3": "mer.",
37+
"4": "jeu.",
38+
"5": "ven.",
39+
"6": "sam."
40+
},
41+
"SHORTMONTH": {
42+
"0": "janv.",
43+
"1": "févr.",
44+
"2": "mars",
45+
"3": "avr.",
46+
"4": "mai",
47+
"5": "juin",
48+
"6": "juil.",
49+
"7": "août",
50+
"8": "sept.",
51+
"9": "oct.",
52+
"10": "nov.",
53+
"11": "déc."
54+
},
55+
"fullDate": "EEEE d MMMM y",
56+
"longDate": "d MMMM y",
57+
"medium": "d MMM y HH:mm:ss",
58+
"mediumDate": "d MMM y",
59+
"mediumTime": "HH:mm:ss",
60+
"short": "dd/MM/yy HH:mm",
61+
"shortDate": "dd/MM/yy",
62+
"shortTime": "HH:mm"
63+
},
64+
"NUMBER_FORMATS": {
65+
"CURRENCY_SYM": "€",
66+
"DECIMAL_SEP": ",",
67+
"GROUP_SEP": " ",
68+
"PATTERNS": {
69+
"0": {
70+
"gSize": 3,
71+
"lgSize": 3,
72+
"macFrac": 0,
73+
"maxFrac": 3,
74+
"minFrac": 0,
75+
"minInt": 1,
76+
"negPre": "-",
77+
"negSuf": "",
78+
"posPre": "",
79+
"posSuf": ""
80+
},
81+
"1": {
82+
"gSize": 3,
83+
"lgSize": 3,
84+
"macFrac": 0,
85+
"maxFrac": 2,
86+
"minFrac": 2,
87+
"minInt": 1,
88+
"negPre": "(",
89+
"negSuf": " \u00A4)",
90+
"posPre": "",
91+
"posSuf": " \u00A4"
92+
}
93+
}
94+
},
95+
"id": "fr-fr",
96+
"pluralCat": function (n) { if (n >= 0 && n <= 2 && n != 2) { return PLURAL_CATEGORY.ONE; } return PLURAL_CATEGORY.OTHER;}
97+
});
98+
}]);

0 commit comments

Comments
 (0)