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

Warning for slashes in domains #76

Merged
merged 2 commits into from
Feb 15, 2016
Merged

Conversation

whatyouhide
Copy link
Contributor

Implements the ideas discussed in #75.

@josevalim
Copy link
Contributor

If the domain has a / in it, we can say in the error message that slashes in domain names are not supported. For this case, we may not even need to show the available domains. I don't remember why we would want to show the known domains anymore, hahaha (sorry!).

def warn_if_domain_has_slashes(backend, domain) do
if String.contains?(domain, "/") do
IO.puts :stderr, """
The domain #{inspect domain} was not compiled. The #{inspect backend}
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: the domain ...

@whatyouhide
Copy link
Contributor Author

@josevalim makes sense :) I squashed the second commit, now we warn when the domain is unknown (and we show the available domains) and we warn that /s in domains aren't supported if the domain contains any /s.

cond do
String.contains?(domain, "/") ->
IO.puts :stderr, "warning: slashes in domains are not supported: #{inspect domain}"
not domain in known ->
Copy link
Contributor

Choose a reason for hiding this comment

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

Discussion point: should we really warn here? Should we ask folks to create empty .po files in their locales then? I would say we shouldn't warn here (we can still keep known_domains around, I would just remove the warning. If we warn, we will break the workflow where I can just add translations, specially in english, without caring about the .po / .pot files.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm 👍 for not having this warning or make it configurable, e.g. allow_missing: false. :bowtie:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Honestly, I don't want to warn on missing domains. It's a little bit of a mess, we have to capture so much IO in the tests and @josevalim makes a great point (you'll be warned everytime until you run mix gettext.extract).

@josevalim
Copy link
Contributor

Sorry I was not super clear in my previous comment(s). My point is simply that we can keep known_domains around but I don't think we would use it for anything right now. I think the warning will cause more confusion than help. :)

@josevalim
Copy link
Contributor

And to be super clear: the warning on slashes is still super useful.

domains known by the backend.

This function is called by `lgettext` and `lngettext`.
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it should be @doc false? Do we expect end users will use this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The whole module is @moduledoc false, all other functions are documented with @doc.

@whatyouhide
Copy link
Contributor Author

Ok, we're superclear now: we'll keep the known locales around (cause it's easy and it can be useful) and we'll only warn for domains with /s in them.

@lexmag
Copy link
Contributor

lexmag commented Feb 12, 2016

... we'll keep the known locales around (cause it's easy and it can be useful) ...

You mean known domains, right?
If so, why we keep them if there is no use for it – dead code?

@josevalim
Copy link
Contributor

josevalim commented Feb 12, 2016 via email

@whatyouhide
Copy link
Contributor Author

Ok @josevalim and @lexmag, I decided to remove known_domains-related stuff as it's indeed dead code and it's something internal to Gettext, so it wouldn't benefit users; we can always re-add it later (as it's terribly simple to re-implement).

I also fixed the warnings: now only domains with slashes in them emit warnings when used. Ready to merge?

@josevalim
Copy link
Contributor

:shipit:

whatyouhide added a commit that referenced this pull request Feb 15, 2016
@whatyouhide whatyouhide merged commit 5f0ba36 into master Feb 15, 2016
@whatyouhide whatyouhide deleted the warning-for-slashes-in-domains branch February 15, 2016 08:55
@vborodkin
Copy link

Hi there! I might be missing something, but how do you treat nested domains then? For example, dgettext "users/admin", "List Users", where the domain file should inside a users directory.

@whatyouhide
Copy link
Contributor Author

@vborodkin is this something GNU gettext supports?

@vborodkin
Copy link

@whatyouhide I don't know. I never used gettext until I started using Phoenix, which is recently. Is there anything I can do to help and clarify this? Although, it seems fairly normal to namespace domains in larger applications. I can use a underscore for the time being.

@OvermindDL1
Copy link

OvermindDL1 commented Jun 8, 2018

GNU gettext does support / in domains just for note (I just tested it).

EDIT: In fact it seems to handle about any characters I throw at it...

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.

None yet

5 participants