- Update UserNotifier to use t_email() helper for all email content
- Extract 4 email subjects and 4 email bodies to emails domain:
* Update email instructions
* Log in instructions
* Confirmation instructions
* Reset password instructions
- Replace string interpolation with Gettext bindings (%{email}, %{url})
- Auto-populate English translations (msgstr = msgid)
- All emails now ready for future internationalization
First module migration complete per design plan.
139 lines
3 KiB
Elixir
139 lines
3 KiB
Elixir
defmodule ToweropsWeb.GettextHelpers do
|
|
@moduledoc """
|
|
Domain-specific helper functions for Gettext translations.
|
|
|
|
Provides shorter syntax for common translation patterns:
|
|
- `t/1` - Common UI elements (default domain)
|
|
- `t_auth/1` - Authentication flows
|
|
- `t_equipment/1` - Equipment/device management
|
|
- `t_admin/1` - Admin features
|
|
- `t_email/1` - Email templates
|
|
|
|
Error messages use the standard `gettext/1` function.
|
|
|
|
## Examples
|
|
|
|
# Common UI
|
|
t("Save")
|
|
t("Cancel")
|
|
|
|
# Authentication
|
|
t_auth("Log in")
|
|
t_auth("Sign up")
|
|
|
|
# Equipment
|
|
t_equipment("Add Device")
|
|
t_equipment("Last polled: %{time}", time: formatted_time)
|
|
|
|
# Admin
|
|
t_admin("Impersonate User")
|
|
|
|
# Emails
|
|
t_email("Reset password instructions")
|
|
|
|
# Errors (use standard gettext)
|
|
gettext("can't be blank")
|
|
"""
|
|
|
|
use Gettext, backend: ToweropsWeb.Gettext
|
|
|
|
@doc """
|
|
Translates a string in the default domain.
|
|
|
|
Used for common UI elements, navigation, generic actions.
|
|
"""
|
|
defmacro t(msgid) do
|
|
quote do
|
|
dgettext("default", unquote(msgid))
|
|
end
|
|
end
|
|
|
|
@doc """
|
|
Translates a string with interpolation in the default domain.
|
|
"""
|
|
defmacro t(msgid, bindings) do
|
|
quote do
|
|
dgettext("default", unquote(msgid), unquote(bindings))
|
|
end
|
|
end
|
|
|
|
@doc """
|
|
Translates a string in the auth domain.
|
|
|
|
Used for authentication flows, user management, login/signup.
|
|
"""
|
|
defmacro t_auth(msgid) do
|
|
quote do
|
|
dgettext("auth", unquote(msgid))
|
|
end
|
|
end
|
|
|
|
@doc """
|
|
Translates a string with interpolation in the auth domain.
|
|
"""
|
|
defmacro t_auth(msgid, bindings) do
|
|
quote do
|
|
dgettext("auth", unquote(msgid), unquote(bindings))
|
|
end
|
|
end
|
|
|
|
@doc """
|
|
Translates a string in the equipment domain.
|
|
|
|
Used for equipment/device management, SNMP, monitoring, alerts.
|
|
"""
|
|
defmacro t_equipment(msgid) do
|
|
quote do
|
|
dgettext("equipment", unquote(msgid))
|
|
end
|
|
end
|
|
|
|
@doc """
|
|
Translates a string with interpolation in the equipment domain.
|
|
"""
|
|
defmacro t_equipment(msgid, bindings) do
|
|
quote do
|
|
dgettext("equipment", unquote(msgid), unquote(bindings))
|
|
end
|
|
end
|
|
|
|
@doc """
|
|
Translates a string in the admin domain.
|
|
|
|
Used for admin-specific features like impersonation, GeoIP, audit logs.
|
|
"""
|
|
defmacro t_admin(msgid) do
|
|
quote do
|
|
dgettext("admin", unquote(msgid))
|
|
end
|
|
end
|
|
|
|
@doc """
|
|
Translates a string with interpolation in the admin domain.
|
|
"""
|
|
defmacro t_admin(msgid, bindings) do
|
|
quote do
|
|
dgettext("admin", unquote(msgid), unquote(bindings))
|
|
end
|
|
end
|
|
|
|
@doc """
|
|
Translates a string in the emails domain.
|
|
|
|
Used for email templates and subjects.
|
|
"""
|
|
defmacro t_email(msgid) do
|
|
quote do
|
|
dgettext("emails", unquote(msgid))
|
|
end
|
|
end
|
|
|
|
@doc """
|
|
Translates a string with interpolation in the emails domain.
|
|
"""
|
|
defmacro t_email(msgid, bindings) do
|
|
quote do
|
|
dgettext("emails", unquote(msgid), unquote(bindings))
|
|
end
|
|
end
|
|
end
|