Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🌐 chore: translate non-English comments to English in packages/utils and src/services (#10143)

LobeHub Bot88e376272c1e
diff --git a/packages/utils/src/compass.ts b/packages/utils/src/compass.ts
index 82f010d69bb..3786764fd0c 100644
--- a/packages/utils/src/compass.ts
+++ b/packages/utils/src/compass.ts
@@ -1,7 +1,7 @@
import brotliPromise from 'brotli-wasm';
/**
- * @title 字符串压缩器
+ * @title String Compressor
*/
export class StrCompressor {
/**
@@ -17,9 +17,9 @@ export class StrCompressor {
}
/**
- * @title 压缩字符串
- * @param str - 要压缩的字符串
- * @returns 压缩后的字符串
+ * @title Compress string
+ * @param str - String to compress
+ * @returns Compressed string
*/
compress(str: string): string {
const input = new TextEncoder().encode(str);
@@ -30,9 +30,9 @@ export class StrCompressor {
}
/**
- * @title 解压缩字符串
- * @param str - 要解压缩的字符串
- * @returns 解压缩后的字符串
+ * @title Decompress string
+ * @param str - String to decompress
+ * @returns Decompressed string
*/
decompress(str: string): string {
const compressedData = this.urlSafeBase64Decode(str);
@@ -43,8 +43,8 @@ export class StrCompressor {
}
/**
- * @title 异步压缩字符串
- * @param str - 要压缩的字符串
+ * @title Compress string asynchronously
+ * @param str - String to compress
* @returns Promise
*/
async compressAsync(str: string) {
@@ -58,8 +58,8 @@ export class StrCompressor {
}
/**
- * @title 异步解压缩字符串
- * @param str - 要解压缩的字符串
+ * @title Decompress string asynchronously
+ * @param str - String to decompress
* @returns Promise
*/
async decompressAsync(str: string) {
diff --git a/packages/utils/src/fetch/headers.ts b/packages/utils/src/fetch/headers.ts
index e3b7f5d6756..38583801a5c 100644
--- a/packages/utils/src/fetch/headers.ts
+++ b/packages/utils/src/fetch/headers.ts
@@ -1,7 +1,7 @@
/**
- * 将 HeadersInit 转换为 Record<string, string>
- * @param headersInit - Headers 初始化对象
- * @returns 转换后的记录对象
+ * Convert HeadersInit to Record<string, string>
+ * @param headersInit - Headers initialization object
+ * @returns The converted record object
*/
// eslint-disable-next-line no-undef
export const headersToRecord = (headersInit?: HeadersInit): Record<string, string> => {
diff --git a/packages/utils/src/fetch/request.ts b/packages/utils/src/fetch/request.ts
index 73b463ea435..fdefcbd24d6 100644
--- a/packages/utils/src/fetch/request.ts
+++ b/packages/utils/src/fetch/request.ts
@@ -1,7 +1,7 @@
/**
- * 从请求体中获取数据
- * @param body - 请求体
- * @returns 转换后的请求体数据
+ * Get data from request body
+ * @param body - Request body
+ * @returns Converted request body data
*/
export const getRequestBody = async (
// eslint-disable-next-line no-undef
@@ -23,6 +23,6 @@ export const getRequestBody = async (
return await body.arrayBuffer();
}
- console.warn('不支持的 IPC 代理请求体类型:', typeof body);
- throw new Error('不支持的 IPC 代理请求体类型');
+ console.warn('Unsupported IPC proxy request body type:', typeof body);
+ throw new Error('Unsupported IPC proxy request body type');
};
diff --git a/packages/utils/src/object.ts b/packages/utils/src/object.ts
index 3e69f351663..9fc82a3ff46 100644
--- a/packages/utils/src/object.ts
+++ b/packages/utils/src/object.ts
@@ -1,9 +1,9 @@
import { isNil, omitBy } from 'lodash-es';
/**
- * 清理对象中的空值(undefined、null、空字符串)
- * @param obj 要清理的对象
- * @returns 清理后的对象
+ * Clean empty values (undefined, null, empty string) from an object
+ * @param obj The object to clean
+ * @returns The cleaned object
*/
export const cleanObject = <T extends Record<string, any>>(obj: T): T => {
return omitBy(obj, (value) => isNil(value) || value === '') as T;
diff --git a/src/services/discover.ts b/src/services/discover.ts
index 8e8b5a840b2..617272bf10d 100644
--- a/src/services/discover.ts
+++ b/src/services/discover.ts
@@ -137,7 +137,7 @@ class DiscoverService {
};
/**
- * 上报 MCP 插件安装结果
+ * Report MCP plugin installation result
*/
reportMcpInstallResult = async ({
success,
@@ -168,7 +168,7 @@ class DiscoverService {
};
/**
- * 上报插件调用结果
+ * Report plugin call result
*/
reportPluginCall = async (reportData: CallReportRequest) => {
// if user don't allow tracing , just not report calling
@@ -283,27 +283,27 @@ class DiscoverService {
private async injectMPToken() {
if (typeof localStorage === 'undefined') return;
- // 检查服务端设置的状态标记 cookie
+ // Check server-set status flag cookie
const tokenStatus = this.getTokenStatusFromCookie();
if (tokenStatus === 'active') return;
let clientId: string;
let clientSecret: string;
- // 1. 从 localStorage 获取客户端信息
+ // 1. Get client information from localStorage
const item = localStorage.getItem('_mpc');
if (!item) {
- // 2. 如果没有,则注册客户端
+ // 2. If not exists, register client
const clientInfo = await this.registerClient();
clientId = clientInfo.clientId;
clientSecret = clientInfo.clientSecret;
- // 3. Base64 编码并保存到 localStorage
+ // 3. Base64 encode and save to localStorage
const clientData = JSON.stringify({ clientId, clientSecret });
const encodedData = btoa(clientData);
localStorage.setItem('_mpc', encodedData);
} else {
- // 4. 如果有,则解码获取客户端信息
+ // 4. If exists, decode to get client information
try {
const decodedData = atob(item);
const clientData = JSON.parse(decodedData);
@@ -311,7 +311,7 @@ class DiscoverService {
clientSecret = clientData.clientSecret;
} catch (error) {
console.error('Failed to decode client data:', error);
- // 如果解码失败,重新注册
+ // If decoding fails, re-register
const clientInfo = await this.registerClient();
clientId = clientInfo.clientId;
clientSecret = clientInfo.clientSecret;
@@ -322,23 +322,23 @@ class DiscoverService {
}
}
- // 5. 获取访问令牌(服务端会自动设置 HTTP-Only cookie)
+ // 5. Get access token (server will automatically set HTTP-Only cookie)
try {
const result = await lambdaClient.market.registerM2MToken.query({
clientId,
clientSecret,
});
- // 检查服务端返回的结果
+ // Check server response result
if (!result.success) {
console.warn(
'Token registration failed, client credentials may be invalid. Clearing and retrying...',
);
- // 清空相关的本地存储数据
+ // Clear related local storage data
localStorage.removeItem('_mpc');
- // 重新执行完整的注册流程(但只重试一次)
+ // Re-execute the complete registration process (but only retry once)
if (!this._isRetrying) {
this._isRetrying = true;
try {
diff --git a/src/utils/server/routeVariants.ts b/src/utils/server/routeVariants.ts
index 0d220181c4e..bac725d9a06 100644
--- a/src/utils/server/routeVariants.ts
+++ b/src/utils/server/routeVariants.ts
@@ -1,11 +1,11 @@
-// 定义主题类型
+// Define theme type
import { ThemeAppearance } from 'antd-style/lib/types/appearance';
import { DEFAULT_LANG } from '@/const/locale';
import { Locales, locales } from '@/locales/resources';
import { DynamicLayoutProps } from '@/types/next';
-// 定义变体接口
+// Define variant interface
export interface IRouteVariants {
isMobile: boolean;
locale: Locales;
@@ -14,10 +14,10 @@ export interface IRouteVariants {
theme: ThemeAppearance;
}
-// 支持的主题
+// Supported themes
const SUPPORTED_THEMES = ['dark', 'light'] as const;
-// 默认变体配置
+// Default variant configuration
export const DEFAULT_VARIANTS: IRouteVariants = {
isMobile: false,
locale: DEFAULT_LANG,
@@ -28,8 +28,8 @@ const SPLITTER = '__';
export class RouteVariants {
static serializeVariants = (variants: IRouteVariants): string => {
- // 使用紧凑的格式: locale_isMobile_theme
- // 例如: "en-US_0_dark" 表示 英文_非移动端_深色主题
+ // Use compact format: locale_isMobile_theme
+ // Example: "en-US_0_dark" represents English_Non-mobile_Dark theme
return [variants.locale, Number(variants.isMobile), variants.theme].join(SPLITTER);
};
@@ -37,14 +37,14 @@ export class RouteVariants {
try {
const [locale, isMobile, theme] = serialized.split(SPLITTER);
- // 验证并返回变体
+ // Validate and return variant
return {
isMobile: isMobile === '1',
locale: this.isValidLocale(locale) ? (locale as Locales) : DEFAULT_VARIANTS.locale,
theme: this.isValidTheme(theme) ? theme : DEFAULT_VARIANTS.theme,
};
} catch {
- // 解析失败时返回默认值
+ // Return default value on parse failure
return { ...DEFAULT_VARIANTS };
}
};
@@ -66,14 +66,14 @@ export class RouteVariants {
return locale;
};
- // 工具函数:创建变体
+ // Utility function: create variant
static createVariants = (options: Partial<IRouteVariants> = {}): IRouteVariants => ({
...DEFAULT_VARIANTS,
...options,
});
- // 验证函数
+ // Validation functions
private static isValidLocale = (locale: string): boolean => locales.includes(locale as any);
private static isValidTheme = (theme: string): boolean => SUPPORTED_THEMES.includes(theme as any);