-
Notifications
You must be signed in to change notification settings - Fork 40
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
Gettext i18n #561
Gettext i18n #561
Conversation
Looks great to me, I think this is pretty much the only way (and definitely the most standard way) to do it. @jimsynz what do you think? |
One variation might be to let the user inject a generic |
Would suggest to go the latter route and not have Gettext as dependency. Instead extend the Igniter installer to check for Gettext availability and in case offer to setup the translate function and copy the language files. |
🤔 I hadn't considered it, but yeah it's a good point. The implementation would look roughly the same except you'd be fetching a translation function from config for the app in question (probably best at the app config level, i.e |
Hello guys, Do you need some help? |
Sure! 🙂 Manual testing: There might be some pieces of text left that need to be wrapped in Language files: A number of untranslated strings are missing from the .pot file, would be great to complete those. Next step would be to collect translations to various languages. |
I left the config under This variant requires a config like config :ash_authentication_phoenix, gettext_fn: {MyAppWeb.Gettext, :translate} with a translate fn in def translate(msgid, bindings \\ []), do: Gettext.dgettext(__MODULE__, "auth", msgid, bindings) |
In general: just try it out and see if it works for you! 🙂 Apply the above config, copy the language files, point the dep to this branch: {:ash_authentication_phoenix, git: "https://github.com/serpent213/ash_authentication_phoenix.git", branch: "gettext", override: true}, |
46cdd21
to
94756ed
Compare
Small note: this should include #562 before being released. |
IIRC we pass the |
Hey folks. Thank you for this! 🙌 The reason I didn't address it when building AAP was because I've never actually worked on an app with translations in place, so wanted to leave it until someone with more knowledge shows up rather than just getting it wrong based on my english-based assumptions. I'm afraid I couldn't say whether this is the right approach or not - I'm just going to leave it up to you folks to decide amongst yourselves and let me know when to merge it 😄 |
Refactored it again: We carry around the sign_in_route register_path: "/register",
reset_path: "/reset",
auth_routes_prefix: "/auth",
gettext_fn: {AshAuthentication.Phoenix.Test.Helper, :gettext} Will polish it a little, add some docs and we should be good to go. |
Provides `_gettext` macro to views, which leverages a user supplied function for output text translation. * `_gettext` macro * Pass `gettext_fn` parallel to `overrides` * Wrap all output texts in `_gettext` * Gettext .pot/.po file templates in `/i18n` (included in package) * Docs * Doc clarification regarding password reset routes * Tests for translation and basic test for `/password-reset`
Ready from my side. |
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.
🔥
Looks great to me! |
@jimsynz mind giving it a once over? |
🚀 Thank you for your contribution! 🚀 |
Thank you bro, it' s was really needed. |
A simple wrapper to invoke gettext if available.
Would solve #110, #559.
What you think of this implementation?
Missing: Tests, default .pot, maybe .po files, docs