Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Plural): A logic bug in plural #313

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

abruzzihraig
Copy link

Guys, I found a plural bug when I was developing with your library.

In your original code there is a line:

prefixDebug(n === 1 ? string : stringPlural);

That means the 'n' must be a Number rather than a String or something else.

But how did you get the 'n'? I found that you did something like this:

$parse(attrs.translateN)(scope)

That means if the translateN on attrs is a String, the 'n' will be String as well. Then you will never get a right plural result when the count changing.

So I just made the change to ensure the logic is safe.

And I think maybe it also fixed the issue #305 and the similar other ones.

@rubenv
Copy link
Owner

rubenv commented Sep 21, 2016

@abruzzihraig I'm pretty sure that functionality works. Nonetheless, if we want to get this in, you'll need to add a unit test, which fails without the fix applied.

@abruzzihraig
Copy link
Author

So if you pretty sure that functionality works, why I can get this:

I was totally followed by the developer guide.

On Wed, Sep 21, 2016 at 18:25 Ruben Vermeersch [email protected]
wrote:

@abruzzihraig https://github.com/abruzzihraig I'm pretty sure that
functionality works. Nonetheless, if we want to get this in, you'll need to
add a unit test, which fails without the fix applied.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#313 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ADM3a0qMohq_oMoDaNyyr5dBIeCF3Vtcks5qsOnwgaJpZM4KCgYo
.

Yang He

@rubenv
Copy link
Owner

rubenv commented Sep 21, 2016

Note that we have a test that tests exactly this:

it("Changing the scope should update the translation, changed count", function () {
$rootScope.count = 3;
var el = $compile("<div><div translate translate-n=\"count\" translate-plural=\"{{count}} boats\">One boat</div></div>")($rootScope);
$rootScope.$digest();
assert.equal(el.text(), "3 boats");
$rootScope.$apply(function () {
$rootScope.count = 1;
});
assert.equal(el.text(), "One boat");
});

@zhuangya
Copy link

@rubenv when input bind to something like activity.length as in #305, after the value changed, typeof activity.length would become string rather than number.

i think angular-gettext should handle this situation.

you can have a look at the page below
https://gist.github.com/zhuangya/38476c504d29d39d8d2bfae5e11b5060

:)

also cc @sebrojas14

zhuangya added a commit to zhuangya/angular-gettext that referenced this pull request Sep 26, 2016
@@ -313,7 +313,7 @@ angular.module('gettext').factory('gettextCatalog', ["gettextPlurals", "gettextF
var fallbackLanguage = gettextFallbackLanguage(this.currentLanguage);
string = this.getStringFormFor(this.currentLanguage, string, n, context) ||
this.getStringFormFor(fallbackLanguage, string, n, context) ||
prefixDebug(n === 1 ? string : stringPlural);
prefixDebug(n == 1 ? string : stringPlural);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but i think it would be better if convert n to number :/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, there should be a new test case for this.

zhuangya added a commit to zhuangya/angular-gettext that referenced this pull request Sep 26, 2016
@zhuangya
Copy link

zhuangya commented Oct 8, 2016

update: living demo on jsfiddle goes here: https://jsfiddle.net/hxv260y6/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants