Skip to content

Commit e7a7808

Browse files
ericyangpanclaude
andcommitted
refactor(types): rename i18n field to translations
Update core type system to use 'translations' instead of 'i18n' for better semantic clarity and consistency with schema definitions. - Rename ManifestI18n to ManifestTranslations - Update all type interfaces to use translations field - Update manifest-i18n utility functions and documentation - Update search functionality to reference translations 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 3bd9659 commit e7a7808

File tree

3 files changed

+32
-40
lines changed

3 files changed

+32
-40
lines changed

src/lib/manifest-i18n.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { defaultLocale, type Locale } from '@/i18n/config'
22

33
/**
4-
* Interface for manifest items with i18n support
4+
* Interface for manifest items with translations support
55
*/
6-
export interface ManifestItemWithI18n {
6+
export interface ManifestItemWithTranslations {
77
description?: string
88
name?: string
9-
i18n?: {
9+
translations?: {
1010
[locale: string]: {
1111
description?: string
1212
name?: string
@@ -18,12 +18,12 @@ export interface ManifestItemWithI18n {
1818

1919
/**
2020
* Get localized field from a manifest item
21-
* @param item - The manifest item with potential i18n translations
21+
* @param item - The manifest item with potential translations
2222
* @param field - The field name to translate (e.g., 'description', 'name')
2323
* @param locale - The target locale (e.g., 'en', 'zh-Hans')
2424
* @returns The localized value or the original value if translation not found
2525
*/
26-
export function getLocalizedField<T extends ManifestItemWithI18n>(
26+
export function getLocalizedField<T extends ManifestItemWithTranslations>(
2727
item: T,
2828
field: keyof T,
2929
locale: Locale
@@ -33,8 +33,8 @@ export function getLocalizedField<T extends ManifestItemWithI18n>(
3333
return item[field] as string
3434
}
3535

36-
// Check if i18n translations exist for this locale
37-
const translation = item.i18n?.[locale]
36+
// Check if translations exist for this locale
37+
const translation = item.translations?.[locale]
3838
if (translation && field in translation && translation[field as string]) {
3939
return translation[field as string] as string
4040
}
@@ -45,7 +45,7 @@ export function getLocalizedField<T extends ManifestItemWithI18n>(
4545

4646
/**
4747
* Apply localization to a manifest item
48-
* @param item - The manifest item with potential i18n translations
48+
* @param item - The manifest item with potential translations
4949
* @param locale - The target locale (e.g., 'en', 'zh-Hans')
5050
* @param fields - Array of field names to localize (default: ['description'])
5151
* @returns A new object with localized fields
@@ -63,14 +63,14 @@ export function localizeManifestItem<T extends Record<string, unknown>>(
6363
// Create a new object with localized fields
6464
const localizedItem = { ...item }
6565

66-
// Check if item has i18n translations
67-
const i18nData = item.i18n as Record<string, Record<string, string>> | undefined
68-
if (!i18nData || !i18nData[locale]) {
66+
// Check if item has translations
67+
const translationsData = item.translations as Record<string, Record<string, string>> | undefined
68+
if (!translationsData || !translationsData[locale]) {
6969
return item
7070
}
7171

7272
// Apply translations for requested fields
73-
const translations = i18nData[locale]
73+
const translations = translationsData[locale]
7474
for (const field of fields) {
7575
const fieldStr = String(field)
7676
if (fieldStr in translations && translations[fieldStr]) {
@@ -83,7 +83,7 @@ export function localizeManifestItem<T extends Record<string, unknown>>(
8383

8484
/**
8585
* Apply localization to an array of manifest items
86-
* @param items - Array of manifest items with potential i18n translations
86+
* @param items - Array of manifest items with potential translations
8787
* @param locale - The target locale (e.g., 'en', 'zh-Hans')
8888
* @param fields - Array of field names to localize (default: ['description'])
8989
* @returns A new array with localized items

src/lib/search.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,23 @@ export interface SearchResult {
4040
* Get localized name from manifest with fallback to default name
4141
*/
4242
function getLocalizedName(
43-
item: { name: string; i18n?: { [locale: string]: { name?: string } } },
43+
item: { name: string; translations?: { [locale: string]: { name?: string } } },
4444
locale?: string
4545
): string {
46-
if (locale && item.i18n?.[locale]?.name) {
47-
return item.i18n[locale].name
46+
if (locale && item.translations?.[locale]?.name) {
47+
return item.translations[locale].name
4848
}
4949
return item.name
5050
}
5151

5252
/**
53-
* Check if query matches item name (supports i18n)
53+
* Check if query matches item name (supports translations)
5454
*/
5555
function matchesQuery(
5656
item: {
5757
name: string
5858
description: string
59-
i18n?: { [locale: string]: { name?: string; description?: string } }
59+
translations?: { [locale: string]: { name?: string; description?: string } }
6060
},
6161
query: string
6262
): boolean {
@@ -65,9 +65,9 @@ function matchesQuery(
6565
// Search in default name only
6666
if (item.name.toLowerCase().includes(lowerQuery)) return true
6767

68-
// Search in i18n translations (name only)
69-
if (item.i18n) {
70-
for (const translation of Object.values(item.i18n)) {
68+
// Search in translations (name only)
69+
if (item.translations) {
70+
for (const translation of Object.values(item.translations)) {
7171
if (translation.name?.toLowerCase().includes(lowerQuery)) return true
7272
}
7373
}

src/types/manifests.ts

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ export interface ManifestEntity {
2121
id: string
2222
name: string
2323
description: string
24-
i18n?: ManifestI18n
25-
websiteUrl?: string
26-
docsUrl?: string
24+
translations: ManifestTranslations
25+
verified: boolean
26+
websiteUrl: string
27+
docsUrl?: string | null
2728
}
2829

2930
/**
@@ -33,6 +34,7 @@ export interface ManifestEntity {
3334
*/
3435
export interface ManifestVendorEntity extends ManifestEntity {
3536
vendor: string
37+
docsUrl: string | null // Override: required in vendor-entity schema
3638
}
3739

3840
/**
@@ -48,7 +50,7 @@ export interface ManifestApp extends ManifestEntity {
4850
* Internationalization translations
4951
* Based on: /manifests/$schemas/ref/translations.schema.json
5052
*/
51-
export interface ManifestI18n {
53+
export interface ManifestTranslations {
5254
[locale: string]: {
5355
name?: string
5456
title?: string
@@ -198,7 +200,7 @@ export interface ManifestBaseProduct extends ManifestVendorEntity {
198200
latestVersion: string
199201
githubUrl: string | null
200202
license: string // SPDX License Identifier or 'Proprietary'
201-
pricing?: ManifestPricingTier[]
203+
pricing: ManifestPricingTier[]
202204
resourceUrls: ManifestResourceUrls
203205
communityUrls: ManifestCommunityUrls
204206
relatedProducts: ManifestRelatedProduct[]
@@ -220,14 +222,10 @@ export interface ManifestIDE extends ManifestVendorEntity {
220222
communityUrls: ManifestCommunityUrls
221223
relatedProducts: ManifestRelatedProduct[]
222224
platforms: ManifestPlatformElement[]
223-
websiteUrl?: string
224-
docsUrl?: string
225-
i18n?: ManifestI18n
226225
// Legacy fields that may exist in data
227226
cli?: string | null
228227
install?: string | null
229228
launch?: string | null
230-
verified?: boolean
231229
}
232230

233231
/**
@@ -244,14 +242,10 @@ export interface ManifestCLI extends ManifestVendorEntity {
244242
communityUrls: ManifestCommunityUrls
245243
relatedProducts: ManifestRelatedProduct[]
246244
platforms: ManifestPlatformElement[]
247-
websiteUrl?: string
248-
docsUrl?: string
249-
i18n?: ManifestI18n
250245
// Legacy fields that may exist in data
251246
ide?: string | null
252247
install?: string | null
253248
launch?: string | null
254-
verified?: boolean
255249
}
256250

257251
/**
@@ -264,8 +258,6 @@ export interface ManifestExtension extends ManifestApp {
264258
type: 'cli' | 'ide'
265259
extends: string // Type of extension
266260
latestVersion: string
267-
websiteUrl?: string
268-
docsUrl?: string
269261
license: string
270262
pricing: ManifestPricingTier[]
271263
resourceUrls: ManifestResourceUrls
@@ -298,8 +290,8 @@ export interface ManifestModel {
298290
vendor: string
299291
id: string
300292
description: string
301-
i18n?: ManifestI18n
302-
websiteUrl?: string | null
293+
translations: ManifestTranslations
294+
websiteUrl: string | null
303295
docsUrl?: string | null
304296
verified?: boolean
305297
size: string | null
@@ -325,7 +317,7 @@ export interface ManifestModel {
325317
* Extends: ManifestVendorEntity
326318
*/
327319
export interface ManifestProvider extends ManifestVendorEntity {
328-
verified?: boolean
320+
// verified is inherited from ManifestVendorEntity -> ManifestEntity (required boolean)
329321
type?: string
330322
applyKeyUrl?: string
331323
platformUrls?: {
@@ -362,7 +354,7 @@ export interface ManifestCollection {
362354
title: string
363355
description: string
364356
extractedDate: string
365-
i18n?: {
357+
translations?: {
366358
[locale: string]: {
367359
title?: string
368360
description?: string

0 commit comments

Comments
 (0)