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

Commit d91e802

Browse files
committed
feat($interpolate): MessageFormat extensions
Extend interpolation with MessageFormat like syntax. Ref: <https://docs.google.com/a/google.com/document/d/1pbtW2yvtmFBikfRrJd8VAsabiFkKezmYZ_PbgdjQOVU/edit> Example: ```html {{recipients.length, plural, offset:1 =0 {You gave no gifts} =1 { {{ recipients[0].gender, select, male {You gave him a gift.} female {You gave her a gift.} other {You gave them a gift.} }} } one { {{ recipients[0].gender, select, male {You gave him and one other person a gift.} female {You gave her and one other person a gift.} other {You gave them and one other person a gift.} }} } other {You gave {{recipients[0].gender}} and # other people gifts. } }} ``` This is a SEPARATE module so you MUST include angular-messageformat.min.js. In addition, your application module should depend on the "ngMessageFormat". (e.g. angular.module('myApp', ['ngMessageFormat']);) $interpolate automatically gets the new behavior. Quick note on syntax differences from MessageFormat: - MessageFormat directives are always inside {{ }} instead of single { }. This ensures a consistent interpolation syntax (else you could interpolate in more than one way and have to pick one based on feature availability for that syntax.) - The first word inside such syntax can be an arbitrary Angular expression instead of a single identifier. - You can nest them as deep as you want. As mentioned earlier, you would use {{ }} to start the nested interpolation that may optionally include select/plural extensions. - Only "select" and "plural" keywords are currently recognized. - Quoting support is coming in a future commit. - Positional arguments/placeholders are not supported. They don't make sense in Angular templates anyway (they are only helpful when using API calls from a programming language.) - Redefining of the startSymbol and endSymbol used for interpolation is not currently supported yet.
1 parent bfd7b22 commit d91e802

File tree

9 files changed

+1646
-1
lines changed

9 files changed

+1646
-1
lines changed

Gruntfile.js

+8
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ module.exports = function(grunt) {
126126
ngLocale: {
127127
files: { src: 'src/ngLocale/**/*.js' },
128128
},
129+
ngMessageFormat: {
130+
files: { src: 'src/ngMessageFormat/**/*.js' },
131+
},
129132
ngMessages: {
130133
files: { src: 'src/ngMessages/**/*.js' },
131134
},
@@ -200,6 +203,10 @@ module.exports = function(grunt) {
200203
dest: 'build/angular-resource.js',
201204
src: util.wrap(files['angularModules']['ngResource'], 'module')
202205
},
206+
messageformat: {
207+
dest: 'build/angular-messageformat.js',
208+
src: util.wrap(files['angularModules']['ngMessageFormat'], 'module_closure')
209+
},
203210
messages: {
204211
dest: 'build/angular-messages.js',
205212
src: util.wrap(files['angularModules']['ngMessages'], 'module')
@@ -232,6 +239,7 @@ module.exports = function(grunt) {
232239
animate: 'build/angular-animate.js',
233240
cookies: 'build/angular-cookies.js',
234241
loader: 'build/angular-loader.js',
242+
messageformat: 'build/angular-messageformat.js',
235243
messages: 'build/angular-messages.js',
236244
touch: 'build/angular-touch.js',
237245
resource: 'build/angular-resource.js',

angularFiles.js

+5
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ var angularFiles = {
9191
'ngCookies': [
9292
'src/ngCookies/cookies.js'
9393
],
94+
'ngMessageFormat': [
95+
'src/ngMessageFormat/messageformat.js'
96+
],
9497
'ngMessages': [
9598
'src/ngMessages/messages.js'
9699
],
@@ -181,6 +184,7 @@ var angularFiles = {
181184
'@angularSrcModules',
182185
'src/ngScenario/browserTrigger.js',
183186
'test/helpers/*.js',
187+
'test/ngMessageFormat/*.js',
184188
'test/ngMock/*.js',
185189
'test/ngCookies/*.js',
186190
'test/ngRoute/**/*.js',
@@ -209,6 +213,7 @@ var angularFiles = {
209213

210214
angularFiles['angularSrcModules'] = [].concat(
211215
angularFiles['angularModules']['ngAnimate'],
216+
angularFiles['angularModules']['ngMessageFormat'],
212217
angularFiles['angularModules']['ngMessages'],
213218
angularFiles['angularModules']['ngCookies'],
214219
angularFiles['angularModules']['ngResource'],

lib/grunt/utils.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,22 @@ module.exports = {
185185
var mapFileName = mapFile.match(/[^\/]+$/)[0];
186186
var errorFileName = file.replace(/\.js$/, '-errors.json');
187187
var versionNumber = grunt.config('NG_VERSION').full;
188+
var compilationLevel = 'SIMPLE_OPTIMIZATIONS';
189+
var googDEBUG = '';
190+
if (file === 'build/angular-messageformat.js') {
191+
var compilationLevel = 'ADVANCED_OPTIMIZATIONS';
192+
var googDEBUG = '--define goog.DEBUG=false ';
193+
}
188194
shell.exec(
189195
'java ' +
190196
this.java32flags() + ' ' +
191197
'-Xmx2g ' +
192198
'-cp bower_components/closure-compiler/compiler.jar' + classPathSep +
193199
'bower_components/ng-closure-runner/ngcompiler.jar ' +
194200
'org.angularjs.closurerunner.NgClosureRunner ' +
195-
'--compilation_level SIMPLE_OPTIMIZATIONS ' +
201+
'--compilation_level ' + compilationLevel + ' ' +
196202
'--language_in ECMASCRIPT5_STRICT ' +
203+
googDEBUG +
197204
'--minerr_pass ' +
198205
'--minerr_errors ' + errorFileName + ' ' +
199206
'--minerr_url http://errors.angularjs.org/' + versionNumber + '/ ' +

src/module_closure.prefix

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* @license AngularJS v"NG_VERSION_FULL"
3+
* (c) 2010-2015 Google, Inc. http://angularjs.org
4+
* License: MIT
5+
*/
6+
/** @const */
7+
var goog = goog || {};
8+
/** @define {boolean} */
9+
goog.DEBUG = true;
10+
(function(window, angular, undefined) {

src/module_closure.suffix

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
})(window, window.angular);

src/ng/interpolate.js

+1
Original file line numberDiff line numberDiff line change
@@ -347,3 +347,4 @@ function $InterpolateProvider() {
347347
}];
348348
}
349349

350+

0 commit comments

Comments
 (0)