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-gettext
.
When the original command text references
{{INPUT}}
,
$1
, or named arguments, map them from the user's current request.
Claude命令
/phoenix-convert-gettext
的Agent技能封装。
当原始命令文本引用
{{INPUT}}
$1
或命名参数时,从用户当前请求中映射这些参数。

Command 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

任务

  1. Convert hardcoded strings in templates, views, and controllers to use gettext functions
  2. 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
  3. Use appropriate gettext functions:
    • Use
      dgettext/2
      for domain-specific translations
    • Use
      dgettext/3
      when interpolation is needed
    • Use
      dngettext/4
      for pluralization
  4. Extract strings from:
    • All
      .ex
      files (controllers, views, live views, components)
    • All
      .heex
      templates
    • Any JavaScript/TypeScript with user-facing text
  1. 转换硬编码字符串:将模板、视图和控制器中的硬编码字符串转换为使用gettext函数
  2. 按领域/上下文组织翻译:
    • user
      - 用户账户、个人资料、身份验证相关文本
    • admin
      - 管理面板、管理功能、设置相关文本
    • errors
      - 错误消息、验证提示、警告信息
    • navigation
      - 菜单、链接、面包屑、页面标题
    • common
      - 通用/共享文本、按钮、操作提示
  3. 使用合适的gettext函数:
    • 使用
      dgettext/2
      实现特定领域的翻译
    • 当需要插值时使用
      dgettext/3
    • 使用
      dngettext/4
      处理复数形式
  4. 从以下文件中提取字符串:
    • 所有
      .ex
      文件(控制器、视图、Live View、组件)
    • 所有
      .heex
      模板
    • 所有包含用户可见文本的JavaScript/TypeScript文件

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
  • msgids: 保留英文作为默认语言
  • 导入: 在需要的模块中添加
    import <AppName>Web.Gettext
  • 上下文注释: 为含义模糊的翻译添加注释
  • 插值: 对动态内容使用命名参数

Example Transformations

转换示例

Templates (.heex)

模板(.heex)

elixir
undefined
elixir
undefined

Before

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
undefined
elixir
undefined

Before

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")
undefined
conn |> put_flash(:info, dgettext("user", "User created successfully")) |> redirect(to: ~p"/users")
undefined

Views/Components

视图/组件

elixir
undefined
elixir
undefined

Before

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")
undefined
def error_message, do: dgettext("errors", "Something went wrong")
undefined

LiveViews

LiveView

elixir
undefined
elixir
undefined

Before

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"))}
undefined

Additional Requirements

额外要求

  1. Maintain structure: Preserve existing code formatting and functionality
  2. Ensure imports: Verify Gettext module is imported where needed
  3. Check configuration: Ensure the Gettext module is properly configured in the app
  4. 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
  1. 保持结构: 保留现有代码的格式和功能
  2. 确保导入: 验证Gettext模块已在需要的地方导入
  3. 检查配置: 确保Gettext模块在应用中已正确配置
  4. 处理边缘情况:
    • 不要翻译属性名、ID或技术值
    • 不要翻译日志消息,除非是用户可见的
    • 保留电子邮件地址、URL和代码示例不翻译

Focus Area

重点范围

Work only within the {{ web_dir }} directory and its subdirectories.
仅在{{ web_dir }}目录及其子目录内操作。