@@ -156,8 +156,94 @@ The syntax extension is based on a subset of the ICU MessageFormat syntax that c
156156gender selections. Please refer to the links in the “Further Reading” section at the bottom of this
157157section.
158158
159- You may find it helpful to play with our [Plnkr Example](http://plnkr.co/edit/QBVRQ70dvKZDWmHW9RyR?p=preview)
160- as you read the examples below.
159+ You may find it helpful to play with the following example as you read the explanations below:
160+
161+ <example name="message-format-example" module="messageFormatExample" deps="angular-message-format.js">
162+ <file name="index.html">
163+ <div ng-controller="ckCtrl">
164+ <b>Set number of recipients</b>
165+ <button ng-click="setNumRecipients(0)">None</button>
166+ <button ng-click="setNumRecipients(1)">One</button>
167+ <button ng-click="setNumRecipients(2)">Two</button>
168+ <button ng-click="setNumRecipients(3)">Three</button>
169+
170+
171+ <br><br>
172+ <b>Sender's</b> name: <input ng-model="sender.name">
173+
174+ <br><br><b>Recipients</b><br>
175+ <div ng-repeat="recipient in recipients">
176+ Name: <input ng-model="recipient.name">
177+ Gender: <button ng-click="setGender(recipient, 'male')">male</button>
178+ <button ng-click="setGender(recipient, 'female')">female</button>
179+ <button ng-click="setGender(recipient, 'other')">other</button>
180+ </div>
181+
182+ <br><br><b>Message</b><br>
183+ {{recipients.length, plural, offset:1
184+ =0 {You ({{sender.name}}) gave no gifts}
185+ =1 { {{ recipients[0].gender, select,
186+ male {You ({{sender.name}}) gave him ({{recipients[0].name}}) a gift.}
187+ female {You ({{sender.name}}) gave her ({{recipients[0].name}}) a gift.}
188+ other {You ({{sender.name}}) gave them ({{recipients[0].name}}) a gift.}
189+ }}
190+ }
191+ one { {{ recipients[0].gender, select,
192+ male {You ({{sender.name}}) gave him ({{recipients[0].name}}) and one other person a gift.}
193+ female {You ({{sender.name}}) gave her ({{recipients[0].name}}) and one other person a gift.}
194+ other {You ({{sender.name}}) gave them ({{recipients[0].name}}) and one other person a gift.}
195+ }}
196+ }
197+ other {You ({{sender.name}}) gave {{recipients.length}} people gifts. }
198+ }}
199+
200+ <br><br><b>In an attribute</b><br>
201+ <div attrib="{{recipients.length, plural, offset:1
202+ =0 {You ({{sender.name}}) gave no gifts}
203+ =1 { {{ recipients[0].gender, select,
204+ male {You ({{sender.name}}) gave him ({{recipients[0].name}}) a gift.}
205+ female {You ({{sender.name}}) gave her ({{recipients[0].name}}) a gift.}
206+ other {You ({{sender.name}}) gave them ({{recipients[0].name}}) a gift.}
207+ }}
208+ }
209+ one { {{ recipients[0].gender, select,
210+ male {You ({{sender.name}}) gave him ({{recipients[0].name}}) and one other person a gift.}
211+ female {You ({{sender.name}}) gave her ({{recipients[0].name}}) and one other person a gift.}
212+ other {You ({{sender.name}}) gave them ({{recipients[0].name}}) and one other person a gift.}
213+ }}
214+ }
215+ other {You ({{sender.name}}) gave {{recipients.length}} people gifts. }
216+ }}">
217+ This div has an attribute interpolated with messageformat. Use the DOM inspector to check it out.
218+ </div>
219+ </div>
220+ </file>
221+ <file name="app.js">
222+ function Person(name, gender) {
223+ this.name = name;
224+ this.gender = gender;
225+ }
226+
227+ angular.module('messageFormatExample', ['ngMessageFormat'])
228+ .controller('ckCtrl', function ($scope, $injector, $parse) {
229+ var people = [ new Person("Alice", "female"),
230+ new Person("Bob", "male"),
231+ new Person("Charlie", "male") ];
232+
233+ $scope.sender = new Person("Harry Potter", "male");
234+ $scope.recipients = people.slice();
235+
236+ $scope.setNumRecipients = function(n) {
237+ n = n > people.length ? people.length : n;
238+ $scope.recipients = people.slice(0, n);
239+ };
240+
241+ $scope.setGender = function(person, gender) {
242+ person.gender = gender;
243+ };
244+ });
245+ </file>
246+ </example>
161247
162248### Plural Syntax
163249
@@ -333,9 +419,9 @@ allows you to nest plural and gender expressions in any order.
333419Please note that if these are intended to reach a translator and be translated, it is recommended
334420that the messages appear as a whole and not be split up.
335421
336- ### More complex example that demonstrates nesting
422+ ### Demonstration of nesting
337423
338- This is taken from the [plunker example](http://plnkr.co/edit/QBVRQ70dvKZDWmHW9RyR?p=preview) linked to earlier .
424+ This is taken from the above example.
339425
340426```text
341427{{recipients.length, plural, offset:1
0 commit comments