-
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
Allow whitelisting of references #86
Conversation
## Example | ||
|
||
config :gettext, | ||
exlude_refs_from_pruging: "^web\/static\/.*" |
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.
Typo in _pruging
and in exlude
.
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.
Also, not sure why you're escaping /
given you're in a string; it would make sense in ~r//
, but in strings you can just use ^web/static/.*
. :)
Hey @maufl, great job, this is definitely headed in the right direction. I left a first batch of comments, let me know if everything is clear :) |
Argh, this damn pruging typo followed me everywhere, I thought I found all of them ... I made some improvements, I think they cover all your suggestions. |
that matches this pattern. You can use this pattern to prevent Gettext from | ||
removing translations that you have extracted using another tool, e.g. from | ||
static resources (web/static). | ||
* `:excluded_refs_from_purging` - a regex that is matched agains translation |
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.
agains
-> agains
I love how all you suggestions make the code smaller and simpler. |
@@ -42,7 +42,7 @@ defmodule Gettext.PO.Translations do | |||
## Example | |||
|
|||
config :gettext, | |||
exclude_refs_from_purging: ~r/^web\/static\/.*/ | |||
exclude_refs_from_purging: ~r{^web/static/.*} |
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 better to make this consistent with the rest of the regexes, ~r{^web/static/}
.
@maufl awesome. So, I've been thinking about this and I think we should move the impure logic of this up from where it is now. By impure logic, I mean the retrieving of the def merge_template(existing, new) do
protected_pattern = Application.get_env(:gettext, :exclude_refs_from_purging)
...
PO.Translations.protected?(t, protected_pattern)
This way, Also, I don't love the idea of having a "fallback" regex that never matches when the protected_pattern = Application.get_env(:gettext, :exclude_refs_from_purging)
# in protected?/2
def protected?(_t, nil), do: false
def protected?(_t, %Regex{} = pattern), do: ... Wdyt? |
I agree that it's ugly to fetch the pattern every time the Originally I used the fallback regex to avoid conditional expressions in |
@maufl why you don't like the idea of fetching the option in (btw, ideally we would have this as up as possible, e.g., in the |
I don't like it better in |
@maufl let's put it in We're almost good to go :D We're only missing docs for this new option. You can describe this option in this section of the docs. |
I already added docs for this option. Should be the first changeset when you compare the files. :) |
Ooops, very sorry :) I even left a few comments there 😄 So, very very last thing: can you squash all the commits in a single one? Then I think we're ready to go 👍 |
You mean, squash them locally and force push? I just discovered in another repo that GitHub allows you to squash commits of a pull request before merging them. If you hit "Merge pull request" you will get a "Confirm merge" button with a dropdown. The squash options is hidden in the dropdown. |
iex> protected_pattern = ~r{^web/static/} | ||
iex> t = %Gettext.PO.Translation{msgid: "Hello world!", references: [{"web/static/js/app.js", 42}]} | ||
iex> Gettext.PO.Translations.protected?(t, protected_pattern) | ||
true |
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.
Can we leave an empty line after the true
? It's very common to do that in Elixir.
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.
Of course we can :)
def protected?(_t, nil), do: false | ||
def protected?(%{__struct__: s, references: []}, pattern) when is_translation(s), do: false | ||
def protected?(%{__struct__: s, references: refs}, pattern) when is_translation(s), | ||
do: Enum.any?(refs, fn({path, _}) -> Regex.match?(pattern, path) end) |
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.
This is great with do:
instead of do ... end
:) Last nitpick: can we always have the do:
on a new line?
def protected?(_t, nil),
do: false
def protected?(%{__struct__: s, references: []}, pattern) when is_translation(s),
do: false
def protected?(%{__struct__: s, references: refs}, pattern) when is_translation(s),
do: Enum.any?(refs, fn({path, _}) -> Regex.match?(pattern, path) end)
oh, you're right, force of habit :) Left the superlast couple of comments, then we're ready to merge :) |
Fixed :) Somehow Emacs Elixir mode has issues with this kind of indentation :/ |
Wonderful 💟 Thanks so much! (btw yep, this is hard code to indent I think, that's why elixir-mode has trouble with it) |
Your welcome :) Feels great already to contribute to an Elixir library after only about 2 months. |
Adds an option to specify a pattern of references that should be preserved by Gettext.
As discussed in #85.