Skip to content
Merged
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
19 changes: 14 additions & 5 deletions i18n/glossary.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
"es": "techo",
"ja": "天井",
"note": "A generic overhead room surface, not necessarily a suspended ceiling.",
"it": "soffitto"
"it": "soffitto",
"ru": "потолок"
},
"floor plan": {
"zh-CN": "平面图",
"fr": "plan d’étage",
"es": "plano de planta",
"ja": "平面図",
"note": "A 2D architectural drawing, not a project plan.",
"it": "pianta"
"it": "pianta",
"ru": "план этажа"
},
"level": {
"zh-CN": "楼层",
Expand All @@ -30,7 +32,8 @@
"fr": "pièce",
"es": "estancia",
"ja": "部屋",
"it": "stanza"
"it": "stanza",
"ru": "комната"
},
"scan": {
"zh-CN": "扫描模型",
Expand All @@ -40,20 +43,26 @@
"note": "A captured 3D reference, not the verb scan.",
"it": "scansione"
},
"unit": {
"ru": "помещение",
"note": "A self-contained part of a building (apartment, suite, commercial space), not a measurement unit."
},
"wall": {
"zh-CN": "墙体",
"fr": "mur",
"es": "muro",
"ja": "壁",
"it": "muro"
"it": "muro",
"ru": "стена"
},
"walkthrough": {
"zh-CN": "漫游",
"fr": "visite",
"es": "recorrido",
"ja": "ウォークスルー",
"note": "First-person navigation through the building.",
"it": "passeggiata"
"it": "passeggiata",
"ru": "прогулка"
}
}
}
29 changes: 28 additions & 1 deletion packages/core/src/lib/asset-storage.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'fake-indexeddb/auto'
import { afterEach, describe, expect, test } from 'bun:test'
import { loadAssetUrl, saveAsset } from './asset-storage'
import { get, set } from 'idb-keyval'
import { ASSET_PREFIX, loadAssetUrl, saveAsset } from './asset-storage'

function file(contents: string, name = 'test.txt'): File {
return new File([contents], name, { type: 'text/plain' })
Expand Down Expand Up @@ -46,6 +47,32 @@ describe('loadAssetUrl', () => {
expect(objectUrl?.startsWith('blob:')).toBe(true)
})

// Regression test: saveAsset used to put the File object itself into
// IndexedDB. Not every engine accepts File/Blob records (WebKit rejects
// them), so the record is now plain bytes plus the content type.
test('stores raw bytes and the content type, not a File object', async () => {
const url = await saveAsset(new File(['png-bytes'], 'a.png', { type: 'image/png' }))
const stored = await get<{ assetVersion: number; bytes: ArrayBuffer; type: string }>(
`${ASSET_PREFIX}${url.replace('asset://', '')}`,
)
expect(stored).not.toBeInstanceOf(Blob)
expect(stored?.assetVersion).toBe(1)
expect(stored?.bytes).toBeInstanceOf(ArrayBuffer)
expect(new TextDecoder().decode(stored?.bytes)).toBe('png-bytes')
expect(stored?.type).toBe('image/png')
})

test('still reads File/Blob records written before the byte format', async () => {
await set(`${ASSET_PREFIX}legacy`, new Blob(['old'], { type: 'text/plain' }))
const objectUrl = await loadAssetUrl('asset://legacy')
expect(objectUrl?.startsWith('blob:')).toBe(true)
})

test('returns null instead of throwing for an unreadable record', async () => {
await set(`${ASSET_PREFIX}broken`, { unexpected: true })
expect(await loadAssetUrl('asset://broken')).toBeNull()
})

test('passes through blob: and http(s) URLs unchanged', async () => {
expect(await loadAssetUrl('blob:http://example.com/1234')).toBe('blob:http://example.com/1234')
expect(await loadAssetUrl('https://cdn.example.com/a.glb')).toBe(
Expand Down
50 changes: 46 additions & 4 deletions packages/core/src/lib/asset-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,49 @@ export const ASSET_PREFIX = 'asset_data:'
// Cache for active object URLs to prevent leaks and flickering
const urlCache = new Map<string, string>()

/**
* Stored shape for assets. Raw bytes go through the portable structured-clone
* path, which every IndexedDB implementation supports; File/Blob records do
* not (WebKit has rejected them). The content type is kept so the object URL
* served later still carries the original MIME type.
*/
export interface StoredAssetRecord {
assetVersion: 1
bytes: ArrayBuffer
type: string
}

function isStoredAssetRecord(value: unknown): value is StoredAssetRecord {
return (
typeof value === 'object' &&
value !== null &&
(value as StoredAssetRecord).assetVersion === 1 &&
(value as StoredAssetRecord).bytes instanceof ArrayBuffer &&
typeof (value as StoredAssetRecord).type === 'string'
)
}

/**
* Turn whatever is in IndexedDB back into a Blob. Records written before the
* byte format existed are plain File/Blob objects and stay readable.
*/
function toBlob(value: unknown): Blob | null {
if (value instanceof Blob) return value
if (isStoredAssetRecord(value)) return new Blob([value.bytes], { type: value.type })
return null
}

/**
* Save a file to IndexedDB and return a custom protocol URL
*/
export async function saveAsset(file: File): Promise<string> {
const id = randomId()
await set(`${ASSET_PREFIX}${id}`, file)
const record: StoredAssetRecord = {
assetVersion: 1,
bytes: await file.arrayBuffer(),
type: file.type,
}
await set(`${ASSET_PREFIX}${id}`, record)
return `asset://${id}`
}

Expand Down Expand Up @@ -42,12 +79,17 @@ export async function loadAssetUrl(url: string): Promise<string | null> {
}

try {
const file = await get<File | Blob>(`${ASSET_PREFIX}${id}`)
if (!file) {
const stored = await get<unknown>(`${ASSET_PREFIX}${id}`)
if (!stored) {
console.warn(`Asset not found: ${id}`)
return null
}
const objectUrl = URL.createObjectURL(file)
const blob = toBlob(stored)
if (!blob) {
console.warn(`Asset ${id} has an unreadable record`)
return null
}
const objectUrl = URL.createObjectURL(blob)
urlCache.set(id, objectUrl)
return objectUrl
} catch (error) {
Expand Down
1 change: 1 addition & 0 deletions packages/editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"./locales/fr": "./src/i18n/locales/fr/index.ts",
"./locales/it": "./src/i18n/locales/it/index.ts",
"./locales/ja": "./src/i18n/locales/ja/index.ts",
"./locales/ru": "./src/i18n/locales/ru/index.ts",
"./locales/zh-CN": "./src/i18n/locales/zh-CN/index.ts",
"./locales/pseudo": "./src/i18n/pseudo-locale.ts",
"./procedural-items": "./src/components/procedural-items/inspector.tsx",
Expand Down
4 changes: 3 additions & 1 deletion packages/editor/src/i18n/lazy-locales.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type CompiledTranslationMessages, registerCompiledMessages } from '@pascal-app/core'

export const BUNDLED_LOCALES = ['en', 'zh-CN', 'fr', 'es', 'ja', 'it'] as const
export const BUNDLED_LOCALES = ['en', 'zh-CN', 'fr', 'es', 'ja', 'it', 'ru'] as const
export type BundledLocale = (typeof BUNDLED_LOCALES)[number]

export type LocaleCatalog = {
Expand Down Expand Up @@ -77,6 +77,8 @@ async function importLocaleMessages(locale: BundledLocale): Promise<CompiledTran
return (await import('./locales/ja/messages')).messages
case 'it':
return (await import('./locales/it/messages')).messages
case 'ru':
return (await import('./locales/ru/messages')).messages
}
}

Expand Down
48 changes: 47 additions & 1 deletion packages/editor/src/i18n/locales.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { bundledLocalePacks, registerBundledLocales } from './locales'
import { locale as frenchLocale, registerLocale as registerFrenchLocale } from './locales/fr'
import { locale as italianLocale, registerLocale as registerItalianLocale } from './locales/it'
import { registerLocale as registerRussianLocale, locale as russianLocale } from './locales/ru'

afterEach(() => {
setLocale('en')
Expand All @@ -22,6 +23,8 @@ test('resolveBundledLocale maps exact, script, and base locales without crossing
expect(resolveBundledLocale('es-MX')).toBe('es')
expect(resolveBundledLocale('ja-JP')).toBe('ja')
expect(resolveBundledLocale('it-IT')).toBe('it')
expect(resolveBundledLocale('ru')).toBe('ru')
expect(resolveBundledLocale('ru-RU')).toBe('ru')
expect(resolveBundledLocale('zh-CN')).toBe('zh-CN')
expect(resolveBundledLocale('zh-Hans')).toBe('zh-CN')
expect(resolveBundledLocale('zh-Hans-CN')).toBe('zh-CN')
Expand Down Expand Up @@ -55,7 +58,15 @@ test('per-locale entry point and loadBundledLocale register only the requested l
})

test('synchronous locales entry point preserves bundledLocalePacks and registerBundledLocales', () => {
expect(Object.keys(bundledLocalePacks).sort()).toEqual(['en', 'es', 'fr', 'it', 'ja', 'zh-CN'])
expect(Object.keys(bundledLocalePacks).sort()).toEqual([
'en',
'es',
'fr',
'it',
'ja',
'ru',
'zh-CN',
])
const ret = registerBundledLocales()
expect(ret).toBeUndefined()

Expand All @@ -64,6 +75,7 @@ test('synchronous locales entry point preserves bundledLocalePacks and registerB
fr: ['Paramètres d’affichage', 'Pièces'],
es: ['Ajustes de visualización', 'Estancias'],
ja: ['表示設定', '部屋'],
ru: ['Настройки отображения', 'Комнаты'],
} as const

for (const [locale, [display, rooms]] of Object.entries(expectations)) {
Expand Down Expand Up @@ -95,6 +107,40 @@ test('loading Italian on demand serves reviewed entries and keeps drafts in Engl
expect(translate('editor.sidebar.panels.sitePanel.site', 'Site')).toBe('Sito')
})

test('the Russian entry point registers only Russian', () => {
expect(russianLocale).toBe('ru')
expect(isBundledLocaleLoaded('ru-RU')).toBe(false)
registerRussianLocale()
expect(isBundledLocaleLoaded('ru-RU')).toBe(true)
expect(isBundledLocaleLoaded('fr')).toBe(false)
})

test('loading Russian on demand serves reviewed entries and keeps drafts in English', async () => {
expect(isBundledLocaleLoaded('ru-RU')).toBe(false)
const loaded = await loadBundledLocale('ru-RU')
expect(loaded?.locale).toBe('ru')
expect(isBundledLocaleLoaded('ru')).toBe(true)
expect(isBundledLocaleLoaded('fr')).toBe(false)
setLocale('ru-RU')

expect(translate('viewer.display.title', 'Display settings')).toBe('Настройки отображения')
const toolCount = '{count, plural, one {# tool} other {# tools}}'
expect(translate('app.lib.buildPanelModel.toolCount', toolCount, { count: 1 })).toBe(
'1 инструмент',
)
expect(translate('app.lib.buildPanelModel.toolCount', toolCount, { count: 2 })).toBe(
'2 инструмента',
)
expect(translate('app.lib.buildPanelModel.toolCount', toolCount, { count: 5 })).toBe(
'5 инструментов',
)
expect(translate('app.lib.buildPanelModel.toolCount', toolCount, { count: 21 })).toBe(
'21 инструмент',
)
// A draft (fuzzy, Review: required) is not compiled, so it falls back to English.
expect(translate('node.hedge.label', 'Hedge')).toBe('Hedge')
})

test('Simplified Chinese aliases use zh-CN without affecting Traditional Chinese', () => {
registerBundledLocales()

Expand Down
2 changes: 2 additions & 0 deletions packages/editor/src/i18n/locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { messages as es } from './locales/es/messages'
import { messages as fr } from './locales/fr/messages'
import { messages as it } from './locales/it/messages'
import { messages as ja } from './locales/ja/messages'
import { messages as ru } from './locales/ru/messages'
import { messages as zhCN } from './locales/zh-CN/messages'

export type { BundledLocale, LocaleCatalog }
Expand All @@ -15,6 +16,7 @@ export const bundledLocalePacks: Record<BundledLocale, LocaleCatalog> = {
es: { locale: 'es', messages: es },
ja: { locale: 'ja', messages: ja },
it: { locale: 'it', messages: it },
ru: { locale: 'ru', messages: ru },
}

export function registerBundledLocales(): void {
Expand Down
9 changes: 9 additions & 0 deletions packages/editor/src/i18n/locales/ru/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { registerBundledCatalog } from '../../lazy-locales'
import { messages } from './messages'

export const locale = 'ru' as const
export { messages }

export function registerLocale(): void {
registerBundledCatalog({ locale, messages })
}
Loading
Loading