dify/web/__tests__/app-star-i18n.test.ts
Stephen Zhou a84c2d36a3
style: format with vp fmt (#38803)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-07-12 15:57:46 +00:00

47 lines
1.3 KiB
TypeScript

import fs from 'node:fs'
import path from 'node:path'
const I18N_DIR = path.join(__dirname, '../i18n')
const REQUIRED_APP_STAR_KEYS = [
'studio.allApps',
'studio.starApp',
'studio.starFailed',
'studio.starred',
'studio.unstarApp',
] as const
type AppTranslations = Record<string, unknown>
const getSupportedLocales = () =>
fs
.readdirSync(I18N_DIR)
.filter((item) => fs.statSync(path.join(I18N_DIR, item)).isDirectory())
.sort()
const loadAppTranslations = (locale: string): AppTranslations => {
const filePath = path.join(I18N_DIR, locale, 'app.json')
if (!fs.existsSync(filePath)) throw new Error(`Translation file not found: ${filePath}`)
return JSON.parse(fs.readFileSync(filePath, 'utf-8')) as AppTranslations
}
describe('App star i18n translations', () => {
it('should define star-related app list labels for every locale', () => {
const supportedLocales = getSupportedLocales()
const missingKeys = supportedLocales.flatMap((locale) => {
const translations = loadAppTranslations(locale)
return REQUIRED_APP_STAR_KEYS.filter((key) => {
const value = translations[key]
return typeof value !== 'string' || value.trim() === ''
}).map((key) => `${locale}:${key}`)
})
expect(supportedLocales.length).toBeGreaterThan(0)
expect(missingKeys).toEqual([])
})
})