The angular <eg-confirm-dialog> ignores i18n plural syntax in the dialogBody attribute

Bug #1809183 reported by Jane Sandberg
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Evergreen
Fix Released
Medium
Unassigned

Bug Description

The angular documentation describes some interesting things you can do with plural expressions: https://angular.io/guide/i18n#translating-plural-and-select-expressions

Based on that documentation, it seems like you should be able to write the following and have it choose the appropriate substring based on the value of numThings:

<eg-confirm-dialog #numberConfirmDialog
  i18n-dialogTitle i18n-dialogBody
  dialogTitle="Confirm Number"
  dialogBody="Are you sure you want to confirm {numThings, plural, =1 {this thing} other {these {{numThings}} things}}?">
</eg-confirm-dialog>

However, no matter the value of numThings, the confirm-dialog always just reads "Are you sure you want to confirm " and skips the rest of the string. :-(

Here's an example branch that adds some buttons to the bottom of the sandbox. Expected behavior is that you can click on the buttons and get a confirmation that repeats the number you clicked on, with appropriate plural or singular i18n. It's possible that I'm doing something wrong here, too, so let me know! Here's the branch: http://git.evergreen-ils.org/?p=working/Evergreen.git;a=shortlog;h=refs/heads/user/sandbergja/testing-out-confirmation-modal

Revision history for this message
Jane Sandberg (sandbergja) wrote :

Sorry, wrong link to the documentation. Should be this instead: https://angular.io/guide/i18n#regular-expressions-for-plurals-and-selections

Revision history for this message
Jane Sandberg (sandbergja) wrote :
Revision history for this message
Bill Erickson (berick) wrote :

Jane, I think the Angular issue is to blame. It looks like plurals in attributes won't be supported until they release the new Ivy rendering engine. (Possibly available in Angular 8 -- I have confirmed it's not in Angular 7 for bug #1801984).

I copied your test into a <div> in the sandbox and confirmed the pluralization works fine there.

We could still support pluralizations in the meantime by adding an option to the dialogs for users to pass string values via templates instead of attributes. Something like:

<ng-template #numThingsConfirmation let-numThings>
Are you sure you want to confirm {numThings, plural, =1 {this thing} other {these {{numThings}} things}}?
</ng-template>

<eg-confirm-dialog #numberConfirmDialog
  i18n-dialogTitle i18n-dialogBody
  dialogTitle="Confirm Number"
  dialogBodyTemplate="numThingsConfirmation">
</eg-confirm-dialog>

I would like to keep the attribute-passing option as well, though, since it's simpler for the common case.

Revision history for this message
Jane Sandberg (sandbergja) wrote :

Here's a branch that implements Bill's solution, as well as including a sandbox example. Enjoy!

The branch is called user/sandbergja/lp1809183-pass-templates-to-eg-confirm-dialog

Link: https://git.evergreen-ils.org/?p=working/Evergreen.git;a=shortlog;h=refs/heads/user/sandbergja/lp1809183-pass-templates-to-eg-confirm-dialog

tags: added: angular pullrequest
removed: webstaffclient
Bill Erickson (berick)
Changed in evergreen:
assignee: nobody → Bill Erickson (berick)
status: New → Confirmed
Revision history for this message
Bill Erickson (berick) wrote :

Thanks, Jane. Looks good. I have merged to master for 3.4. Since this is new-feature-ish and does not cleanly merge to rel_3_3, I opted not to backport for now. Could be done pretty easily though if needed.

Changed in evergreen:
milestone: none → 3.4-beta1
assignee: Bill Erickson (berick) → nobody
status: Confirmed → Fix Committed
Galen Charlton (gmc)
Changed in evergreen:
importance: Undecided → Medium
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.