forked from angular/angular.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat($interpolate): extend interpolation with MessageFormat like syntax
For more detailed information refer to this document: 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.js` or `angular-messageformat.min.js`. In addition, your application module should depend on the "ngMessageFormat" (e.g. angular.module('myApp', ['ngMessageFormat']);) When you use the `ngMessageFormat`, the $interpolate gets overridden with a new service that adds the new MessageFormat behavior. **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 the features availability for that syntax.) - The first part of such a 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 yet supported. Closes angular#11152
- Loading branch information
1 parent
170ff9a
commit 1e58488
Showing
26 changed files
with
1,916 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@ngdoc error | ||
@name $interpolate:badexpr | ||
@fullName Expecting end operator | ||
@description | ||
|
||
The Angular expression is missing the corresponding closing operator. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@ngdoc error | ||
@name $interpolate:dupvalue | ||
@fullName Duplicate choice in plural/select | ||
@description | ||
|
||
You have repeated a match selection for your plural or select MessageFormat | ||
extension in your interpolation expression. The different choices have to be unique. | ||
|
||
For more information about the MessageFormat syntax in interpolation | ||
expressions, please refer to MessageFormat extensions section at | ||
{@link guide/i18n#MessageFormat Angular i18n MessageFormat} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@ngdoc error | ||
@name $interpolate:logicbug | ||
@fullName Bug in ngMessageFormat module | ||
@description | ||
|
||
You've just hit a bug in the ngMessageFormat module provided by angular-messageFormat.min.js. | ||
Please file a github issue for this and provide the interpolation text that caused you to hit this | ||
bug mentioning the exact version of AngularJS used and we will fix it! | ||
|
||
For more information about the MessageFormat syntax in interpolation | ||
expressions, please refer to MessageFormat extensions section at | ||
{@link guide/i18n#MessageFormat Angular i18n MessageFormat} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
@ngdoc error | ||
@name $interpolate:nochgmustache | ||
@fullName Redefinition of start/endSymbol incompatible with MessageFormat extensions | ||
@description | ||
|
||
You have redefined `$interpolate.startSymbol`/`$interpolate.endSymbol` and also | ||
loaded the `ngMessageFormat` module (provided by angular-messageFormat.min.js) | ||
while creating your injector. | ||
|
||
`ngMessageFormat` currently does not support redefinition of the | ||
startSymbol/endSymbol used by `$interpolate`. If this is affecting you, please | ||
file an issue and mention @chirayuk on it. This is intended to be fixed in a | ||
future commit and the github issue will help gauge urgency. | ||
|
||
For more information about the MessageFormat syntax in interpolation | ||
expressions, please refer to MessageFormat extensions section at | ||
{@link guide/i18n#MessageFormat Angular i18n MessageFormat} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@ngdoc error | ||
@name $interpolate:reqarg | ||
@fullName Missing required argument for MessageFormat | ||
@description | ||
|
||
You must specify the MessageFormat function that you're using right after the | ||
comma following the Angular expression. Currently, the supported functions are | ||
"plural" and "select" (for gender selections.) | ||
|
||
For more information about the MessageFormat syntax in interpolation | ||
expressions, please refer to MessageFormat extensions section at | ||
{@link guide/i18n#MessageFormat Angular i18n MessageFormat} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@ngdoc error | ||
@name $interpolate:reqcomma | ||
@fullName Missing comma following MessageFormat plural/select keyword | ||
@description | ||
|
||
The MessageFormat syntax requires a comma following the "plural" or "select" | ||
extension keyword in the extended interpolation syntax. | ||
|
||
For more information about the MessageFormat syntax in interpolation | ||
expressions, please refer to MessageFormat extensions section at | ||
{@link guide/i18n#MessageFormat Angular i18n MessageFormat} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@ngdoc error | ||
@name $interpolate:reqendbrace | ||
@fullName Unterminated message for plural/select value | ||
@description | ||
|
||
The plural or select message for a value or keyword choice has no matching end | ||
brace to mark the end of the message. | ||
|
||
For more information about the MessageFormat syntax in interpolation | ||
expressions, please refer to MessageFormat extensions section at | ||
{@link guide/i18n#MessageFormat Angular i18n MessageFormat} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@ngdoc error | ||
@name $interpolate:reqendinterp | ||
@fullName Unterminated interpolation | ||
@description | ||
|
||
The interpolation text does not have an ending `endSymbol` ("}}" by default) and is unterminated. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@ngdoc error | ||
@name $interpolate:reqopenbrace | ||
@fullName An opening brace was expected but not found | ||
@description | ||
|
||
The plural or select extension keyword or values (such as "other", "male", | ||
"female", "=0", "one", "many", etc.) MUST be followed by a message enclosed in | ||
braces. | ||
|
||
For more information about the MessageFormat syntax in interpolation | ||
expressions, please refer to MessageFormat extensions section at | ||
{@link guide/i18n#MessageFormat Angular i18n MessageFormat} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
@ngdoc error | ||
@name $interpolate:reqother | ||
@fullName Required choice "other" for select/plural in MessageFormat | ||
@description | ||
|
||
Your interpolation expression with a MessageFormat extension for either | ||
"plural" or "select" (typically used for gender selection) does not contain a | ||
message for the choice "other". Using either select or plural MessageFormat | ||
extensions require that you provide a message for the selection "other". | ||
|
||
For more information about the MessageFormat syntax in interpolation | ||
expressions, please refer to MessageFormat extensions section at | ||
{@link guide/i18n#MessageFormat Angular i18n MessageFormat} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@ngdoc error | ||
@name $interpolate:unknarg | ||
@fullName Unrecognized MessageFormat extension | ||
@description | ||
|
||
The MessageFormat extensions provided by `ngMessageFormat` are currently | ||
limited to "plural" and "select". The extension that you have used is either | ||
unsupported or invalid. | ||
|
||
For more information about the MessageFormat syntax in interpolation | ||
expressions, please refer to MessageFormat extensions section at | ||
{@link guide/i18n#MessageFormat Angular i18n MessageFormat} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@ngdoc error | ||
@name $interpolate:unsafe | ||
@fullName MessageFormat extensions not allowed in secure context | ||
@description | ||
|
||
You have attempted to use a MessageFormat extension in your interpolation expression that is marked as a secure context. For security purposes, this is not supported. | ||
|
||
Read more about secure contexts at {@link ng.$sce Strict Contextual Escaping | ||
(SCE)} and about the MessageFormat extensions at {@link | ||
guide/i18n#MessageFormat Angular i18n MessageFormat}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@ngdoc error | ||
@name $interpolate:untermstr | ||
@fullName Unterminated string literal | ||
@description | ||
|
||
The string literal was not terminated in your Angular expression. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
@ngdoc error | ||
@name $interpolate:wantstring | ||
@fullName Expected the beginning of a string | ||
@description | ||
|
||
We expected to see the beginning of a string (either a single quote or a double | ||
quote character) in the expression but it was not found. The expression is | ||
invalid. If this is incorrect, please file an issue on github. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.