angular-gettext icon indicating copy to clipboard operation
angular-gettext copied to clipboard

plural translate returns when translate-n is zero

Open depyronick opened this issue 9 years ago • 5 comments

for this example

<translate translate-n="model.userInfo.view_count | number" translate-plural="{{$count}} views">{{$count}} view</translate>

when $count is 0 it returns plural text

depyronick avatar Dec 25 '15 17:12 depyronick

That is correct behavior in English.

What were you expecting to happen here?

rubenv avatar Dec 25 '15 22:12 rubenv

Well, because of that could change according to different languages, we might want to show user different texts. For example I want to show our users when view count is zero: "No views here" and when it's one: "One post" and if more than 1, "$count posts". I think availability of setting this behaviour should be done by using a new attribute translate-zero or something else, instead of using if/else condition inside singularstr

depyronick avatar Dec 27 '15 11:12 depyronick

Well, because of that could change according to different languages

The formula used changes based on the language passed to setCurrentLanguage. See https://github.com/rubenv/angular-gettext/blob/master/src/plural.js

You need to specify an ISO language code such as tr or nl_BE.

rubenv avatar Dec 27 '15 18:12 rubenv

I would also like this feature. Angular's ngPluralize supports it, as does their new MessageFormat support, as does with MessageFormat. It may be outside the scope of an angular-gettext lib since technically it would still be correct grammar in English to say something like "0 apples". But it's usually more for friendly messaging since 0 can be so empty. "0 comments" vs "No comments yet. Add your voice!" Currently you have to have separate translation labels/logic to manage it.

hworld avatar Jan 13 '16 04:01 hworld

@hworld You'll have to go with that then. It was a conscious decision not to support this to keep things simple. There are other choices available when you want all the options, angular-gettext is, by design, simple.

rubenv avatar Jan 13 '16 06:01 rubenv