Skip to content

Commit 154a246

Browse files
committed
fix: localize warning messages
1 parent 68d95cd commit 154a246

File tree

12 files changed

+76
-20
lines changed

12 files changed

+76
-20
lines changed

app/components/Package/SkillsModal.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ const installCommand = computed(() => {
3636
3737
const { copied, copy } = useClipboard({ copiedDuring: 2000 })
3838
const copyCommand = () => installCommand.value && copy(installCommand.value)
39+
const translateWarning = useI18nWarning()
3940
4041
function getWarningTooltip(skill: SkillListItem): string | undefined {
4142
if (!skill.warnings?.length) return undefined
42-
return skill.warnings.map(w => w.message).join(', ')
43+
return skill.warnings.map(translateWarning).join(', ')
4344
}
4445
</script>
4546

@@ -218,10 +219,10 @@ function getWarningTooltip(skill: SkillListItem): string | undefined {
218219
)
219220
}}
220221
</span>
221-
<template v-for="warning in skill.warnings" :key="warning.message">
222+
<template v-for="warning in skill.warnings" :key="warning.key">
222223
<span class="text-amber-500">
223224
<span class="i-lucide:circle-alert size-3 align-[-2px] me-0.5" />{{
224-
warning.message
225+
translateWarning(warning)
225226
}}
226227
</span>
227228
</template>

app/components/diff/SidebarPanel.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const fileFilter = defineModel<'all' | 'added' | 'removed' | 'modified'>('fileFi
1919
2020
const sectionOrder = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']
2121
const { t } = useI18n()
22+
const translateWarning = useI18nWarning()
2223
const sectionMeta = computed<Record<string, { label: string; icon: string }>>(() => ({
2324
dependencies: { label: t('compare.dependencies'), icon: 'i-lucide:box' },
2425
devDependencies: { label: t('compare.dev_dependencies'), icon: 'i-lucide:wrench' },
@@ -112,7 +113,9 @@ function handleFileSelect(file: FileChange) {
112113
<div class="flex items-start gap-2">
113114
<span class="i-lucide:triangle-alert w-3.5 h-3.5 text-yellow-500 shrink-0 mt-0.5" />
114115
<div class="text-3xs text-fg-muted">
115-
<p v-for="warning in compare.meta.warnings" :key="warning">{{ warning }}</p>
116+
<p v-for="warning in compare.meta.warnings" :key="warning.key">
117+
{{ translateWarning(warning) }}
118+
</p>
116119
</div>
117120
</div>
118121
</div>

app/composables/useI18nWarning.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { WarningMessage } from '#shared/types/warning'
2+
3+
export function useI18nWarning() {
4+
const { t } = useI18n()
5+
6+
return (warning: WarningMessage): string => t(warning.key, warning.data ?? {})
7+
}

i18n/locales/en.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@
286286
"refs": "{count} ref | {count} refs",
287287
"assets": "{count} asset | {count} assets"
288288
},
289+
"warnings": {
290+
"no_license": "No license specified",
291+
"no_compatibility": "No compatibility info"
292+
},
289293
"view_source": "View source"
290294
},
291295
"links": {
@@ -1205,7 +1209,10 @@
12051209
"files_button": "Files",
12061210
"select_file_prompt": "Select a file from the sidebar to view its diff",
12071211
"close_files_panel": "Close files panel",
1208-
"filter_files_label": "Filter files by change type"
1212+
"filter_files_label": "Filter files by change type",
1213+
"warnings": {
1214+
"files_truncated": "File list truncated to {count} files"
1215+
}
12091216
},
12101217
"pds": {
12111218
"title": "npmx.social",

i18n/locales/zh-CN.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,11 @@
272272
"refs": "{count} 个引用 | {count} 个引用",
273273
"assets": "{count} 个资源 | {count} 个资源"
274274
},
275-
"view_source": "查看源代码"
275+
"view_source": "查看源代码",
276+
"warnings": {
277+
"no_compatibility": "无兼容性信息",
278+
"no_license": "未指定许可证"
279+
}
276280
},
277281
"links": {
278282
"repo": "仓库",

i18n/schema.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,18 @@
862862
},
863863
"additionalProperties": false
864864
},
865+
"warnings": {
866+
"type": "object",
867+
"properties": {
868+
"no_license": {
869+
"type": "string"
870+
},
871+
"no_compatibility": {
872+
"type": "string"
873+
}
874+
},
875+
"additionalProperties": false
876+
},
865877
"view_source": {
866878
"type": "string"
867879
}
@@ -3621,6 +3633,15 @@
36213633
},
36223634
"filter_files_label": {
36233635
"type": "string"
3636+
},
3637+
"warnings": {
3638+
"type": "object",
3639+
"properties": {
3640+
"files_truncated": {
3641+
"type": "string"
3642+
}
3643+
},
3644+
"additionalProperties": false
36243645
}
36253646
},
36263647
"additionalProperties": false

server/utils/compare.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { diff as semverDiff } from 'semver'
2+
import type { WarningMessage } from '#shared/types/warning'
23

34
/**
45
* Parse a version range from a URL segment.
@@ -236,9 +237,12 @@ export function buildCompareResponse(
236237
const fileChanges = compareFileTrees(fromTree, toTree)
237238
const dependencyChanges = compareDependencies(fromPkg, toPkg)
238239

239-
const warnings: string[] = []
240+
const warnings: WarningMessage[] = []
240241
if (fileChanges.truncated) {
241-
warnings.push(`File list truncated to ${MAX_FILES_COMPARE} files`)
242+
warnings.push({
243+
key: 'compare.warnings.files_truncated',
244+
data: { count: String(MAX_FILES_COMPARE) },
245+
})
242246
}
243247

244248
return {

server/utils/skills.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { WarningMessage } from '#shared/types/warning'
2+
13
const MAX_SKILL_FILE_SIZE = 500 * 1024
24

35
/**
@@ -154,13 +156,13 @@ export async function fetchSkillContent(
154156
/**
155157
* Validate skill frontmatter and return warnings.
156158
*/
157-
export function validateSkill(frontmatter: SkillFrontmatter): SkillWarning[] {
158-
const warnings: SkillWarning[] = []
159+
export function validateSkill(frontmatter: SkillFrontmatter): WarningMessage[] {
160+
const warnings: WarningMessage[] = []
159161
if (!frontmatter.license) {
160-
warnings.push({ type: 'warning', message: 'No license specified' })
162+
warnings.push({ key: 'package.skills.warnings.no_license' })
161163
}
162164
if (!frontmatter.compatibility) {
163-
warnings.push({ type: 'warning', message: 'No compatibility info' })
165+
warnings.push({ key: 'package.skills.warnings.no_compatibility' })
164166
}
165167
return warnings
166168
}

shared/types/compare.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { WarningMessage } from '#shared/types/warning'
2+
13
/** A change in a dependency between versions */
24
export interface DependencyChange {
35
/** Package name */
@@ -60,7 +62,7 @@ export interface CompareResponse {
6062
/** Whether file list was truncated due to size */
6163
truncated?: boolean
6264
/** Any warnings during comparison */
63-
warnings?: string[]
65+
warnings?: WarningMessage[]
6466
/** Time taken to compute (ms) */
6567
computeTime?: number
6668
}

shared/types/skills.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { WarningMessage } from '#shared/types/warning'
2+
13
export interface SkillFrontmatter {
24
name: string
35
description: string
@@ -6,11 +8,6 @@ export interface SkillFrontmatter {
68
metadata?: Record<string, string>
79
}
810

9-
export interface SkillWarning {
10-
type: 'error' | 'warning'
11-
message: string
12-
}
13-
1411
export interface SkillFileCounts {
1512
scripts?: number
1613
references?: number
@@ -23,7 +20,7 @@ export interface SkillListItem {
2320
dirName: string
2421
license?: string
2522
compatibility?: string
26-
warnings?: SkillWarning[]
23+
warnings?: WarningMessage[]
2724
fileCounts?: SkillFileCounts
2825
}
2926

0 commit comments

Comments
 (0)