diff --git a/packages/core/index.d.ts b/packages/core/index.d.ts new file mode 100644 index 0000000..65b4d08 --- /dev/null +++ b/packages/core/index.d.ts @@ -0,0 +1,7 @@ +import type { BindingObj, BindingI18nObj } from './shared' +declare module '@vue/runtime-core' { + export interface ComponentCustomProperties { + $i18nHtml: (binding: string | BindingI18nObj) => string + $safeHtml: (binding: string | BindingObj) => string + } +} diff --git a/packages/core/plugins.d.ts b/packages/core/plugins.d.ts deleted file mode 100644 index 7c0e097..0000000 --- a/packages/core/plugins.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import type { $i18nHtml, $safeHtml } from './plugins' - -declare module 'vue' { - interface ComponentCustomProperties { - $i18nHtml: typeof $i18nHtml - $safeHtml: typeof $safeHtml - } -} diff --git a/packages/core/plugins.ts b/packages/core/plugins.ts index e7b88b7..0f30a17 100644 --- a/packages/core/plugins.ts +++ b/packages/core/plugins.ts @@ -1,6 +1,6 @@ import type { App } from 'vue' import { useI18n } from 'vue-i18n' -import type { Options, BindingObj } from './shared' +import type { Options, BindingObj, BindingI18nObj } from './shared' import { setGlobalOptions, getBindingValue, @@ -10,7 +10,7 @@ import { } from './shared' const generateHtml = - (getContentText: (binding: string | BindingObj) => string) => + (getContentText: (binding: string | BindingObj | BindingI18nObj) => string) => (binding: string | BindingObj): string => { if (!binding) return '' diff --git a/packages/core/shared.ts b/packages/core/shared.ts index 3fbfcb3..de1a043 100644 --- a/packages/core/shared.ts +++ b/packages/core/shared.ts @@ -17,6 +17,10 @@ export type BindingObj = { htmlString: string | (() => string) } & Options +export type BindingI18nObj = Omit & { + htmlString: string +} + const globalOptions = ref() export function getDefaultString( diff --git a/playgrounds/App.vue b/playgrounds/App.vue index 59a368a..abf583c 100644 --- a/playgrounds/App.vue +++ b/playgrounds/App.vue @@ -40,6 +40,7 @@

i18n

+

diff --git a/plugins/i18n-html.ts b/plugins/i18n-html.ts deleted file mode 100644 index 6fba438..0000000 --- a/plugins/i18n-html.ts +++ /dev/null @@ -1,11 +0,0 @@ -import type { App } from 'vue' - -export const i18nHtml = { - install: (app: App, options) => { - app.config.globalProperties.$translate = (key: string) => { - // retrieve a nested property in `options` - // using `key` as the path - return `${key} plugin` - } - } -} diff --git a/vite.config.ts b/vite.config.ts index e1da9d9..72a3a5f 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -9,9 +9,9 @@ export default defineConfig({ plugins: [ vue(), dts({ - include: ['packages/**/*.ts'], + include: ['packages/core/*.ts'], insertTypesEntry: true, - copyDtsFiles: false, + copyDtsFiles: true, tsConfigFilePath: './tsconfig.app.json' }) ],