Skip to content

feat: configprovider #3180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: feat_v3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 0 additions & 141 deletions src/locales/base.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/locales/en-US.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseLang } from './base'
import { Locales } from '@/types'

const enUS: BaseLang = {
const enUS: Locales = {
save: 'Save',
confirm: 'Confirm',
cancel: 'Cancel',
Expand Down
4 changes: 2 additions & 2 deletions src/locales/id-ID.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseLang } from './base'
import { Locales } from '@/types'

const idID: BaseLang = {
const idID: Locales = {
save: 'Simpan',
confirm: 'Konfirmasi',
cancel: 'Batal',
Expand Down
4 changes: 2 additions & 2 deletions src/locales/tr-TR.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseLang } from './base'
import { Locales } from '@/types'

const trTR: BaseLang = {
const trTR: Locales = {
save: 'Kaydet',
confirm: 'Onayla',
cancel: 'İptal',
Expand Down
4 changes: 2 additions & 2 deletions src/locales/zh-CN.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseLang } from './base'
import { Locales } from '@/types'

const zhCN: BaseLang = {
const zhCN: Locales = {
save: '保存',
confirm: '确认',
cancel: '取消',
Expand Down
6 changes: 3 additions & 3 deletions src/locales/zh-TW.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseLang } from './base'
import { Locales } from '@/types'

const zhCN: BaseLang = {
const zhTW: Locales = {
save: '保存',
confirm: '確認',
cancel: '取消',
Expand Down Expand Up @@ -139,4 +139,4 @@ const zhCN: BaseLang = {
errorCanvasTips: '當前環境不支持Canvas',
},
}
export default zhCN
export default zhTW
4 changes: 2 additions & 2 deletions src/locales/zh-UG.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseLang } from './base'
import { Locales } from '@/types'

const zhUG: BaseLang = {
const zhUG: Locales = {
save: 'ساقلاش',
confirm: 'ھەئە',
cancel: 'ياق',
Expand Down
4 changes: 2 additions & 2 deletions src/packages/address/address.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const InternalAddress: ForwardRefRenderFunction<
<CustomRender
visible={innerVisible}
closeable
title={title || locale.address.selectRegion}
title={title || locale.address?.selectRegion}
left={renderLeftOnCustomSwitch()}
defaultValue={defaultValue}
closeIcon={closeIcon}
Expand All @@ -152,7 +152,7 @@ const InternalAddress: ForwardRefRenderFunction<
round
closeable
closeIcon={closeIcon}
title={title || locale.address.selectRegion}
title={title || locale.address?.selectRegion}
onClose={handleClose}
>
<View
Expand Down
4 changes: 2 additions & 2 deletions src/packages/address/address.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const InternalAddress: ForwardRefRenderFunction<
<CustomRender
visible={innerVisible}
closeable
title={title || locale.address.selectRegion}
title={title || locale.address?.selectRegion}
left={renderLeftOnCustomSwitch()}
defaultValue={defaultValue}
closeIcon={closeIcon}
Expand All @@ -150,7 +150,7 @@ export const InternalAddress: ForwardRefRenderFunction<
round
closeable
closeIcon={closeIcon}
title={title || locale.address.selectRegion}
title={title || locale.address?.selectRegion}
onClose={handleClose}
>
<div
Expand Down
2 changes: 1 addition & 1 deletion src/packages/address/existRender.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const ExistRender: FunctionComponent<
</ul>
</ScrollView>

{(custom || (custom && locale.address.chooseAnotherAddress)) && (
{(custom || (custom && locale.address?.chooseAnotherAddress)) && (
<View className={`${classPrefix}-footer`} onClick={onClick}>
<View className={`${classPrefix}-footer-btn`}>{custom}</View>
</View>
Expand Down
2 changes: 1 addition & 1 deletion src/packages/address/existRender.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export const ExistRender: FunctionComponent<
)
})}
</ul>
{(custom || (custom && locale.address.chooseAnotherAddress)) && (
{(custom || (custom && locale.address?.chooseAnotherAddress)) && (
<div className={`${classPrefix}-footer`} onClick={onClick}>
<div className={`${classPrefix}-footer-btn`}>{custom}</div>
</div>
Expand Down
10 changes: 5 additions & 5 deletions src/packages/audio/audio.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const Audio: FunctionComponent<
})
audioCtx.onEnded(() => {
if (loop) {
console.warn(locale.audio.tips || 'onPlayEnd事件在loop=false时才会触发')
console.warn(locale.audio?.tips || 'onPlayEnd事件在loop=false时才会触发')
} else {
onPlayEnd?.(audioCtx)
}
Expand Down Expand Up @@ -191,7 +191,7 @@ export const Audio: FunctionComponent<
className="back"
onClick={handleBack}
>
{locale.audio.back || '快退'}
{locale.audio?.back || '快退'}
</Button>
<Button
type="primary"
Expand All @@ -200,11 +200,11 @@ export const Audio: FunctionComponent<
onClick={handleStatusChange}
>
{playing
? `${locale.audio.pause || '暂停'}`
: `${locale.audio.start || '开始'}`}
? `${locale.audio?.pause || '暂停'}`
: `${locale.audio?.start || '开始'}`}
</Button>
<Button type="primary" size="small" onClick={handleForward}>
{locale.audio.forward || '快进'}
{locale.audio?.forward || '快进'}
</Button>
</View>
</>
Expand Down
12 changes: 6 additions & 6 deletions src/packages/audio/audio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
const classPrefix = 'nut-audio'
const handleEnded = (e: SyntheticEvent<HTMLAudioElement>) => {
if (loop) {
console.warn(locale.audio.tips || 'onPlayEnd事件在loop=false时才会触发')
console.warn(locale.audio?.tips || 'onPlayEnd事件在loop=false时才会触发')

Check warning on line 71 in src/packages/audio/audio.tsx

View check run for this annotation

Codecov / codecov/patch

src/packages/audio/audio.tsx#L71

Added line #L71 was not covered by tests
} else {
onEnd?.(e)
}
Expand Down Expand Up @@ -183,7 +183,7 @@
className="back"
onClick={handleBack}
>
{locale.audio.back || '快退'}
{locale.audio?.back || '快退'}
</Button>
Comment on lines +186 to 187
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

统一使用可选链操作符增强国际化处理的健壮性

在按钮文本中使用可选链操作符访问 locale.audio 的各个属性,并提供默认文本,使组件在国际化配置不完整时依然能正常显示。

建议为音频组件添加更完善的单元测试,确保在各种国际化配置场景下能正确显示按钮文本。

Also applies to: 195-197, 199-200, 208-209


🏁 Script executed:

#!/bin/bash
# 检查音频组件的测试覆盖情况

# 查找音频组件测试文件
echo "音频组件测试文件:"
fd -t f "audio.*test" .

# 查找测试中是否包含国际化测试
echo "查找国际化相关测试:"
fd -t f "audio.*test" . --exec grep -l "locale\|i18n\|国际化" {} \;

Length of output: 344


请补充涵盖国际化场景的单元测试

目前代码中对国际化文本的处理已正确使用可选链操作符及默认文本(适用于文件 src/packages/audio/audio.tsx 的 186-187、195-197、199-200、208-209 行),确保了在国际化配置不完整时仍能正常显示。但从测试覆盖情况来看,目前缺少针对国际化配置场景的测试(查找关键字“locale”、“i18n”或“国际化”无相关测试文件反馈)。

  • 请为音频组件补充单元测试,用于验证在各种国际化配置缺失或不完整时按钮文本依然能正确显示。
  • 建议覆盖的场景包括:完全有配置、部分缺失以及完全未配置国际化信息的情况。

<Button
type="primary"
Expand All @@ -192,11 +192,11 @@
onClick={handleStatusChange}
>
{playing
? `${locale.audio.pause || '暂停'}`
: `${locale.audio.start || '开始'}`}
? `${locale.audio?.pause || '暂停'}`

Check warning on line 195 in src/packages/audio/audio.tsx

View check run for this annotation

Codecov / codecov/patch

src/packages/audio/audio.tsx#L195

Added line #L195 was not covered by tests
: `${locale.audio?.start || '开始'}`}
</Button>
<Button type="primary" size="small" onClick={handleForward}>
{locale.audio.forward || '快进'}
{locale.audio?.forward || '快进'}
</Button>
<Button
type={
Expand All @@ -205,7 +205,7 @@
size="small"
onClick={handleMute}
>
{locale.audio.mute || '静音'}
{locale.audio?.mute || '静音'}
</Button>
</div>
</>
Expand Down
2 changes: 1 addition & 1 deletion src/packages/avatarcropper/avatarcropper.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
{locale.cancel}
</Button>,
<Button key="reset">{locale.reset}</Button>,
<Button key="rotate">{locale.avatarCropper.rotate}</Button>,
<Button key="rotate">{locale.avatarCropper?.rotate}</Button>,
<Button type="success" key="confirm">
{locale.confirm}
</Button>,
Expand Down Expand Up @@ -156,7 +156,7 @@
...canvasAll,
cropperCanvasContext: Taro.createCanvasContext(canvasAll.canvasId),
})
}, [])

Check warning on line 159 in src/packages/avatarcropper/avatarcropper.taro.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has a missing dependency: 'canvasAll'. Either include it or remove the dependency array. You can also do a functional update 'setCanvasAll(c => ...)' if you only need 'canvasAll' in the 'setCanvasAll' call

const touch = useTouch()

Expand All @@ -168,7 +168,7 @@
height,
borderRadius: shape === 'round' ? '50%' : '',
}
}, [pixelRatio, state.cropperWidth])

Check warning on line 171 in src/packages/avatarcropper/avatarcropper.taro.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useMemo has a missing dependency: 'shape'. Either include it or remove the dependency array

// 是否是横向
const isAngle = useMemo(() => {
Expand Down Expand Up @@ -250,7 +250,7 @@
ctx.scale(scale, scale)
ctx.drawImage(src as HTMLImageElement, x, y, width, height)
},
[drawImage, state]

Check warning on line 253 in src/packages/avatarcropper/avatarcropper.taro.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useCallback has missing dependencies: 'pixelRatio' and 'space'. Either include them or remove the dependency array
)

// web绘制
Expand All @@ -267,7 +267,7 @@
canvas.height = state.displayHeight
const ctx = canvas.getContext('2d') as CanvasRenderingContext2D
canvas2dDraw(ctx)
}, [canvas2dDraw])

Check warning on line 270 in src/packages/avatarcropper/avatarcropper.taro.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useCallback has missing dependencies: 'canvasAll.canvasId', 'state.displayHeight', and 'state.displayWidth'. Either include them or remove the dependency array

const alipayDraw = useCallback(() => {
const ctx = canvasAll.cropperCanvas.getContext(
Expand Down Expand Up @@ -324,7 +324,7 @@
ctx.scale(scale, scale)
ctx.drawImage(src as string, x, y, width, height)
ctx.draw()
}, [drawImage, state.scale, state.angle, state.moveX, state.moveY])

Check warning on line 327 in src/packages/avatarcropper/avatarcropper.taro.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useCallback has missing dependencies: 'alipayDraw', 'canvasAll', 'showAlipayCanvas2D', 'space', 'state', and 'webDraw'. Either include them or remove the dependency array

useEffect(() => {
if (Math.abs(state.moveX) > maxMoveX) {
Expand Down
4 changes: 2 additions & 2 deletions src/packages/avatarcropper/avatarcropper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
{locale.cancel}
</Button>,
<Button key="reset">{locale.reset}</Button>,
<Button key="rotate">{locale.avatarCropper.rotate}</Button>,
<Button key="rotate">{locale.avatarCropper?.rotate}</Button>,
<Button type="success" key="confirm">
{locale.confirm}
</Button>,
Expand Down Expand Up @@ -111,7 +111,7 @@
height,
borderRadius: shape === 'round' ? '50%' : '',
}
}, [devicePixelRatio, drawImage.swidth])

Check warning on line 114 in src/packages/avatarcropper/avatarcropper.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useMemo has a missing dependency: 'shape'. Either include it or remove the dependency array

// 是否是横向
const isAngle = useMemo(() => {
Expand Down Expand Up @@ -458,7 +458,7 @@
accept="image/*"
className={`${classPrefix}-input`}
onChange={(e: any) => inputImageChange(e)}
aria-label={locale.avatarCropper.selectImage}
aria-label={locale.avatarCropper?.selectImage}
/>
<div className="nut-avatar-cropper-edit-text">{editText}</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions src/packages/calendar/calendar.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ export const Calendar = React.forwardRef<
type={type}
autoBackfill={autoBackfill}
popup={popup}
title={title || locale.calendaritem.title}
title={title || locale.calendaritem?.title}
defaultValue={defaultValue}
startDate={startDate}
endDate={endDate}
showToday={showToday}
startText={startText || locale.calendaritem.start}
endText={endText || locale.calendaritem.end}
confirmText={confirmText || locale.calendaritem.confirm}
startText={startText || locale.calendaritem?.start}
endText={endText || locale.calendaritem?.end}
confirmText={confirmText || locale.calendaritem?.confirm}
showTitle={showTitle}
showSubTitle={showSubTitle}
scrollAnimation={scrollAnimation}
Expand Down
8 changes: 4 additions & 4 deletions src/packages/calendar/calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ export const Calendar = React.forwardRef<
autoBackfill={autoBackfill}
renderBottomButton={renderBottomButton}
popup={popup}
title={title || locale.calendaritem.title}
title={title || locale.calendaritem?.title}
defaultValue={defaultValue}
startDate={startDate}
endDate={endDate}
showToday={showToday}
startText={startText || locale.calendaritem.start}
endText={endText || locale.calendaritem.end}
confirmText={confirmText || locale.calendaritem.confirm}
startText={startText || locale.calendaritem?.start}
endText={endText || locale.calendaritem?.end}
confirmText={confirmText || locale.calendaritem?.confirm}
showTitle={showTitle}
showSubTitle={showSubTitle}
scrollAnimation={scrollAnimation}
Expand Down
Loading
Loading