Skip to content

Add devtools integration #918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Feb 14, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add display of component translations
  • Loading branch information
Demivan committed Feb 14, 2025
commit d3e32f25f939c08ae0311760566f3c4cda699ad2
66 changes: 48 additions & 18 deletions src/devtools/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type { FluentBundle } from '@fluent/bundle'

import type { FluentResource } from '@fluent/bundle'
import type { FluentVue } from 'src'

import type { App, ComponentInternalInstance } from 'vue-demi'
import type { ResolvedOptions } from '../types'
import { FluentBundle } from '@fluent/bundle'
import { setupDevToolsPlugin } from '@vue/devtools-api'
import { getCurrentInstance, watchEffect } from 'vue-demi'
import { computed, getCurrentInstance, watchEffect } from 'vue-demi'
import pseudoLocalize from './pseudoLocalize'

export function registerFluentVueDevtools(app: App, options: ResolvedOptions, fluent: FluentVue) {
Expand Down Expand Up @@ -50,6 +51,14 @@ export function registerFluentVueDevtools(app: App, options: ResolvedOptions, fl
}
}, { flush: 'sync' })

const cleanBundles = computed(() => {
return [...fluent.bundles]
.map(bundle => new FluentBundle(bundle.locales, {
functions: bundle._functions,
useIsolating: bundle._useIsolating,
}))
})

setupDevToolsPlugin({
id: 'fluent-vue',
label: 'fluent-vue',
Expand Down Expand Up @@ -139,24 +148,45 @@ export function registerFluentVueDevtools(app: App, options: ResolvedOptions, fl
})

api.on.inspectComponent(({ componentInstance, instanceData }) => {
if (!componentInstance?.proxy?.$options.fluent)
return

const missing = missingTranslations.get(componentInstance)

if (missing) {
instanceData.state.push({
type: 'fluent-vue',
key: 'missingTranslations',
editable: false,
value: {
_custom: {
type: 'set',
value: [...missing.values()],
display: JSON.stringify([...missing.values()]),
for (const key of missing.values()) {
instanceData.state.push({
type: 'Missing translations',
key,
editable: false,
value: '',
})
}
}

const componentFluent = componentInstance?.proxy?.$options.fluent as Record<string, FluentResource>
if (!componentFluent)
return

const bundles = cleanBundles.value
for (const [locale, messages] of Object.entries(componentFluent)) {
const bundle = bundles.find(bundle => bundle.locales.includes(locale))

for (const message of messages.body) {
const overridesGlobal = bundle?.hasMessage(message.id) ?? false

instanceData.state.push({
type: `Component translations (${locale})`,
key: message.id,
editable: false,
value: {
_custom: {
type: 'custom',
display:
message.value
? bundle?.formatPattern(message.value, {}, [])
: `${
overridesGlobal ? '&nbsp;<span style="color:#ffa726">Global</span>' : ''}`,
},
},
},
})
})
}
}
})

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy