In the Phoenix app at {{ web_dir }}, refactor all hardcoded text strings to use gettext with domain-based translation logic. Specifically:
Tasks
Convert hardcoded strings in templates, views, and controllers to use gettext functions
Organize translations by domain/context:
user - user account, profile, authentication related text
admin - admin panel, management, settings text
errors - error messages, validations, warnings
navigation - menus, links, breadcrumbs, page titles
common - shared/general purpose text, buttons, actions
Use appropriate gettext functions:
- Use
dgettext/2 for domain-specific translations
- Use
dgettext/3 when interpolation is needed
- Use
dngettext/4 for pluralization
Extract strings from:
- All
.ex files (controllers, views, live views, components)
- All
.heex templates
- Any JavaScript/TypeScript with user-facing text
Conventions
- msgids: Keep in English as the default language
- Imports: Add
import <AppName>Web.Gettext to modules that need it
- Context comments: Add comments for ambiguous translations
- Interpolation: Use named parameters for dynamic content
Example Transformations
Templates (.heex)
# Before
<h1>Welcome to our app</h1>
<p>You have 5 messages</p>
# After
<h1><%= dgettext("navigation", "Welcome to our app") %></h1>
<p><%= dngettext("user", "You have 1 message", "You have %{count} messages", @message_count) %></p>
Controllers
# Before
conn
|> put_flash(:info, "User created successfully")
|> redirect(to: ~p"/users")
# After
conn
|> put_flash(:info, dgettext("user", "User created successfully"))
|> redirect(to: ~p"/users")
Views/Components
# Before
def error_message, do: "Something went wrong"
# After
def error_message, do: dgettext("errors", "Something went wrong")
LiveViews
# Before
{:noreply, put_flash(socket, :error, "Invalid input")}
# After
{:noreply, put_flash(socket, :error, dgettext("errors", "Invalid input"))}
Additional Requirements
- Maintain structure: Preserve existing code formatting and functionality
- Ensure imports: Verify Gettext module is imported where needed
- Check configuration: Ensure the Gettext module is properly configured in the app
- Handle edge cases:
- Don't translate attribute names, IDs, or technical values
- Don't translate log messages unless user-facing
- Keep email addresses, URLs, and code examples untranslated
Focus Area
Work only within the {{ web_dir }} directory and its subdirectories.
1---2name: cmd-phoenix-convert-gettext3description: Convert Phoenix app hardcoded text to use gettext with domain-based translations4---56In the Phoenix app at {{ web_dir }}, refactor all hardcoded text strings to use gettext with domain-based translation logic. Specifically:78## Tasks9101. **Convert hardcoded strings** in templates, views, and controllers to use gettext functions11122. **Organize translations by domain/context**:13 - `user` - user account, profile, authentication related text14 - `admin` - admin panel, management, settings text15 - `errors` - error messages, validations, warnings16 - `navigation` - menus, links, breadcrumbs, page titles17 - `common` - shared/general purpose text, buttons, actions18193. **Use appropriate gettext functions**:20 - Use `dgettext/2` for domain-specific translations21 - Use `dgettext/3` when interpolation is needed22 - Use `dngettext/4` for pluralization23244. **Extract strings from**:25 - All `.ex` files (controllers, views, live views, components)26 - All `.heex` templates27 - Any JavaScript/TypeScript with user-facing text2829## Conventions3031- **msgids**: Keep in English as the default language32- **Imports**: Add `import <AppName>Web.Gettext` to modules that need it33- **Context comments**: Add comments for ambiguous translations34- **Interpolation**: Use named parameters for dynamic content3536## Example Transformations3738### Templates (.heex)39```elixir40# Before41<h1>Welcome to our app</h1>42<p>You have 5 messages</p>4344# After45<h1><%= dgettext("navigation", "Welcome to our app") %></h1>46<p><%= dngettext("user", "You have 1 message", "You have %{count} messages", @message_count) %></p>47```4849### Controllers50```elixir51# Before52conn53|> put_flash(:info, "User created successfully")54|> redirect(to: ~p"/users")5556# After57conn58|> put_flash(:info, dgettext("user", "User created successfully"))59|> redirect(to: ~p"/users")60```6162### Views/Components63```elixir64# Before65def error_message, do: "Something went wrong"6667# After68def error_message, do: dgettext("errors", "Something went wrong")69```7071### LiveViews72```elixir73# Before74{:noreply, put_flash(socket, :error, "Invalid input")}7576# After77{:noreply, put_flash(socket, :error, dgettext("errors", "Invalid input"))}78```7980## Additional Requirements81821. **Maintain structure**: Preserve existing code formatting and functionality832. **Ensure imports**: Verify Gettext module is imported where needed843. **Check configuration**: Ensure the Gettext module is properly configured in the app854. **Handle edge cases**: 86 - Don't translate attribute names, IDs, or technical values87 - Don't translate log messages unless user-facing88 - Keep email addresses, URLs, and code examples untranslated8990## Focus Area9192Work only within the {{ web_dir }} directory and its subdirectories.