chore: replace all cn comments of fe to en version by volc api (#320)

This commit is contained in:
tecvan
2025-07-31 10:32:15 +08:00
committed by GitHub
parent 716ec0cba8
commit 71f6245a01
2960 changed files with 15545 additions and 15545 deletions

View File

@@ -19,14 +19,14 @@ const DEBUG_TAG = 'open_debug';
const OPEN_CONSOLE_MARK = new RegExp(`(?:\\?|\\&)${DEBUG_TAG}=true`);
export const shouldCloseConsole = () => {
// 如果URL带有调试开启标记则允许console打开
// Allow console to open if the URL is marked with debug enabled
const { search } = window.location;
let isOpenDebug = !!sessionStorage.getItem(DEBUG_TAG);
if (!isOpenDebug) {
isOpenDebug = OPEN_CONSOLE_MARK.test(search);
isOpenDebug && sessionStorage.setItem(DEBUG_TAG, 'true');
}
// 除了正式正常环境都允许console打开
// Except for the official normal environment, the console is allowed to open
const isProduction = !!(IS_RELEASE_VERSION );
console.log('IS_RELEASE_VERSION', IS_RELEASE_VERSION, isProduction);
return !isOpenDebug && isProduction;

View File

@@ -27,7 +27,7 @@ import React, { useCallback, version } from 'react';
import { ApiError } from '../slardar/utils';
import { useLogger, type Logger } from '../logger';
// 拷贝自 react-error-boundary@3.1.4版本源码
// Copy from react-error-boundary@3.1.4 version source code
function useErrorHandler(givenError?: unknown): (error: unknown) => void {
const [error, setError] = React.useState<unknown>(null);
if (givenError !== null && givenError !== undefined) {
@@ -45,15 +45,15 @@ export { useErrorBoundary, useErrorHandler, type FallbackProps };
export type ErrorBoundaryProps = ReactErrorBoundaryProps & {
/**
* @description componentDidCatch 触发该回调函数,参数透传自 componentDidCatch 的两个参数
* @param error 具体错误
* @Description The callback function is triggered by component DidCatch, and the parameters are passed through from the two parameters of component DidCatch
* @param error specific error
* @param info
* @returns
*/
onError?: (error: Error, info: ErrorInfo) => void;
/**
* @description 可在该回调函数中重置组件的一些 state以避免一些错误的再次发生
* @param details reset
* @Description can reset some state of the component in this callback function to prevent some errors from happening again
* @param details reset
* @returns
*/
onReset?: (
@@ -63,18 +63,18 @@ export type ErrorBoundaryProps = ReactErrorBoundaryProps & {
) => void;
resetKeys?: [];
/**
* logger 实例。默认从 LoggerContext 中读取
* Logger instance. Read from LoggerContext by default
*/
// logger?: Logger;
logger?: Logger;
/**
* 发生错误展示的兜底组件
* The bottom cover component of the error display occurred.
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
FallbackComponent: ComponentType<FallbackProps>;
/**
* errorBoundaryName,用于在发生错误时上报
* 事件:react_error_collection / react_error_by_api_collection
* errorBoundaryName to report when an error occurs
* Event: react_error_collection/react_error_by_api_collection
*/
errorBoundaryName: string;
};
@@ -99,7 +99,7 @@ export const ErrorBoundary: React.FC<ErrorBoundaryProps> = ({
const { componentStack } = info;
const meta = {
reportJsError: true, // 标记为 JS Error,上报走 slardar.captureException
reportJsError: true, // Marked as JS Error, report slardar.captureException
errorBoundaryName,
reactInfo: {
componentStack,

View File

@@ -16,7 +16,7 @@
export { reporter, Reporter } from './reporter';
// reporter 需要上报到 slardar 的方法导出
// Reporter needs to report to slardar method export
export type {
LoggerCommonProperties,
CustomEvent,
@@ -24,10 +24,10 @@ export type {
CustomLog,
ErrorEvent,
} from './reporter';
// console 控制台打印
// Console printing
export { logger, LoggerContext, Logger } from './logger';
// ErrorBoundary 相关方法
// ErrorBoundary related methods
export {
ErrorBoundary,
useErrorBoundary,

View File

@@ -42,19 +42,19 @@ export class Logger extends RawLogger {
}
/**
* @deprecated logger方法仅作控制台打印用无需手动添加slardar client如需日志上报请使用`import { reporter } from '@coze-arch/logger',具体规范:
* The @deprecated logger method is only used for console printing, and there is no need to manually add the slardar client. If you need to report the log, please use'import {reporter} from '@code-arch/logger'. Specific specifications:
*/
addClient(client: LoggerReportClient): void {
super.addClient(client);
}
/**
* @deprecated 该方法已废弃,请统一使用`import { reporter } from '@coze-arch/logger'替换,具体规范:
* @Deprecated This method is deprecated, please use'import {reporter} from '@code-arch/logger' to replace it uniformly. Specific specifications:
*/
persist: BaseLogger<CommonLogOptions> = this.persist;
/**
* @deprecated logger方法仅作控制台打印用无需手动添加slardar client如需日志上报请使用`import { reporter } from '@coze-arch/logger',具体规范:
* The @deprecated logger method is only used for console printing, and there is no need to manually add the slardar client. If you need to report the log, please use'import {reporter} from '@code-arch/logger'. Specific specifications:
*/
init(slardarInstance: SlardarInstance) {
const client = new SlardarReportClient(slardarInstance);

View File

@@ -86,7 +86,7 @@ export class Reporter {
}
/**
* 创建一个带有preset的reporter一般可以配置专属的`namespace`和`scope`
* Create a reporter with preset, you can generally configure your own'namespace 'and'scope'.
* @param preset
* @returns
*/
@@ -102,8 +102,8 @@ export class Reporter {
}
/**
* 初始化reporter
* @param slardarInstance 需要上报的slardar实例
* Initialization reporter
* @param slardarInstance The slardar instance that needs to be reported
* @returns
*/
init(slardarInstance: SlardarInstance) {
@@ -137,7 +137,7 @@ export class Reporter {
/// Custom Log
/**
* 上报一个info日志
* Report an info log
* @param event
* @returns
*/
@@ -146,7 +146,7 @@ export class Reporter {
}
/**
* 上报一个success日志
* Report a success log
* @param event
* @returns
*/
@@ -156,7 +156,7 @@ export class Reporter {
}
/**
* 上报一个warning日志
* Report a warning log
* @param event
* @returns
*/
@@ -166,7 +166,7 @@ export class Reporter {
}
/**
* 上报一个error日志
* Report an error log
* @param event
* @returns
*/
@@ -180,7 +180,7 @@ export class Reporter {
/// Custom Event
/**
* 上报一个自定义event事件
* Report a custom event
* @param event
* @returns
*/
@@ -190,7 +190,7 @@ export class Reporter {
}
/**
* 上报一个错误event事件(LogLevel = 'error'
* Report an error event (LogLevel = 'error')
* @param event
* @returns
*/
@@ -202,7 +202,7 @@ export class Reporter {
}
/**
* 上报一个成功event事件(LogLevel = 'success'
* Report a success event (LogLevel = 'success')
* @param event
* @returns
*/
@@ -213,7 +213,7 @@ export class Reporter {
/// Trace Event
/**
* 性能追踪,可以记录一个流程中多个步骤间隔的耗时:
* Performance tracking allows you to track the time spent between multiple steps in a process.
* @param event
* @returns
*/
@@ -305,7 +305,7 @@ export class Reporter {
...e,
meta: {
...e.meta,
// !NOTE: Slardar不支持`a.b`的字段的正则搜索(会报错),需要把`error.message`和`error.name`铺平放到第一层
// ! NOTE: Slardar does not support regular search for fields of'a.b ' (will report an error), you need to lay'error.message' and 'error.name 'on the first layer
errorMessage: event.error.message,
errorName: event.error.name,
level: event.level ?? 'error',

View File

@@ -32,9 +32,9 @@ import {
} from './utils';
/**
* 将 meta 根据类型转换成
* - 指标 metrics可以被度量的值也就是数值
* - 维度 categories:分类,维度,用来做筛选,分组
* Converting meta to type
* Metrics: Values that can be measured, that is, numerical values
* - Dimension categories: classification, dimension, used for filtering, grouping
*
* @param meta
* @returns
@@ -77,7 +77,7 @@ export class SlardarReportClient implements LoggerReportClient {
slardarInstance: SlardarInstance;
constructor(slardarInstance: SlardarInstance) {
// 业务项目里可能有多个 slardar 版本多个版本的类型不兼容constructor 里约束版本会存在问题 => 放开。
// There may be multiple slardar versions in the business project, and the types of multiple versions are incompatible. There will be problems with the constrained version in the constructor = > release.
this.slardarInstance = slardarInstance;
if (!this.slardarInstance) {
@@ -87,7 +87,7 @@ export class SlardarReportClient implements LoggerReportClient {
send(options: CommonLogOptions) {
if (!options.action?.includes(LogAction.PERSIST)) {
// 非持久化日志,不上报
// Non-persistent log, not reported
return;
}
@@ -116,7 +116,7 @@ export class SlardarReportClient implements LoggerReportClient {
eventName,
});
// 上报 JS 异常
// Report a JS exception
this.slardarInstance?.(
'captureException',
error,
@@ -138,7 +138,7 @@ export class SlardarReportClient implements LoggerReportClient {
const { metrics, categories } = metaToMetricsCategories(resolvedMeta);
// 上报独立的事件
// Report an independent incident
this.slardarInstance?.('sendEvent', {
name: eventName,
metrics,
@@ -149,11 +149,11 @@ export class SlardarReportClient implements LoggerReportClient {
...meta,
});
// 上报日志
// report log
this.slardarInstance?.('sendLog', {
level: getSlardarLevel(level),
content: message,
// slardar 内部会对 extra 处理分类number 类型的字段放入 metrics其他放入 categories
// Slardar will handle the classification of extra, put the fields of number type into metrics, and put the others into categories.
extra: normalizeExtra(resolvedMeta),
});
}

View File

@@ -18,7 +18,7 @@ import { reporter } from '../reporter';
export const getSlardarInstance = () => reporter.slardarInstance;
// 异步设置 coze uid 信息
// Set coze's uid information asynchronously
export const setUserInfoContext = (userInfo: DataItem.UserInfo) => {
const slardarInstance = getSlardarInstance();
if (slardarInstance) {

View File

@@ -111,7 +111,7 @@ export const getErrorType = (error?: ApiError | Error): string => {
}
if (error instanceof ApiError) {
// 优先用业务给的 api error type
// Preferentially use the API error type given by the business
if (error.errorOption?.errorType) {
return error.errorOption.errorType;
}
@@ -162,7 +162,7 @@ export function getLogLevel(level = LogLevel.INFO) {
return levelMap[level];
}
/** Slardar 自定义事件级别,默认是 info, 可枚举项 debug | info | warn | error */
/** Slardar custom event level, default is info, enumerable debug | info | warning | error */
const slardarLevelMap = {
[LogLevel.INFO]: 'info',
[LogLevel.SUCCESS]: 'info',

View File

@@ -15,93 +15,93 @@
*/
/**
* 日志级别
* log level
*/
export const enum LogLevel {
/**
* 日志
* log
*/
INFO = 'info',
/**
* 成功日志
* success log
*/
SUCCESS = 'success',
/**
* 接口问题导致的错误
* 不影响用户使用的边缘 case
* 非核心功能问题
* Errors caused by interface problems
* Edge cases that do not affect user use
* non-core functional issues
*/
WARNING = 'warning',
/**
* 严重错误
* Serious mistake
*/
ERROR = 'error',
/**
* 故障
* fault
*/
FATAL = 'fatal',
}
/**
* 日志动作,描述消费日志的行为
* Log actions that describe the behavior of consuming logs
*/
export const enum LogAction {
/**
* 输出到浏览器控制台
* Output to browser console
*/
CONSOLE = 'console',
/**
* 持久化,即上报至平台
* Persistence, that is, reporting to the platform
*/
PERSIST = 'persist',
}
/**
* 通用日志配置
* common log configuration
*/
export interface CommonLogOptions {
/**
* 命名空间
* namespace
*/
namespace?: string;
/**
* 作用域
* 层级:namespace > scope
* scope
* Hierarchy: namespace > scope
*/
scope?: string;
/**
* 日志级别
* log level
* @default LogLevel.INFO
*/
level?: LogLevel;
/**
* 日志动作,描述消费日志的行为
* Log actions that describe the behavior of consuming logs
* @default [LogAction.CONSOLE]
*/
action?: LogAction[];
/**
* 日志消息
* 输出到浏览器控制台场景下必填。
* 最终输出到浏览器控制台: ${namespace} ${scope} ${message}
* log message
* Required in the Output to Browser Console scenario.
* Final output to browser console: ${namespace} ${scope} ${message}
*/
message?: string;
/**
* 事件名
* 上报事件场景下必填。
* event name
* Required under the reported incident scenario.
*/
eventName?: string;
/**
* 扩展信息,可用于描述日志/事件的上下文信息
* Extended information that can be used to describe the context of logs/events
*/
meta?: Record<string, unknown>;
/**
* Error
* 错误日志/事件场景下必填
* Required under error log/event scenario
*/
error?: Error;
}
/**
* 上报平台 Client
* Reporting to the Platform Client
*/
export interface LoggerReportClient {
send: (options: CommonLogOptions) => void;
@@ -122,7 +122,7 @@ export interface BaseLoggerOptions {
type WithRequired<T, K extends keyof T> = T & { [P in K]-?: T[P] };
/**
* 美化输出,开发提效
* Beautify output, develop and improve efficiency
* type A = { a: string };
* type B = { b: string };
* type C = A & B;
@@ -137,15 +137,15 @@ export type LogOptions = Pretty<WithRequired<CommonLogOptions, 'message'>>;
export const enum ErrorType {
/**
* API httpCode 200
* API HTTPCode not 200
*/
ApiError = 'ApiError',
/**
* API httpCode 200,业务 Code 存在异常
* API htpCode 200, there is an exception in the business Code
*/
ApiBizError = 'ApiBizError',
/**
* 未归类的错误
* Uncategorized error
*/
Unknown = 'Unknown',
}
@@ -153,7 +153,7 @@ export const enum ErrorType {
export interface ApiErrorOption {
httpStatus: string;
/**
* 业务 code
* Business code
*/
code?: string;
message?: string;
@@ -161,7 +161,7 @@ export interface ApiErrorOption {
requestConfig?: Record<string, unknown>;
response?: Record<string, unknown>;
/**
* 错误类型,用于细化监控
* Error types, used to refine monitoring
* @default ErrorType.ApiError
*/
errorType?: string;