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

@@ -13,31 +13,31 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, it, expect } from 'vitest';
import { i18nContext } from '../../src/i18n-provider/context';
describe('i18n-provider/context', () => {
it('should create a context with default values', () => {
// 验证 i18nContext 是否被正确创建
// Verify that i18nContext was created correctly
expect(i18nContext).toBeDefined();
// 获取默认值 - 使用类型断言访问内部属性
// @ts-expect-error - 访问内部属性
// Get Default Values - Use Type Assertions to Access Internal Properties
// @ts-expect-error - access internal properties
const defaultValue = i18nContext._currentValue;
// 验证默认值中的 i18n 对象是否存在
// Verify that the i18n object in the default value exists
expect(defaultValue.i18n).toBeDefined();
// 验证 t 函数是否存在
// Verify that the t function exists
expect(defaultValue.i18n.t).toBeDefined();
expect(typeof defaultValue.i18n.t).toBe('function');
// 验证 t 函数的行为
// Verify the behavior of the t function
expect(defaultValue.i18n.t('test-key')).toBe('test-key');
// 验证 i18nContext 是一个对象
// Verify that i18nContext is an object
expect(typeof i18nContext).toBe('object');
});
});

View File

@@ -40,7 +40,7 @@ describe('I18nProvider', () => {
const provider = new I18nProvider({ children });
const result = provider.render().props.children;
// 验证渲染结果
// Validate the render result
expect(result).toBeDefined();
expect(result.props).toBeDefined();
expect(result.props.value).toBeDefined();
@@ -48,7 +48,7 @@ describe('I18nProvider', () => {
expect(typeof result.props.value.i18n.t).toBe('function');
expect(result.props.children).toBe(children);
// 验证默认的 t 函数行为
// Verify the default t function behavior
const defaultT = result.props.value.i18n.t;
expect(defaultT('test-key')).toBe('test-key');
});
@@ -69,14 +69,14 @@ describe('I18nProvider', () => {
const provider = new I18nProvider({ children, i18n: mockI18n as any });
const result = provider.render().props.children;
// 验证渲染结果
// Validate the render result
expect(result).toBeDefined();
expect(result.props).toBeDefined();
expect(result.props.value).toBeDefined();
expect(result.props.value.i18n).toBe(mockI18n);
expect(result.props.children).toBe(children);
// 验证使用了提供的 i18n
// Verify that the provided i18n is used.
const key = 'test-key';
result.props.value.i18n.t(key);
expect(mockI18n.t).toHaveBeenCalledWith(key);

View File

@@ -18,7 +18,7 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';
import { I18n, initI18nInstance } from '../../src/raw';
// 模拟本地化资源
// Simulate localized resources
vi.mock('../../src/resource.ts', () => ({
default: {
en: { i18n: { test: 'Test' } },

View File

@@ -39,9 +39,9 @@ type I18nOptions<K extends LocaleData> = K extends keyof I18nOptionsMap
? I18nOptionsMap[K]
: never;
// 这里导出的 const I18n = new FlowIntl() '@edenx/plugin-starling-intl/runtime' 中的 I18n 功能等价
// 其实就是对 '@edenx/plugin-starling-intl/runtime' 中的 I18n 进行了一层封装,目的是为了后续进一步灵活的定义I18n.t() 的参数类型。
// 这里的 I18n.t() 的参数类型是通过泛型 LocaleData 来定义的,而 '@edenx/plugin-starling-intl/runtime' 中的 I18n.t() 的参数类型是通过泛型 string 来定义的。
// The exported const I18n = new FlowIntl () is functionally equivalent to I18n in '@edenx/plugin-starling-intl/runtime'
// In fact, it is a layer of encapsulation for I18n in '@edenx/plugin-starling-intl/runtime', in order to further flexibly define the parameter type of I18n.t () in the future.
// The parameter types of I18n.t () here are defined by the generic LocaleData, while the parameter types of I18n.t () in '@edenx/plugin-starling-intl/runtime' are defined by the generic string.
class FlowIntl {
plugins: any[] = [];
public i18nInstance: I18nCore;
@@ -89,9 +89,9 @@ class FlowIntl {
t<K extends I18nKeysNoOptionsType>(
keys: K,
// 这里如果用 never 的话,导致存量代码第二个参数是 `{}` 的时候会报错,所以这里用 Record<string, unknown> 代替
// 后续的做法是:用 sg 把存量的代码都修复了之后,这里再改成 never 类型,从而保证未来新增的代码,都是有类型检查的。
// 记得改动的时候 #87 行也要一起修改
// If you use never here, an error will be reported when the second parameter of the stock code is' {} ', so use Record < string, unknown > instead
// The follow-up approach is to use sg to fix all the existing code, and then change it to the never type here, so as to ensure that future new code is type-checked.
// Remember to modify line #87 together when changing.
options?: Record<string, unknown>,
fallbackText?: string,
): string;

View File

@@ -27,8 +27,8 @@ export interface IntlConstructorOptions {
}
let intlInstance: any = null;
/**
* I18n实例
* 自定义配置
* I18n example
* custom configuration
*/
class Intl {
plugins: any[];
@@ -38,7 +38,7 @@ class Intl {
this.i18nInstance = opts?.i18nInstance ?? new I18next();
}
/**
* i18n 没有定义类型,这里声明 any
* I18n does not define a type, declare any here
*/
use(plugin: any) {
if (!this.plugins.includes(plugin)) {
@@ -119,7 +119,7 @@ class Intl {
if (!that.i18nInstance || !that.i18nInstance.init) {
return fallbackText ?? (Array.isArray(keys) ? keys[0] : keys);
}
// 有人给 key 传空字符串?
// Someone passed an empty string to the key?
if (!keys || (typeof keys === 'string' && !keys.trim())) {
return '';
}

View File

@@ -55,15 +55,15 @@ export function formatLang(lng, plugins) {
const defaultFallbackLanguage = 'zh-CN';
const defaultConfig = {
lng: defaultFallbackLanguage, // 如果使用了 Language Detectori18next 底层 lng 的权重是大于插件的
lng: defaultFallbackLanguage, // If Language Detector is used, the weight of the underlying lng of i18next is greater than that of the plug-in.
fallbackLng: ['en-US'],
inContext: true,
};
// 默认开启ICU插值解析
// Default enable ICU interpolation parsing
/**
* I18n内核
* 安全校验
* I18n kernel
* security check
*/
export default class I18next {
instance: i18n;
@@ -90,7 +90,7 @@ export default class I18next {
}
_handleConfigs(config?: InitOptions) {
this.userLng = config?.lng || null; // 用户自己设定的 lng
this.userLng = config?.lng || null; // Lng set by the user.
this.config = Object.assign({}, defaultConfig, config || {});
}
@@ -138,10 +138,10 @@ export default class I18next {
},
},
(err, t) => {
// 初始化好了
// Initialized
try {
// 把等待添加的东西都加进去
// Add everything waiting to be added
for (const item of this._waitingToAddResourceBundle) {
this.instance.addResourceBundle(...item);
}
@@ -184,7 +184,7 @@ export default class I18next {
overwrite,
);
}
// 还没初始化好
// It hasn't been initialized yet.
this._waitingToAddResourceBundle.push([
lng,
ns,
@@ -244,7 +244,7 @@ export default class I18next {
.join('')
: Array(keys.length).fill(' ');
// fixed: 去除默认lngs有lngs i18next就会忽略lng
// Fixed: Remove the default lngs, if there is lngs i18next, the lng will be ignored.
const opt: Record<string, any> = Object.assign(
{ keySeparator: separatorMock, nsSeparator: separatorMock },
options,

View File

@@ -22,18 +22,18 @@
import { type InitOptions } from 'i18next';
/**
* 初始化 Intl 实例配置参数
* Initialize Intl instance configuration parameters
*/
export interface IIntlInitOptions
extends Omit<InitOptions, 'missingInterpolationHandler'> {
/**
* t 方法是否开启第三个参数兜底
* Whether the t method turns on the third parameter to cover the bottom
* @default true
*/
thirdParamFallback?: boolean;
/**
* 忽略所有控制台输出,不建议设置为 true
* Ignore all console output, do not recommend setting to true
* @default false
*/
ignoreWarning?: boolean;