Skip to content

Commit f25fc57

Browse files
author
Antoine Monnet
committed
feat(i18n); add i18n aware vue components, with localized manifest
1 parent 36c64ca commit f25fc57

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import type { MetaObject } from '@nuxt/schema'
2+
import { defineComponent, ref } from 'vue'
3+
import { pwaInfo } from 'virtual:pwa-info'
4+
import { pwaAssetsHead } from 'virtual:pwa-assets/head'
5+
import { useHead, useLocalePath } from '#imports'
6+
7+
export default defineComponent({
8+
setup() {
9+
const meta = ref<MetaObject>({ link: [] })
10+
const localePath = useLocalePath()
11+
useHead(meta)
12+
if (pwaAssetsHead.themeColor)
13+
meta.value.meta = [{ name: 'theme-color', content: pwaAssetsHead.themeColor.content }]
14+
15+
if (pwaAssetsHead.links.length)
16+
// @ts-expect-error: links are fine
17+
meta.value.link!.push(...pwaAssetsHead.links)
18+
19+
if (pwaInfo) {
20+
const { webManifest } = pwaInfo
21+
if (webManifest) {
22+
const { href, useCredentials } = webManifest
23+
const prefix = localePath("/").replace("^/$","")
24+
if (useCredentials) {
25+
meta.value.link!.push({
26+
rel: 'manifest',
27+
href: prefix+href,
28+
crossorigin: 'use-credentials',
29+
})
30+
}
31+
else {
32+
meta.value.link!.push({
33+
rel: 'manifest',
34+
href: prefix+href,
35+
})
36+
}
37+
}
38+
}
39+
40+
return () => null
41+
},
42+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import type { MetaObject } from '@nuxt/schema'
2+
import { defineComponent, ref } from 'vue'
3+
import { pwaInfo } from 'virtual:pwa-info'
4+
import { useHead, useLocalePath } from '#imports'
5+
6+
export default defineComponent({
7+
async setup() {
8+
if (pwaInfo) {
9+
const meta = ref<MetaObject>({ link: [] })
10+
const localePath = useLocalePath()
11+
useHead(meta)
12+
13+
const { webManifest } = pwaInfo
14+
if (webManifest) {
15+
const { href, useCredentials } = webManifest
16+
const prefix = localePath("/").replace("^/$","")
17+
if (useCredentials) {
18+
meta.value.link!.push({
19+
rel: 'manifest',
20+
href: prefix+href,
21+
crossorigin: 'use-credentials',
22+
})
23+
}
24+
else {
25+
meta.value.link!.push({
26+
rel: 'manifest',
27+
href: prefix+href,
28+
})
29+
}
30+
}
31+
}
32+
33+
return () => null
34+
},
35+
})

src/utils/module.ts

+8
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,18 @@ export async function doSetup(options: PwaModuleOptions, nuxt: Nuxt) {
7272
name: 'NuxtPwaManifest',
7373
filePath: resolver.resolve(runtimeDir, 'components/VitePwaManifest'),
7474
}),
75+
addComponent({
76+
name: 'NuxtPwaManifestI18n',
77+
filePath: resolver.resolve(runtimeDir, 'components/VitePwaManifestI18n'),
78+
}),
7579
addComponent({
7680
name: 'NuxtPwaAssets',
7781
filePath: resolver.resolve(runtimeDir, 'components/NuxtPwaAssets'),
7882
}),
83+
addComponent({
84+
name: 'NuxtPwaAssetsI18n',
85+
filePath: resolver.resolve(runtimeDir, 'components/NuxtPwaAssetsI18n'),
86+
}),
7987
addComponent({
8088
name: 'PwaAppleImage',
8189
filePath: resolver.resolve(runtimeDir, 'components/PwaAppleImage.vue'),

0 commit comments

Comments
 (0)