diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/mention/MentionNode.tsx b/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/mention/MentionNode.tsx index bd3fd1b23..bef8a7cb1 100644 --- a/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/mention/MentionNode.tsx +++ b/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/mention/MentionNode.tsx @@ -13,7 +13,6 @@ import { $applyNodeReplacement, DecoratorNode } from "lexical" import * as React from "react" import { MentionComponent } from "./components/MentionComponent" -import { RANGE_WITH_LABEL_KEY } from "./hooks/dateMentionConfig" import { getDateMentionDisplayName } from "./hooks/dateMentionUtils" import type { MentionData } from "./types" @@ -166,5 +165,5 @@ const resolveMentionDisplayName = (mentionData: MentionData): string => { const language = i18next.language || i18next.resolvedLanguage || i18next.options?.lng || "en" const translate = i18next.getFixedT(language, "ai") - return getDateMentionDisplayName(mentionData, translate, language, RANGE_WITH_LABEL_KEY) + return getDateMentionDisplayName(mentionData, translate, language) } diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/mention/components/MentionComponent.tsx b/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/mention/components/MentionComponent.tsx index 270eb476d..522b61b51 100644 --- a/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/mention/components/MentionComponent.tsx +++ b/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/mention/components/MentionComponent.tsx @@ -15,7 +15,6 @@ import * as React from "react" import { useTranslation } from "react-i18next" import { MentionLikePill } from "../../shared/components/MentionLikePill" -import { RANGE_WITH_LABEL_KEY } from "../hooks/dateMentionConfig" import { createDateMentionData, getDateMentionDisplayName, @@ -34,7 +33,9 @@ interface MentionComponentProps { } const MentionTooltipContent = ({ mentionData }: { mentionData: MentionData }) => { - const displayValue = getMentionDisplayTextValue(mentionData) + const { t, i18n } = useTranslation("ai") + const language = i18n.language || i18n.resolvedLanguage || "en" + const displayValue = getMentionDisplayTextValue(mentionData, t, language) const getIconBgColor = () => { if (mentionData.type === "view" && typeof mentionData.value === "number") { @@ -126,7 +127,7 @@ export const MentionComponent: React.FC = ({ const displayName = React.useMemo(() => { if (mentionData.type === "date") { - return getDateMentionDisplayName(mentionData, t, language, RANGE_WITH_LABEL_KEY) + return getDateMentionDisplayName(mentionData, t, language) } return `@${mentionData.name}` }, [mentionData, t, language]) @@ -142,8 +143,6 @@ export const MentionComponent: React.FC = ({ const newMentionData = createDateMentionData({ range, translate: t, - locale: language, - withRangeKey: RANGE_WITH_LABEL_KEY, }) editor.update(() => { @@ -153,7 +152,7 @@ export const MentionComponent: React.FC = ({ } }) }, - [nodeKey, editor, t, language], + [nodeKey, editor, t], ) const currentDateRange = React.useMemo(() => { diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/mention/components/MentionDropdown.tsx b/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/mention/components/MentionDropdown.tsx index f9471a43a..c14f4a94d 100644 --- a/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/mention/components/MentionDropdown.tsx +++ b/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/mention/components/MentionDropdown.tsx @@ -6,7 +6,6 @@ import { useTranslation } from "react-i18next" import type { TypeaheadGroup } from "../../shared/components/TypeaheadDropdown" import { TypeaheadDropdown } from "../../shared/components/TypeaheadDropdown" import { MENTION_TRIGGER_PATTERN } from "../constants" -import { RANGE_WITH_LABEL_KEY } from "../hooks/dateMentionConfig" import { getDateMentionDisplayName } from "../hooks/dateMentionUtils" import type { MentionData } from "../types" import { MentionTypeIcon } from "./shared/MentionTypeIcon" @@ -43,7 +42,7 @@ const MentionSuggestionItem = React.memo( const displayName = React.useMemo(() => { if (mention.type === "date") { - return getDateMentionDisplayName(mention, t, language, RANGE_WITH_LABEL_KEY) + return getDateMentionDisplayName(mention, t, language) } return mention.name }, [mention, t, language]) diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/mention/hooks/dateMentionConfig.ts b/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/mention/hooks/dateMentionConfig.ts index a858bbfe8..045d875d7 100644 --- a/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/mention/hooks/dateMentionConfig.ts +++ b/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/mention/hooks/dateMentionConfig.ts @@ -188,5 +188,3 @@ export interface WeekdayTranslationDescriptor { labelKey: string searchKey: string } - -export const RANGE_WITH_LABEL_KEY = "mentions.date.display.with_range" diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/mention/hooks/dateMentionParsers.ts b/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/mention/hooks/dateMentionParsers.ts index 4a6e663a4..c0dd6d639 100644 --- a/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/mention/hooks/dateMentionParsers.ts +++ b/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/mention/hooks/dateMentionParsers.ts @@ -6,7 +6,7 @@ import type { TFunction } from "i18next" import type { MentionData, MentionLabelDescriptor } from "../types" import type { RelativeDateDefinition } from "./dateMentionConfig" -import { RANGE_WITH_LABEL_KEY, RELATIVE_DATE_DEFINITIONS } from "./dateMentionConfig" +import { RELATIVE_DATE_DEFINITIONS } from "./dateMentionConfig" import type { DateRange } from "./dateMentionUtils" import { createDateMentionData, @@ -118,8 +118,6 @@ const buildRangeMention = ( label: candidate.label, labelOptions: appendRange ? { appendRange: true } : undefined, translate: context.t, - locale: context.language, - withRangeKey: RANGE_WITH_LABEL_KEY, }) } @@ -215,8 +213,6 @@ export const createDateMentionBuilder = (context: DateMentionBuilderContext) => const chronoMention = createDateMentionData({ range: naturalDateRange, translate: context.t, - locale: context.language, - withRangeKey: RANGE_WITH_LABEL_KEY, displayName: formatLocalizedRange(naturalDateRange, context.language), }) mentions.push(chronoMention) diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/mention/hooks/dateMentionUtils.ts b/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/mention/hooks/dateMentionUtils.ts index 5fd0ebae5..1e22b9527 100644 --- a/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/mention/hooks/dateMentionUtils.ts +++ b/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/mention/hooks/dateMentionUtils.ts @@ -116,8 +116,6 @@ export const createDateMentionData = ({ label, labelOptions, translate, - locale, - withRangeKey, displayName, }: { id?: string @@ -125,8 +123,6 @@ export const createDateMentionData = ({ label?: MentionLabelDescriptor labelOptions?: DateMentionData["labelOptions"] translate: LabelTranslator - locale: string - withRangeKey: I18nKeysForAi displayName?: string }): DateMentionData => { // For relative dates with an id, use the relative format @@ -138,15 +134,7 @@ export const createDateMentionData = ({ : formatRangeValue(range) const text = value // Use the same value for text - const baseLabel = displayName ?? resolveMentionLabel(label, translate) ?? value - let resolvedName = baseLabel - - if (labelOptions?.appendRange) { - resolvedName = translate(withRangeKey, { - label: baseLabel, - range: formatLocalizedRange(range, locale), - }) - } + const resolvedName = displayName ?? resolveMentionLabel(label, translate) ?? value return { id: id ?? `date:${value}`, @@ -207,7 +195,7 @@ export const getDateMentionDisplayName = ( mention: Pick, translate: LabelTranslator, locale: string, - withRangeKey: I18nKeysForAi, + asRange = false, ): string => { // Only rely on value range to determine the display name if (typeof mention.value !== "string") { @@ -235,12 +223,8 @@ export const getDateMentionDisplayName = ( } const matched = matchRelative() - if (matched) { - const label = translate(matched.labelKey) - return translate(withRangeKey, { - label, - range: formatLocalizedRange(range, locale), - }) + if (matched && !asRange) { + return translate(matched.labelKey) } // Fallback: show the localized date range only diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/mention/utils/mentionTextValue.ts b/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/mention/utils/mentionTextValue.ts index 54518ebcf..23448e882 100644 --- a/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/mention/utils/mentionTextValue.ts +++ b/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/mention/utils/mentionTextValue.ts @@ -6,6 +6,8 @@ import { ROUTE_FEED_IN_FOLDER } from "~/constants" import { getRouteParams } from "~/hooks/biz/useRouteParams" import { getI18n } from "~/i18n" +import type { LabelTranslator } from "../hooks/dateMentionUtils" +import { getDateMentionDisplayName } from "../hooks/dateMentionUtils" import type { MentionData } from "../types" export function getMentionTextValue(mentionData: { @@ -27,7 +29,11 @@ export function getMentionTextValue(mentionData: { return `` } -export function getMentionDisplayTextValue(mentionData: MentionData): string { +export function getMentionDisplayTextValue( + mentionData: MentionData, + translate: LabelTranslator, + locale: string, +): string { const { type, value } = mentionData switch (type) { @@ -50,6 +56,10 @@ export function getMentionDisplayTextValue(mentionData: MentionData): string { } return "Unknown View" } + + case "date": { + return getDateMentionDisplayName(mentionData, translate, locale, true) + } default: { return value } diff --git a/locales/ai/en.json b/locales/ai/en.json index 50c340b82..cd4d22487 100644 --- a/locales/ai/en.json +++ b/locales/ai/en.json @@ -80,7 +80,6 @@ "integration.mcp.services.empty.title": "No MCP Services Connected", "integration.mcp.services.title": "MCP Services", "integration.title": "Integration", - "mentions.date.display.with_range": "{{label}} ({{range}})", "mentions.date.relative.last_15_days.label": "Last 15 days", "mentions.date.relative.last_15_days.search": "last 15 days|past 15 days|last half month|past half month", "mentions.date.relative.last_30_days.label": "Last 30 days", diff --git a/locales/ai/ja.json b/locales/ai/ja.json index 1dd2e2cb0..cb2d87d22 100644 --- a/locales/ai/ja.json +++ b/locales/ai/ja.json @@ -74,7 +74,6 @@ "integration.mcp.services.empty.title": "MCPサービスが接続されていません", "integration.mcp.services.title": "MCPサービス", "integration.title": "統合", - "mentions.date.display.with_range": "{{label}}({{range}})", "mentions.date.relative.last_15_days.label": "過去15日間", "mentions.date.relative.last_15_days.search": "過去15日間|直近15日間|半月", "mentions.date.relative.last_30_days.label": "過去30日間", diff --git a/locales/ai/zh-CN.json b/locales/ai/zh-CN.json index ad2ffe9ad..9f34d4f55 100644 --- a/locales/ai/zh-CN.json +++ b/locales/ai/zh-CN.json @@ -76,7 +76,6 @@ "integration.mcp.services.empty.title": "未连接MCP服务", "integration.mcp.services.title": "MCP服务", "integration.title": "集成", - "mentions.date.display.with_range": "{{label}}({{range}})", "mentions.date.relative.last_15_days.label": "最近15天", "mentions.date.relative.last_15_days.search": "最近15天|近半个月", "mentions.date.relative.last_30_days.label": "最近30天",