Skip to content

i18nPluralPipe errors #25

@jim-coffey

Description

@jim-coffey

Chapter04 issue initially

OK, so I've been using Angular 2.0.0-rc.4 so maybe these are my own fault, but the i18nPlural pipe filter doesn't work with the provided code.

In order to make it work I had to do the following inside the .ts file :

Import the NgLocalization provider

import {
  NgLocalization
} from '@angular/common';

Extend the class to define a getPluralCategory method on it

class MessagesLocalization extends NgLocalization {
  getPluralCategory(value: any) {
    if (value > 1) {
      return 'other';
    }
  }
}

Inject the extended provider in to the bootstrap, although I think you can also add it to the providers key of the component individually

bootstrap(TasksComponent, [{provide: NgLocalization, useClass: MessagesLocalization}]);

Not sure if this area of angular2 just needs further development, or if this is the ideal fix going forward.

There are other angular2 plugins that can be used and injected to make the functionality work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions