lutaml-openapi 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +33 -0
- data/Rakefile +16 -1
- data/frontend/dist/app.iife.js +1 -0
- data/frontend/dist/style.css +2 -0
- data/frontend/index.html +12 -0
- data/frontend/package-lock.json +2196 -0
- data/frontend/package.json +28 -0
- data/frontend/src/App.vue +74 -0
- data/frontend/src/__tests__/i18n.test.ts +102 -0
- data/frontend/src/app.ts +13 -0
- data/frontend/src/components/OverviewView.vue +29 -0
- data/frontend/src/components/PathsView.vue +47 -0
- data/frontend/src/components/SchemasView.vue +55 -0
- data/frontend/src/i18n/index.ts +84 -0
- data/frontend/src/i18n/messages.ts +63 -0
- data/frontend/src/style.css +410 -0
- data/frontend/tsconfig.json +20 -0
- data/frontend/vite.config.ts +28 -0
- data/lib/lutaml/openapi/corpus_audit.rb +85 -0
- data/lib/lutaml/openapi/document.rb +13 -12
- data/lib/lutaml/openapi/oas30.rb +4 -34
- data/lib/lutaml/openapi/spa.rb +60 -0
- data/lib/lutaml/openapi/version.rb +1 -1
- data/lib/lutaml/openapi.rb +7 -5
- data/rakelib/corpus.rake +39 -0
- data/script/axe_audit +109 -0
- metadata +28 -5
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "lutaml-openapi-docs",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite",
|
|
8
|
+
"build": "vite build",
|
|
9
|
+
"preview": "vite preview",
|
|
10
|
+
"test": "vitest run"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"flexsearch": "^0.7.43",
|
|
14
|
+
"pinia": "^2.1.0",
|
|
15
|
+
"vue": "^3.4.0",
|
|
16
|
+
"vue-router": "^4.3.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@vitejs/plugin-vue": "^6.0.10",
|
|
20
|
+
"axe-core": "^4.14.0",
|
|
21
|
+
"jsdom": "^29.1.1",
|
|
22
|
+
"terser": "^5.46.2",
|
|
23
|
+
"typescript": "^5.3.0",
|
|
24
|
+
"vite": "^8.3.5",
|
|
25
|
+
"vitest": "^5.0.5",
|
|
26
|
+
"vue-tsc": "^2.0.0"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, ref, provide, onMounted } from 'vue'
|
|
3
|
+
import OverviewView from './components/OverviewView.vue'
|
|
4
|
+
import PathsView from './components/PathsView.vue'
|
|
5
|
+
import SchemasView from './components/SchemasView.vue'
|
|
6
|
+
import { t, tf, initLocaleFromUrl, localeLabel, nextLocale, setLocale } from './i18n'
|
|
7
|
+
|
|
8
|
+
const props = defineProps<{ openapi: Record<string, any> }>()
|
|
9
|
+
provide('openapi', props.openapi)
|
|
10
|
+
|
|
11
|
+
const filter = ref('')
|
|
12
|
+
const view = ref<'overview' | 'paths' | 'schemas'>('overview')
|
|
13
|
+
const views = [
|
|
14
|
+
{ id: 'overview', label: 'nav.overview' },
|
|
15
|
+
{ id: 'paths', label: 'nav.paths' },
|
|
16
|
+
{ id: 'schemas', label: 'nav.schemas' },
|
|
17
|
+
] as const
|
|
18
|
+
|
|
19
|
+
onMounted(() => initLocaleFromUrl())
|
|
20
|
+
|
|
21
|
+
function switchLocale() {
|
|
22
|
+
setLocale(nextLocale())
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const info = computed(() => (props.openapi.info as any) || {})
|
|
26
|
+
const schemaCount = computed(
|
|
27
|
+
() => Object.keys(((props.openapi.components as any)?.schemas as any) || {}).length,
|
|
28
|
+
)
|
|
29
|
+
const pathCount = computed(() => Object.keys((props.openapi.paths as any) || {}).length)
|
|
30
|
+
</script>
|
|
31
|
+
|
|
32
|
+
<template>
|
|
33
|
+
<div class="docs">
|
|
34
|
+
<header class="docs-header">
|
|
35
|
+
<h1>{{ info.title || t('app.titleFallback') }}</h1>
|
|
36
|
+
<p v-if="info.version" class="version">
|
|
37
|
+
{{ info.title ? t('app.version') : '' }} {{ info.version }}
|
|
38
|
+
</p>
|
|
39
|
+
<input
|
|
40
|
+
v-model="filter"
|
|
41
|
+
class="filter"
|
|
42
|
+
type="search"
|
|
43
|
+
:placeholder="t('app.filterPlaceholder')"
|
|
44
|
+
:aria-label="t('app.filterAria')"
|
|
45
|
+
/>
|
|
46
|
+
<nav :aria-label="t('nav.sections')">
|
|
47
|
+
<button
|
|
48
|
+
v-for="v in views"
|
|
49
|
+
:key="v.id"
|
|
50
|
+
class="nav-btn"
|
|
51
|
+
:class="{ active: view === v.id }"
|
|
52
|
+
@click="view = v.id"
|
|
53
|
+
>
|
|
54
|
+
{{ t(v.label) }}
|
|
55
|
+
</button>
|
|
56
|
+
</nav>
|
|
57
|
+
<button
|
|
58
|
+
class="nav-btn locale-btn"
|
|
59
|
+
:title="t('app.switchLocale')"
|
|
60
|
+
@click="switchLocale"
|
|
61
|
+
>
|
|
62
|
+
{{ localeLabel(nextLocale()) }}
|
|
63
|
+
</button>
|
|
64
|
+
</header>
|
|
65
|
+
<main>
|
|
66
|
+
<OverviewView v-if="view === 'overview'" :filter="filter" />
|
|
67
|
+
<PathsView v-else-if="view === 'paths'" :filter="filter" />
|
|
68
|
+
<SchemasView v-else :filter="filter" />
|
|
69
|
+
</main>
|
|
70
|
+
<footer class="docs-footer">
|
|
71
|
+
<span>{{ tf('footer.stats', { schemas: schemaCount, paths: pathCount }) }}</span>
|
|
72
|
+
</footer>
|
|
73
|
+
</div>
|
|
74
|
+
</template>
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from 'vitest'
|
|
2
|
+
// @vitest-environment jsdom
|
|
3
|
+
import {
|
|
4
|
+
t,
|
|
5
|
+
tf,
|
|
6
|
+
setLocale,
|
|
7
|
+
locale,
|
|
8
|
+
locales,
|
|
9
|
+
localeLabel,
|
|
10
|
+
isLocale,
|
|
11
|
+
nextLocale,
|
|
12
|
+
directionFor,
|
|
13
|
+
applyDocumentLocale,
|
|
14
|
+
initLocaleFromUrl,
|
|
15
|
+
} from '../i18n'
|
|
16
|
+
import { messages } from '../i18n/messages'
|
|
17
|
+
|
|
18
|
+
describe('i18n', () => {
|
|
19
|
+
beforeEach(() => setLocale('en'))
|
|
20
|
+
|
|
21
|
+
it('looks up strings in the active locale', () => {
|
|
22
|
+
expect(t('nav.overview')).toBe('Overview')
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('falls back to English, then to the key itself', () => {
|
|
26
|
+
expect(t('nav.paths')).toBe(messages.en['nav.paths'])
|
|
27
|
+
// @ts-expect-error — deliberate unknown key at runtime
|
|
28
|
+
expect(t('nav.doesNotExist')).toBe('nav.doesNotExist')
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('interpolates parameters', () => {
|
|
32
|
+
expect(tf('footer.stats', { schemas: 3, paths: 7 }))
|
|
33
|
+
.toBe('3 schemas · 7 paths')
|
|
34
|
+
expect(tf('schemas.propertiesOf', { name: 'thing' }))
|
|
35
|
+
.toBe('Properties of thing')
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('switches locales', () => {
|
|
39
|
+
setLocale('en')
|
|
40
|
+
expect(locale()).toBe('en')
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('maps locales to writing directions', () => {
|
|
44
|
+
expect(directionFor('en')).toBe('ltr')
|
|
45
|
+
expect(directionFor('ar')).toBe('rtl')
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('mirrors lang and dir onto the document element', () => {
|
|
49
|
+
applyDocumentLocale('en')
|
|
50
|
+
expect(document.documentElement.lang).toBe('en')
|
|
51
|
+
expect(document.documentElement.dir).toBe('ltr')
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('translates every key in Arabic and mirrors RTL for it', () => {
|
|
55
|
+
setLocale('ar')
|
|
56
|
+
expect(locale()).toBe('ar')
|
|
57
|
+
expect(t('nav.schemas')).toBe('الأنماط')
|
|
58
|
+
expect(tf('footer.stats', { schemas: 2, paths: 5 }))
|
|
59
|
+
.toBe('2 أنماط · 5 مسارات')
|
|
60
|
+
expect(document.documentElement.dir).toBe('rtl')
|
|
61
|
+
expect(document.documentElement.lang).toBe('ar')
|
|
62
|
+
setLocale('en')
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('falls back to English for keys a locale has not translated', () => {
|
|
66
|
+
const ar = messages.ar as Record<string, string>
|
|
67
|
+
const en = messages.en as Record<string, string>
|
|
68
|
+
const untranslated = Object.keys(en).find((k) => !(k in ar))
|
|
69
|
+
if (untranslated) {
|
|
70
|
+
setLocale('ar')
|
|
71
|
+
expect(t(untranslated as never)).toBe(en[untranslated])
|
|
72
|
+
setLocale('en')
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
it('exposes the locale list, labels, and the cycle', () => {
|
|
77
|
+
expect(locales()).toEqual(['en', 'ar'])
|
|
78
|
+
expect(localeLabel('ar')).toBe('العربية')
|
|
79
|
+
expect(nextLocale()).toBe('ar')
|
|
80
|
+
setLocale('ar')
|
|
81
|
+
expect(nextLocale()).toBe('en')
|
|
82
|
+
setLocale('en')
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('guards isLocale against unknown values', () => {
|
|
86
|
+
expect(isLocale('ar')).toBe(true)
|
|
87
|
+
expect(isLocale('xx')).toBe(false)
|
|
88
|
+
expect(isLocale(null)).toBe(false)
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it('boots the locale from ?locale=, else keeps the default', () => {
|
|
92
|
+
initLocaleFromUrl('?locale=ar')
|
|
93
|
+
expect(locale()).toBe('ar')
|
|
94
|
+
expect(document.documentElement.dir).toBe('rtl')
|
|
95
|
+
setLocale('en')
|
|
96
|
+
initLocaleFromUrl('?locale=xx')
|
|
97
|
+
expect(locale()).toBe('en')
|
|
98
|
+
expect(document.documentElement.dir).toBe('ltr')
|
|
99
|
+
initLocaleFromUrl('')
|
|
100
|
+
expect(locale()).toBe('en')
|
|
101
|
+
})
|
|
102
|
+
})
|
data/frontend/src/app.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createApp } from 'vue'
|
|
2
|
+
import App from './App.vue'
|
|
3
|
+
import './style.css'
|
|
4
|
+
|
|
5
|
+
declare global {
|
|
6
|
+
interface Window {
|
|
7
|
+
OPENAPI_DATA?: Record<string, unknown>
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const data = window.OPENAPI_DATA || {}
|
|
12
|
+
const app = createApp(App, { openapi: data })
|
|
13
|
+
app.mount('#app')
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { inject, computed } from 'vue'
|
|
3
|
+
import { t } from '../i18n'
|
|
4
|
+
|
|
5
|
+
const openapi = inject<Record<string, any>>('openapi') || {}
|
|
6
|
+
const props = defineProps<{ filter: string }>()
|
|
7
|
+
|
|
8
|
+
const info = computed(() => (openapi.info as any) || {})
|
|
9
|
+
const servers = computed(() => (openapi.servers as any[]) || [])
|
|
10
|
+
const shown = computed(() => {
|
|
11
|
+
const q = props.filter.toLowerCase()
|
|
12
|
+
if (!q) return servers.value
|
|
13
|
+
return servers.value.filter((s) => JSON.stringify(s).toLowerCase().includes(q))
|
|
14
|
+
})
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<template>
|
|
18
|
+
<section :aria-label="t('overview.heading')">
|
|
19
|
+
<h2>{{ t('overview.heading') }}</h2>
|
|
20
|
+
<p v-if="info.description">{{ info.description }}</p>
|
|
21
|
+
<h3 v-if="shown.length">{{ t('overview.servers') }}</h3>
|
|
22
|
+
<ul>
|
|
23
|
+
<li v-for="s in shown" :key="s.url">
|
|
24
|
+
<code>{{ s.url }}</code> — {{ s.protocol || 'https' }}
|
|
25
|
+
<span v-if="s.description">: {{ s.description }}</span>
|
|
26
|
+
</li>
|
|
27
|
+
</ul>
|
|
28
|
+
</section>
|
|
29
|
+
</template>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { inject, computed } from 'vue'
|
|
3
|
+
import { t } from '../i18n'
|
|
4
|
+
|
|
5
|
+
const openapi = inject<Record<string, any>>('openapi') || {}
|
|
6
|
+
const props = defineProps<{ filter: string }>()
|
|
7
|
+
|
|
8
|
+
const METHODS = ['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace']
|
|
9
|
+
|
|
10
|
+
const entries = computed(() => {
|
|
11
|
+
const paths = (openapi.paths as any) || {}
|
|
12
|
+
const q = props.filter.toLowerCase()
|
|
13
|
+
return Object.entries(paths)
|
|
14
|
+
.filter(([path, item]) => {
|
|
15
|
+
if (!q) return true
|
|
16
|
+
return (
|
|
17
|
+
path.toLowerCase().includes(q) ||
|
|
18
|
+
JSON.stringify(item).toLowerCase().includes(q)
|
|
19
|
+
)
|
|
20
|
+
})
|
|
21
|
+
.map(([path, item]) => ({
|
|
22
|
+
path,
|
|
23
|
+
operations: Object.entries(item as any)
|
|
24
|
+
.filter(([m, op]) => METHODS.includes(m) && op && typeof op === 'object')
|
|
25
|
+
.map(([m, op]) => ({
|
|
26
|
+
method: m.toUpperCase(),
|
|
27
|
+
summary: (op as any).summary || '',
|
|
28
|
+
description: (op as any).description || '',
|
|
29
|
+
})),
|
|
30
|
+
}))
|
|
31
|
+
})
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<template>
|
|
35
|
+
<section :aria-label="t('paths.heading')">
|
|
36
|
+
<h2>{{ t('paths.heading') }}</h2>
|
|
37
|
+
<div v-for="e in entries" :key="e.path" class="path">
|
|
38
|
+
<h3><code>{{ e.path }}</code></h3>
|
|
39
|
+
<div v-for="op in e.operations" :key="op.method" class="op">
|
|
40
|
+
<span class="method" :class="op.method.toLowerCase()">{{ op.method }}</span>
|
|
41
|
+
<strong v-if="op.summary"> {{ op.summary }}</strong>
|
|
42
|
+
<p v-if="op.description">{{ op.description }}</p>
|
|
43
|
+
</div>
|
|
44
|
+
</div>
|
|
45
|
+
<p v-if="!entries.length">{{ t('paths.noMatch') }}</p>
|
|
46
|
+
</section>
|
|
47
|
+
</template>
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { inject, computed } from 'vue'
|
|
3
|
+
import { t, tf } from '../i18n'
|
|
4
|
+
|
|
5
|
+
const openapi = inject<Record<string, any>>('openapi') || {}
|
|
6
|
+
const props = defineProps<{ filter: string }>()
|
|
7
|
+
|
|
8
|
+
const entries = computed(() => {
|
|
9
|
+
const schemas = ((openapi.components as any)?.schemas as any) || {}
|
|
10
|
+
const q = props.filter.toLowerCase()
|
|
11
|
+
return Object.entries(schemas)
|
|
12
|
+
.filter(([name, schema]) => {
|
|
13
|
+
if (!q) return true
|
|
14
|
+
return (
|
|
15
|
+
name.toLowerCase().includes(q) ||
|
|
16
|
+
JSON.stringify(schema).toLowerCase().includes(q)
|
|
17
|
+
)
|
|
18
|
+
})
|
|
19
|
+
.map(([name, schema]) => {
|
|
20
|
+
const s = schema as any
|
|
21
|
+
const properties = Object.entries(s.properties || {}).map(
|
|
22
|
+
([pname, p]: [string, any]) => ({
|
|
23
|
+
name: pname,
|
|
24
|
+
type: Array.isArray(p.type) ? p.type.join(' | ') : p.type || '',
|
|
25
|
+
description: p.description || '',
|
|
26
|
+
}),
|
|
27
|
+
)
|
|
28
|
+
return { name, description: s.description || '', type: s.type, properties }
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
<template>
|
|
34
|
+
<section :aria-label="t('schemas.heading')">
|
|
35
|
+
<h2>{{ t('schemas.heading') }}</h2>
|
|
36
|
+
<div v-for="e in entries" :key="e.name" class="schema">
|
|
37
|
+
<h3>{{ e.name }}</h3>
|
|
38
|
+
<p v-if="e.description">{{ e.description }}</p>
|
|
39
|
+
<table v-if="e.properties.length">
|
|
40
|
+
<caption>{{ tf('schemas.propertiesOf', { name: e.name }) }}</caption>
|
|
41
|
+
<thead>
|
|
42
|
+
<tr><th>{{ t('schemas.name') }}</th><th>{{ t('schemas.type') }}</th><th>{{ t('schemas.description') }}</th></tr>
|
|
43
|
+
</thead>
|
|
44
|
+
<tbody>
|
|
45
|
+
<tr v-for="p in e.properties" :key="p.name">
|
|
46
|
+
<td><code>{{ p.name }}</code></td>
|
|
47
|
+
<td><code>{{ p.type }}</code></td>
|
|
48
|
+
<td>{{ p.description }}</td>
|
|
49
|
+
</tr>
|
|
50
|
+
</tbody>
|
|
51
|
+
</table>
|
|
52
|
+
</div>
|
|
53
|
+
<p v-if="!entries.length">{{ t('schemas.noMatch') }}</p>
|
|
54
|
+
</section>
|
|
55
|
+
</template>
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { ref } from 'vue'
|
|
2
|
+
import { messages, type Locale, type MessageKey } from './messages'
|
|
3
|
+
|
|
4
|
+
// The locale rides a Vue ref so every rendered string is a reactive
|
|
5
|
+
// dependency: flipping the locale re-renders exactly the components
|
|
6
|
+
// that showed translated text.
|
|
7
|
+
const activeLocale = ref<Locale>('en')
|
|
8
|
+
|
|
9
|
+
/** Native names, shown on the switch button for the TARGET locale. */
|
|
10
|
+
const LOCALE_LABELS: Record<Locale, string> = {
|
|
11
|
+
en: 'English',
|
|
12
|
+
ar: 'العربية',
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Writing direction per locale — RTL locales must mirror the layout. */
|
|
16
|
+
const RTL_LOCALES: readonly string[] = ['ar', 'he', 'fa', 'ur']
|
|
17
|
+
|
|
18
|
+
export function locale(): Locale {
|
|
19
|
+
return activeLocale.value
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function locales(): Locale[] {
|
|
23
|
+
return Object.keys(messages) as Locale[]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function localeLabel(id: Locale): string {
|
|
27
|
+
return LOCALE_LABELS[id]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function isLocale(value: unknown): value is Locale {
|
|
31
|
+
return typeof value === 'string' && locales().includes(value as Locale)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The locale the switch button would move to (single-step cycle). */
|
|
35
|
+
export function nextLocale(): Locale {
|
|
36
|
+
const all = locales()
|
|
37
|
+
return all[(all.indexOf(activeLocale.value) + 1) % all.length]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function directionFor(id: Locale): 'ltr' | 'rtl' {
|
|
41
|
+
return RTL_LOCALES.includes(id) ? 'rtl' : 'ltr'
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Mirror <html lang/dir> so layout, fonts and scrollbars follow the locale. */
|
|
45
|
+
export function applyDocumentLocale(id: Locale = activeLocale.value): void {
|
|
46
|
+
if (typeof document === 'undefined') return
|
|
47
|
+
document.documentElement.lang = id
|
|
48
|
+
document.documentElement.dir = directionFor(id)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Boot-time locale: an explicit `?locale=` wins, else the default. */
|
|
52
|
+
export function initLocaleFromUrl(
|
|
53
|
+
search: string = typeof window === 'undefined' ? '' : window.location.search,
|
|
54
|
+
): void {
|
|
55
|
+
const requested = new URLSearchParams(search).get('locale')
|
|
56
|
+
if (isLocale(requested)) {
|
|
57
|
+
setLocale(requested)
|
|
58
|
+
} else {
|
|
59
|
+
applyDocumentLocale()
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function setLocale(next: Locale): void {
|
|
64
|
+
activeLocale.value = next
|
|
65
|
+
applyDocumentLocale(next)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Look up a UI string in the active locale, falling back to English. */
|
|
69
|
+
export function t(key: MessageKey): string {
|
|
70
|
+
const table = messages[activeLocale.value] as Record<string, string>
|
|
71
|
+
const english = messages.en as Record<string, string>
|
|
72
|
+
return table[key] ?? english[key] ?? key
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Interpolated variant: t('search.noResultsFor', { query: 'foo' }) */
|
|
76
|
+
export function tf(
|
|
77
|
+
key: MessageKey,
|
|
78
|
+
params: Record<string, string | number>,
|
|
79
|
+
): string {
|
|
80
|
+
return Object.entries(params).reduce(
|
|
81
|
+
(text, [name, value]) => text.replaceAll(`{${name}}`, String(value)),
|
|
82
|
+
t(key),
|
|
83
|
+
)
|
|
84
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// UI string catalog. `en` is the source of truth; additional locales add
|
|
2
|
+
// entries under their own key. Keys are flat and namespaced per component.
|
|
3
|
+
// A missing key in any locale is a type error against messages.en.
|
|
4
|
+
export const messages = {
|
|
5
|
+
en: {
|
|
6
|
+
'app.titleFallback': 'OpenAPI document',
|
|
7
|
+
'app.version': 'version',
|
|
8
|
+
'app.filterPlaceholder': 'Filter…',
|
|
9
|
+
'app.filterAria': 'Filter sections',
|
|
10
|
+
'app.switchLocale': 'Switch locale',
|
|
11
|
+
|
|
12
|
+
'nav.overview': 'Overview',
|
|
13
|
+
'nav.paths': 'Paths',
|
|
14
|
+
'nav.schemas': 'Schemas',
|
|
15
|
+
'nav.sections': 'Sections',
|
|
16
|
+
|
|
17
|
+
'overview.heading': 'Overview',
|
|
18
|
+
'overview.servers': 'Servers',
|
|
19
|
+
|
|
20
|
+
'paths.heading': 'Paths',
|
|
21
|
+
'paths.noMatch': 'No paths match the filter.',
|
|
22
|
+
|
|
23
|
+
'schemas.heading': 'Schemas',
|
|
24
|
+
'schemas.propertiesOf': 'Properties of {name}',
|
|
25
|
+
'schemas.name': 'Name',
|
|
26
|
+
'schemas.type': 'Type',
|
|
27
|
+
'schemas.description': 'Description',
|
|
28
|
+
'schemas.noMatch': 'No schemas match the filter.',
|
|
29
|
+
|
|
30
|
+
'footer.stats': '{schemas} schemas · {paths} paths',
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
ar: {
|
|
34
|
+
'app.titleFallback': 'وثيقة OpenAPI',
|
|
35
|
+
'app.version': 'الإصدار',
|
|
36
|
+
'app.filterPlaceholder': 'تصفية…',
|
|
37
|
+
'app.filterAria': 'تصفية الأقسام',
|
|
38
|
+
'app.switchLocale': 'تبديل اللغة',
|
|
39
|
+
|
|
40
|
+
'nav.overview': 'نظرة عامة',
|
|
41
|
+
'nav.paths': 'المسارات',
|
|
42
|
+
'nav.schemas': 'الأنماط',
|
|
43
|
+
'nav.sections': 'الأقسام',
|
|
44
|
+
|
|
45
|
+
'overview.heading': 'نظرة عامة',
|
|
46
|
+
'overview.servers': 'الخوادم',
|
|
47
|
+
|
|
48
|
+
'paths.heading': 'المسارات',
|
|
49
|
+
'paths.noMatch': 'لا توجد مسارات مطابقة للتصفية.',
|
|
50
|
+
|
|
51
|
+
'schemas.heading': 'الأنماط',
|
|
52
|
+
'schemas.propertiesOf': 'خصائص {name}',
|
|
53
|
+
'schemas.name': 'الاسم',
|
|
54
|
+
'schemas.type': 'النوع',
|
|
55
|
+
'schemas.description': 'الوصف',
|
|
56
|
+
'schemas.noMatch': 'لا توجد أنماط مطابقة للتصفية.',
|
|
57
|
+
|
|
58
|
+
'footer.stats': '{schemas} أنماط · {paths} مسارات',
|
|
59
|
+
},
|
|
60
|
+
} as const
|
|
61
|
+
|
|
62
|
+
export type Locale = keyof typeof messages
|
|
63
|
+
export type MessageKey = keyof typeof messages.en
|