mirror of
https://github.com/gotson/komga.git
synced 2025-12-06 16:42:24 +01:00
add locale toolbar in storybook
This commit is contained in:
parent
61ccca7100
commit
50dc9d143b
2 changed files with 33 additions and 0 deletions
9
next-ui/.storybook/locale.decorator.ts
Normal file
9
next-ui/.storybook/locale.decorator.ts
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
import type { StoryContext } from '@storybook/vue3-vite'
|
||||||
|
import { setLocale } from '@/utils/i18n/locale-helper'
|
||||||
|
|
||||||
|
export const localeDecorator = () => {
|
||||||
|
return (storyFn: () => Component, context: StoryContext) => {
|
||||||
|
setLocale(context.globals.locale)
|
||||||
|
return storyFn()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -10,6 +10,8 @@ import { PiniaColada } from '@pinia/colada'
|
||||||
import { PiniaColadaAutoRefetch } from '@pinia/colada-plugin-auto-refetch'
|
import { PiniaColadaAutoRefetch } from '@pinia/colada-plugin-auto-refetch'
|
||||||
import { vueIntl } from '@/plugins/vue-intl'
|
import { vueIntl } from '@/plugins/vue-intl'
|
||||||
import 'virtual:uno.css'
|
import 'virtual:uno.css'
|
||||||
|
import { availableLocales } from '@/utils/i18n/locale-helper'
|
||||||
|
import { localeDecorator } from './locale.decorator'
|
||||||
|
|
||||||
initialize(
|
initialize(
|
||||||
{
|
{
|
||||||
|
|
@ -18,6 +20,14 @@ initialize(
|
||||||
handlers,
|
handlers,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const locales: object[] = []
|
||||||
|
Object.entries(availableLocales).forEach(([code, name]) => {
|
||||||
|
locales.push({
|
||||||
|
value: code,
|
||||||
|
title: name,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
const preview: Preview = {
|
const preview: Preview = {
|
||||||
parameters: {
|
parameters: {
|
||||||
controls: {
|
controls: {
|
||||||
|
|
@ -35,6 +45,19 @@ const preview: Preview = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
loaders: [mswLoader],
|
loaders: [mswLoader],
|
||||||
|
globalTypes: {
|
||||||
|
locale: {
|
||||||
|
name: 'Locale',
|
||||||
|
description: 'Internationalization locale',
|
||||||
|
toolbar: {
|
||||||
|
icon: 'globe',
|
||||||
|
items: locales,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
initialGlobals: {
|
||||||
|
locale: 'en',
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
export default preview
|
export default preview
|
||||||
|
|
@ -60,4 +83,5 @@ export const decorators = [
|
||||||
},
|
},
|
||||||
defaultTheme: 'light', // The key of your default theme
|
defaultTheme: 'light', // The key of your default theme
|
||||||
}),
|
}),
|
||||||
|
localeDecorator(),
|
||||||
]
|
]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue