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 pluralization in default domain for non-germanic languages #2859

Merged

Conversation

MatthewWilkes
Copy link
Contributor

This is a reimplementation of PR #2102 which is less invasive and tracks the bug to its original location.

When loading a new .mo file, Pyramid checks if the domain already exists, and if so it merges the new catalog into the old one. It does not update the plural function when this happens, as it's assumed that it is consistent inside a domain.

The default domain is a special case, as it contains the other domains in a dictionary, so it is created ahead of time with an empty catalog, and the default pluralisation rule from #235. As all other files in the messages domain will be merged to this catalog, the plural rule is never overwritten.

This change introduces a flag to state if the default plural from #235 has been overridden. When merging two translations it checks if the domain is the default domain, and if the flag isn't set it replaces the plural lambda expression with the gettext generated one and sets the flag.

# It doesn't override the previously loaded rule
self.assertEqual(inst.plural(0), 0)
self.assertEqual(inst.plural(1), 0)
self.assertEqual(inst.plural(2), 1)
Copy link
Member

Choose a reason for hiding this comment

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

I don't have a lot of translation experience but is this really correct? So the system doesn't choose the correct plural rules based on the selected language?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is all in the context of a single language.

The current behaviour is that the first plural wins, which for the default domain is the default pluraliser.

This change makes it so that for the default domain the second wins, which is the first user defined one.

There is an existing assumption that plurals within a language and domain pair are consistent which this patch doesn't affect

Copy link
Member

Choose a reason for hiding this comment

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

Thank you, I missed that very important point. Is there anyone you want to review this or are you pretty confident things are good to go? I'm happy to merge it if you tell me to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am happy with it personally, but I know that @tseaver had some concerns about the previous PR's approach, so maybe it would be good to have him confirm that this is sufficiently different?

@mmerickel
Copy link
Member

FWIW I might have defined a DEFAULT_PLURAL = lambda n: int(n != 1) and then done tests against it to see if self.plural is DEFAULT_PLURAL instead of introducing a second variable.

@MatthewWilkes
Copy link
Contributor Author

You mean like #2102 last year?

@mmerickel
Copy link
Member

Hmm, yes apparently... why did we abandon that pr again? :-) Is the main issue that the previous PR was doing things for all domains and this one focuses on the default domain? Sorry I'm trying to help review this but maybe just causing more problems.

@MatthewWilkes
Copy link
Contributor Author

I also didn't really understand it previously, but do more so now. I'm happy for you to go back to that PR and encourage a contribution now we have worked it out, if that is better.

@mmerickel
Copy link
Member

The fundamental difference between this PR and the other one is that this only changes the plural when adding to the DEFAULT_DOMAIN instead of preferring the plural from any translation that is added to any domain.

It appears as if this is done because the default domain is considered a fallback for all other domains and in general if a translation occurs on the non-default domain it's expected it comes with an appropriate plural function whereas the default domain currently always has the default plural function. So if someone is adding a new translation to the default domain, we should pull the plural function from that translation.

Please correct me if I'm wrong but with that in mind I prefer your location for the patch, as it's only done once at the top instead of twice. However I prefer the other patch for its approach of using only a single variable. Could you push that particular change and I'm happy to merge.

@MatthewWilkes
Copy link
Contributor Author

@mmerickel I believe that's accurate. I have pushed the change to using the lambda function identity to check for overrides.

Copy link
Member

@mmerickel mmerickel left a comment

Choose a reason for hiding this comment

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

LGTM. @tseaver I'll merge this in a couple days so if you want any other changes go ahead and take a look!

@tseaver
Copy link
Member

tseaver commented Dec 12, 2016

@mmerickel Feel free.

@mmerickel mmerickel merged commit 58fd29d into Pylons:master Dec 12, 2016
@mmerickel
Copy link
Member

Thank you @MatthewWilkes and @quantum-omega!

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

Successfully merging this pull request may close these issues.

3 participants