-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Add missing gettext calls in core_components.ex #5658
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
josevalim
reviewed
Dec 19, 2023
Depending on the context of the template file, we need to output code with different syntaxes. To make maintenance easier and keep the with/without Gettext strings consistent, we add a helper `maybe_gettext/3` to contextually call gettext or skip it, while outputting correct syntax. The helper is internal and is never exposed to the generated code. Both installer and Phoenix (through phx.gen.live) have a core_components.ex template file, and those must stay in sync. We don't want to create a dependency between Phoenix and the installer, so `maybe_gettext/3` is implemented in both places and, similar to the core_components.ex template itself, we ensure that `maybe_gettext/3` implementations stay in sync with automated tests.
And define those functions as private functions in existing modules, as per code review feedback.
rhcarvalho
force-pushed
the
phx_new-gettext
branch
from
December 27, 2023 13:40
f8da08b
to
566d39a
Compare
josevalim
reviewed
Dec 27, 2023
installer/lib/phx_new/generator.ex
Outdated
else | ||
message | ||
end | ||
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.
Instead of defining it inside the quote, define them as regular functions inside PhxNew.Generator
which will be imported.
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.
Done.
Phx.New.Generator is always imported, so we can define the functions just once.
💚 💙 💜 💛 ❤️ |
1 similar comment
💚 💙 💜 💛 ❤️ |
agonzalezro
pushed a commit
to agonzalezro/phoenix
that referenced
this pull request
Dec 30, 2023
studzien
pushed a commit
to Whatnot-Inc/phoenix
that referenced
this pull request
Feb 8, 2024
studzien
pushed a commit
to Whatnot-Inc/phoenix
that referenced
this pull request
Feb 16, 2024
studzien
pushed a commit
to Whatnot-Inc/phoenix
that referenced
this pull request
Feb 20, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #5649.
Note: strings in
app.html.heex
andhome.html.heex
in the generated app are not "meant to stay", so, after ignoring them, the only thing left in a freshly generated app wascore_components.ex
, which already had 2 strings marked for translation -- the rest is updated in this PR.Depending on the context of the template file, we need to output code with different syntax. To make maintenance easier and keep the with/without Gettext strings consistent, we add a helpers
maybe_*_gettext/2
to contextually call gettext or skip it, while outputting correct syntax. The helpers are internal and are never exposed to the generated code.Both installer and Phoenix (through phx.gen.live) have a core_components.ex template file, and those must stay in sync. We don't want to create a dependency between Phoenix and the installer, so the helpers are implemented in both places.