-
Notifications
You must be signed in to change notification settings - Fork 84
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
Conversation
# 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 nil
s 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?
There was a problem hiding this comment.
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
.
(Personally, I unfold the diff above this change to see – maybe we are doing something with this nil
:|).
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 ¯_(ツ)/¯)_
There was a problem hiding this comment.
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 :)
072bdb3
to
c51c89d
Compare
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.
c51c89d
to
0eef20c
Compare
❤️ 💚 💙 💛 💜 |
Let's ship it and see if there is anything left before we do a new release. :D |
Fallback to default clauses when msgstrs are empty
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 emptymsgstrs 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 oflgettext
andlngettext
, 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