Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

ShortcutGrid: Add internationalization (i18n) support for Shortcut grid component

未关闭
#909 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
58/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
冷清
技术栈
react, typescript

调研方向

从 Shortcut.tsx 开始,重点查看第 38–54 行附近现有的硬编码标签以及 ShortcutProps 接口。添加可选标签,同时保留当前的英文默认值,然后验证每个布尔型鼠标操作 prop 都会渲染其可自定义的标签,并保持现有的 ShortcutGrid 用法不变。

由索引模型根据 Issue 内容生成。

描述

rehor-ai-patternfly

Describe the problem

The Shortcut component (used by ShortcutGrid) currently has hardcoded English strings for mouse action labels with no way to internationalize them for applications that need to support multiple languages.

Current hardcoded strings

  • "Hover" (line 38 of Shortcut.tsx)

  • "Click" (line 45)

  • "Right click" (line 48)

  • "Drag" (line 51)

  • "Drag + Drop" (line 54)

These are rendered inside Label components alongside a MouseIcon when the corresponding boolean props (hover, click, rightClick, drag, dragAndDrop) are set to true.

Proposed solution

Add optional label props for each mouse action to allow customization of all user-facing strings:

export interface ShortcutProps {
  // ... existing props

  /** Custom label for "Hover" mouse action */
  hoverLabel?: string;
  /** Custom label for "Click" mouse action */
  clickLabel?: string;
  /** Custom label for "Right click" mouse action */
  rightClickLabel?: string;
  /** Custom label for "Drag" mouse action */
  dragLabel?: string;
  /** Custom label for "Drag + Drop" mouse action */
  dragAndDropLabel?: string;
}

These would default to the current English strings for backwards compatibility.

Example usage

import { useTranslation } from 'react-i18next';

const MyComponent = () => {
  const { t } = useTranslation();

  return (
    <ShortcutGrid
      shortcuts={[
        {
          keys: ['ctrl'],
          drag: true,
          dragLabel: t('Drag'),
          description: t('Move object'),
        },
        {
          keys: [],
          rightClick: true,
          rightClickLabel: t('Right click'),
          description: t('Open context menu'),
        },
      ]}
    />
  );
};

Impact

Applications using Shortcut or ShortcutGrid that need to support non-English languages currently have to either:

  • Accept English-only mouse action labels

  • Avoid the boolean mouse action props entirely and lose the MouseIcon + Label badge rendering

  • Build their own shortcut component from scratch

Related

This would align ShortcutGrid with other PatternFly components that support i18n.


Jira Issue: PF-3867

主要语言
TypeScript
星标
10
派生
40
平均合并
3 天 22 小时
30 天内合并 PR
4

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

patternfly/react-component-groups 的其他 Issue

查看 patternfly/react-component-groups 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。