Skip to content
New issue

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

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

Already on GitHub? # to your account

getPluralIndex return value bug fixed #3

Merged
merged 2 commits into from
Oct 12, 2017
Merged

getPluralIndex return value bug fixed #3

merged 2 commits into from
Oct 12, 2017

Conversation

procket-org
Copy link
Contributor

getPluralIndex should return index, not boolean

getPluralIndex should return index, not boolean
@oscarotero
Copy link
Member

In theory, the plural function should return an integer, and not always is 0 or 1, but in some languages there's more plurals. Are you using a correct plural funcion?

@procket-org
Copy link
Contributor Author

procket-org commented Oct 12, 2017

更新 %s 条: ["%s item updated", "%s items updated"]
This is the plural translation of one item in json file, it's no working when i call n__(original, plural, value).

dnpgettext: function (domain, context, original, plural, value) {

        var index = getPluralIndex(this.plurals, domain, value);   // return boolean

        var translation = getTranslation(this.dictionary, domain, context, original);

        if (translation[index] && translation[index] !== '') {  // index not found
            return translation[index];
        }

        return (index === 0) ? original : plural;  // not translated, just return param plural

}

After reading the gnu doc:
https://www.gnu.org/savannah-checkouts/gnu/gettext/manual/html_node/Plural-forms.html
(Note: this uses the feature of C expressions that boolean expressions have to value zero or one)
This is the correct fix.
@oscarotero
Copy link
Member

What I want to see is the plural function that returns a boolean instead an integer, or in other words, the content of plurals[domain].code

@procket-org
Copy link
Contributor Author

When plural form is
Plural-Forms: nplurals=2; plural=n != 1;
The code will be
return n != 1;

The doc from GNU gettext

Two forms, singular used for one only
This is the form used in most existing programs since it is what English is using. A header entry would look like this:

Plural-Forms: nplurals=2; plural=n != 1;
(Note: this uses the feature of C expressions that boolean expressions have to value zero or one.)

@oscarotero oscarotero merged commit 30744b5 into php-gettext:master Oct 12, 2017
@oscarotero
Copy link
Member

Ok, understood.
Thank you! 👍

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants