cmd-phoenix-convert-gettext
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese/phoenix-convert-gettext
/phoenix-convert-gettext
Agent skill wrapper for the Claude command .
/phoenix-convert-gettextWhen the original command text references , , or named arguments, map them from the user's current request.
{{INPUT}}$1Claude命令的Agent技能封装。
/phoenix-convert-gettext当原始命令文本引用、或命名参数时,从用户当前请求中映射这些参数。
{{INPUT}}$1Command Instructions
命令说明
In the Phoenix app at {{ web_dir }}, refactor all hardcoded text strings to use gettext with domain-based translation logic. Specifically:
在位于{{ web_dir }}的Phoenix应用中,重构所有硬编码文本字符串,使其使用带有基于领域翻译逻辑的gettext。具体要求如下:
Tasks
任务
-
Convert hardcoded strings in templates, views, and controllers to use gettext functions
-
Organize translations by domain/context:
- - user account, profile, authentication related text
user - - admin panel, management, settings text
admin - - error messages, validations, warnings
errors - - menus, links, breadcrumbs, page titles
navigation - - shared/general purpose text, buttons, actions
common
-
Use appropriate gettext functions:
- Use for domain-specific translations
dgettext/2 - Use when interpolation is needed
dgettext/3 - Use for pluralization
dngettext/4
- Use
-
Extract strings from:
- All files (controllers, views, live views, components)
.ex - All templates
.heex - Any JavaScript/TypeScript with user-facing text
- All
-
转换硬编码字符串:将模板、视图和控制器中的硬编码字符串转换为使用gettext函数
-
按领域/上下文组织翻译:
- - 用户账户、个人资料、身份验证相关文本
user - - 管理面板、管理功能、设置相关文本
admin - - 错误消息、验证提示、警告信息
errors - - 菜单、链接、面包屑、页面标题
navigation - - 通用/共享文本、按钮、操作提示
common
-
使用合适的gettext函数:
- 使用实现特定领域的翻译
dgettext/2 - 当需要插值时使用
dgettext/3 - 使用处理复数形式
dngettext/4
- 使用
-
从以下文件中提取字符串:
- 所有文件(控制器、视图、Live View、组件)
.ex - 所有模板
.heex - 所有包含用户可见文本的JavaScript/TypeScript文件
- 所有
Conventions
约定规范
- msgids: Keep in English as the default language
- Imports: Add to modules that need it
import <AppName>Web.Gettext - Context comments: Add comments for ambiguous translations
- Interpolation: Use named parameters for dynamic content
- msgids: 保留英文作为默认语言
- 导入: 在需要的模块中添加
import <AppName>Web.Gettext - 上下文注释: 为含义模糊的翻译添加注释
- 插值: 对动态内容使用命名参数
Example Transformations
转换示例
Templates (.heex)
模板(.heex)
elixir
undefinedelixir
undefinedBefore
Before
<h1>Welcome to our app</h1>
<p>You have 5 messages</p>
<h1>Welcome to our app</h1>
<p>You have 5 messages</p>
After
After
<h1><%= dgettext("navigation", "Welcome to our app") %></h1>
<p><%= dngettext("user", "You have 1 message", "You have %{count} messages", @message_count) %></p>
```
<h1><%= dgettext("navigation", "Welcome to our app") %></h1>
<p><%= dngettext("user", "You have 1 message", "You have %{count} messages", @message_count) %></p>
```
Controllers
控制器
elixir
undefinedelixir
undefinedBefore
Before
conn
|> put_flash(:info, "User created successfully")
|> redirect(to: ~p"/users")
conn
|> put_flash(:info, "User created successfully")
|> redirect(to: ~p"/users")
After
After
conn
|> put_flash(:info, dgettext("user", "User created successfully"))
|> redirect(to: ~p"/users")
undefinedconn
|> put_flash(:info, dgettext("user", "User created successfully"))
|> redirect(to: ~p"/users")
undefinedViews/Components
视图/组件
elixir
undefinedelixir
undefinedBefore
Before
def error_message, do: "Something went wrong"
def error_message, do: "Something went wrong"
After
After
def error_message, do: dgettext("errors", "Something went wrong")
undefineddef error_message, do: dgettext("errors", "Something went wrong")
undefinedLiveViews
LiveView
elixir
undefinedelixir
undefinedBefore
Before
{:noreply, put_flash(socket, :error, "Invalid input")}
{:noreply, put_flash(socket, :error, "Invalid input")}
After
After
{:noreply, put_flash(socket, :error, dgettext("errors", "Invalid input"))}
undefined{:noreply, put_flash(socket, :error, dgettext("errors", "Invalid input"))}
undefinedAdditional 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
- 保持结构: 保留现有代码的格式和功能
- 确保导入: 验证Gettext模块已在需要的地方导入
- 检查配置: 确保Gettext模块在应用中已正确配置
- 处理边缘情况:
- 不要翻译属性名、ID或技术值
- 不要翻译日志消息,除非是用户可见的
- 保留电子邮件地址、URL和代码示例不翻译
Focus Area
重点范围
Work only within the {{ web_dir }} directory and its subdirectories.
仅在{{ web_dir }}目录及其子目录内操作。