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

Fallback to default clauses when msgstrs are empty #56

Merged
merged 1 commit into from
Nov 23, 2015

Conversation

whatyouhide
Copy link
Contributor

Should close #55.

Before this PR, empty msgstrs were treated like any other msgstr. This resulted in a nasty behaviour when generating new PO files (from POT files) with e.g. mix gettext.merge, because empty
msgstrs were being returned.

This PR changes the behaviour of the Gettext.Compiler, which now doesn't generate a function clause for translations with an empty msgstr at all. This means such translations will fallback to the dynamic clauses of lgettext and lngettext, which just return the msgid (after interpolation) in a {:default, _} tuple. Plural translations are treated this way if they have one or more empty msgstrs.

/cc @chrismccord and @endersstocker

# it's empty, not generating this clause means that the dynamic clause will
# be executed, returning `{:default, msgid}` (with interpolation and so on).
if msgstr == "" do
nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe just omit this branch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lexmag I'm not a fan of implicit nils for if actually :( I know you are (it's in the styleguide 😄) but I think that often relying on the default nil is a very implicit behaviour which makes it harder to understand what the code is doing. I think here this may be even stronger, because we're relying on the fact that nil is a valid quoted term that in this instance means "don't generate anything"; it's already slightly explicit this way, I'm afraid omitting the nil branch would only make it worse :| wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

@whatyouhide I could see the value of explicit nil if we're interested in the returning value (e.g. assignment), but when if has the meaning of skipping some work I believe it is much more clear without nil. :bowtie:
(Personally, I unfold the diff above this change to see – maybe we are doing something with this nil :|).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lexmag I pushed a compromise, there's just one if (or unless) branch and the nil is implicit but I mention we're sometimes returning nil in the comments 😄 wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice. 💛
(however this comment feels superfluous as it is just how if works ¯_(ツ)/¯)_

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lexmag I know, I know 😄 but I value prose and explicitness too much to let this go 😸 jokes aside, I can remove the (by returning nil from this if) if you want :)

Before this commit, empty msgstrs were treated like any other
msgstr. This resulted in a nasty behaviour when generating new PO
files (from POT files) with e.g. `mix gettext.merge`, because empty
msgstrs were being returned.

This commit changes the behaviour of the Gettext.Compiler, which now
doesn't generate a function clause for translations with an empty msgstr
at all. This means such translations will fallback to the dynamic
clauses of `lgettext` and `lngettext`, which just return the
msgid (after interpolation) in a `{:default, _}` tuple.  Plural
translations are treated this way if they have one or more empty
msgstrs.
@josevalim
Copy link
Contributor

❤️ 💚 💙 💛 💜

@josevalim
Copy link
Contributor

Let's ship it and see if there is anything left before we do a new release. :D

whatyouhide added a commit that referenced this pull request Nov 23, 2015
Fallback to default clauses when msgstrs are empty
@whatyouhide whatyouhide merged commit 281a678 into master Nov 23, 2015
@whatyouhide whatyouhide deleted the empty-msgstr branch November 23, 2015 10:45
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.

gettext.extract --merge does not preserve default msgstr's
3 participants