Skip to content

fix: translateIfKey breaks plugin config labels by treating plain text as i18n keys#8564

Open
DDomelette wants to merge 2 commits into
AstrBotDevs:masterfrom
DDomelette:pr/fix-translateIfKey
Open

fix: translateIfKey breaks plugin config labels by treating plain text as i18n keys#8564
DDomelette wants to merge 2 commits into
AstrBotDevs:masterfrom
DDomelette:pr/fix-translateIfKey

Conversation

@DDomelette
Copy link
Copy Markdown

@DDomelette DDomelette commented Jun 3, 2026

Problem

ranslateIfKey() in useConfigTextResolver.js treats ALL non-i18n-key strings as translation failures and returns 

ull, causing plugin configuration field labels (descriptions, hints) to disappear entirely in the WebUI.

Root Cause

The function calls getRaw(value) on the raw config field text. When the plugin provides plain text descriptions (e.g. API Key, Timeout) that don't correspond to any i18n key path, getRaw() returns undefined, and the function returns
ull.

Fix

Added a check: if the value doesn't contain ., it's plain text (not an i18n dot-separated path), so return it as-is. Only attempt i18n resolution for dot-separated key paths.

Changes

  • dashboard/src/composables/useConfigTextResolver.js: +2 / -1

Summary by Sourcery

Bug Fixes:

  • Prevent plain-text plugin configuration labels from being treated as missing i18n keys and disappearing in the UI.

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. area:webui The bug / feature is about webui(dashboard) of astrbot. feature:plugin The bug / feature is about AstrBot plugin system. labels Jun 3, 2026
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • The new value.includes('.') heuristic may be too strict for i18n keys that don't use dot notation or for legitimate plain text containing a dot (e.g. URLs); consider a more robust way to distinguish keys from plain text (e.g. explicit prefix, config flag, or trying translation first and falling back).
  • Previously, non-resolvable strings fell back to the original value, but now translateIfKey returns null when getRaw(value) is falsy; double-check that all call sites handle null correctly or consider maintaining the previous fallback-to-original behavior.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `value.includes('.')` heuristic may be too strict for i18n keys that don't use dot notation or for legitimate plain text containing a dot (e.g. URLs); consider a more robust way to distinguish keys from plain text (e.g. explicit prefix, config flag, or trying translation first and falling back).
- Previously, non-resolvable strings fell back to the original `value`, but now `translateIfKey` returns `null` when `getRaw(value)` is falsy; double-check that all call sites handle `null` correctly or consider maintaining the previous fallback-to-original behavior.

## Individual Comments

### Comment 1
<location path="dashboard/src/composables/useConfigTextResolver.js" line_range="11" />
<code_context>
     if (!value || typeof value !== 'string') return value
-    return getRaw(value) ? tm(value) : value
+    if (!value.includes('.')) return value
+    return getRaw(value) ? tm(value) : null
   }

</code_context>
<issue_to_address>
**issue (bug_risk):** Returning null instead of the original value on missing i18n key may cause downstream breakage.

Previously, a falsy `getRaw(value)` fell back to returning `value`, which is a safe, visible string. Now it returns `null`, which may flow into callers expecting a string and lead to empty UI or warnings. If you want missing keys to be explicit, ensure all consumers handle `null`; otherwise consider keeping the original `value` or using a dedicated placeholder instead.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread dashboard/src/composables/useConfigTextResolver.js Outdated
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modifies the translateIfKey function in useConfigTextResolver.js to return early if the string does not contain a dot, and to return null instead of the original value when getRaw(value) is falsy. The review feedback correctly identifies a regression where plain text strings containing dots (such as version numbers or IP addresses) that are not valid i18n keys will return null, causing them to disappear from the UI. The reviewer suggests falling back to the original value instead of returning null.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

if (!value || typeof value !== 'string') return value
return getRaw(value) ? tm(value) : value
if (!value.includes('.')) return value
return getRaw(value) ? tm(value) : null
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

If value is a plain text string that contains a dot (for example, version numbers like "v1.0", IP addresses like "127.0.0.1", or descriptions containing sentences with periods like "Timeout (e.g. 5s)"), !value.includes('.') will evaluate to false.

Since it is not a valid i18n key, getRaw(value) will return null, causing translateIfKey to return null. This will result in fallbackText becoming '' (empty string) in resolveConfigText, making these plain text labels, descriptions, or hints completely disappear from the UI.

To prevent this regression, we should return the original value as a fallback when getRaw(value) is falsy, rather than returning null.

Suggested change
return getRaw(value) ? tm(value) : null
return getRaw(value) ? tm(value) : value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:webui The bug / feature is about webui(dashboard) of astrbot. feature:plugin The bug / feature is about AstrBot plugin system. size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant