Skip to content

Commit 98e7150

Browse files
committed
Add nuxt 3 example
1 parent f11b183 commit 98e7150

File tree

13 files changed

+6461
-0
lines changed

13 files changed

+6461
-0
lines changed

nuxt-3/.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Nuxt dev/build outputs
2+
.output
3+
.data
4+
.nuxt
5+
.nitro
6+
.cache
7+
dist
8+
9+
# Node dependencies
10+
node_modules
11+
12+
# Logs
13+
logs
14+
*.log
15+
16+
# Misc
17+
.DS_Store
18+
.fleet
19+
.idea
20+
21+
# Local env files
22+
.env
23+
.env.*
24+
!.env.example

nuxt-3/App.vue

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<template>
2+
<div>
3+
<h3>Examples</h3>
4+
5+
<h4>Change locale</h4>
6+
<div>
7+
<button @click="$changeLocale('en')">English</button>
8+
<button @click="$changeLocale('fr')">French</button>
9+
</div>
10+
11+
<h4>$t method</h4>
12+
<div>
13+
<span>{{ $t('greeting', { name: 'World' }) }}</span>
14+
</div>
15+
16+
<h4>$ta method</h4>
17+
<div>
18+
<span v-bind="$ta('greeting')">{{ $t('greeting', { name: 'World' }) }}</span>
19+
</div>
20+
21+
<h4>Directive</h4>
22+
<div>
23+
<span v-t:greeting="{ name: 'World' }"></span>
24+
</div>
25+
26+
<h4>Component</h4>
27+
<div>
28+
<i18n path="greeting" tag="div">
29+
<template #name>
30+
<b>{{ $t('user-name') }}</b>
31+
</template>
32+
</i18n>
33+
</div>
34+
35+
<h4>Composition api (useFluent)</h4>
36+
<div v-bind="compositionGreetingTa">
37+
{{ compositionGreeting }}
38+
</div>
39+
</div>
40+
</template>
41+
42+
<script lang="ts">
43+
import { defineComponent } from 'vue'
44+
import { useFluent } from 'fluent-vue'
45+
46+
export default defineComponent({
47+
name: 'typescript',
48+
setup () {
49+
const { $t, $ta } = useFluent()
50+
51+
return {
52+
compositionGreeting: computed(() => $t('greeting', { name: $t('user-name') })),
53+
compositionGreetingTa: computed(() => $ta('greeting', { name: $t('user-name') }))
54+
}
55+
},
56+
computed: {
57+
username() {
58+
return this.$t('user-name')
59+
},
60+
greeting() {
61+
return this.$ta('greeting')
62+
},
63+
},
64+
})
65+
</script>
66+
67+
<style>
68+
.test {
69+
display: block;
70+
}
71+
</style>

nuxt-3/README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Nuxt 3 Minimal Starter
2+
3+
Look at the [Nuxt 3 documentation](https://nuxt.com/docs/getting-started/introduction) to learn more.
4+
5+
## Setup
6+
7+
Make sure to install the dependencies:
8+
9+
```bash
10+
# npm
11+
npm install
12+
13+
# pnpm
14+
pnpm install
15+
16+
# yarn
17+
yarn install
18+
19+
# bun
20+
bun install
21+
```
22+
23+
## Development Server
24+
25+
Start the development server on `http://localhost:3000`:
26+
27+
```bash
28+
# npm
29+
npm run dev
30+
31+
# pnpm
32+
pnpm run dev
33+
34+
# yarn
35+
yarn dev
36+
37+
# bun
38+
bun run dev
39+
```
40+
41+
## Production
42+
43+
Build the application for production:
44+
45+
```bash
46+
# npm
47+
npm run build
48+
49+
# pnpm
50+
pnpm run build
51+
52+
# yarn
53+
yarn build
54+
55+
# bun
56+
bun run build
57+
```
58+
59+
Locally preview production build:
60+
61+
```bash
62+
# npm
63+
npm run preview
64+
65+
# pnpm
66+
pnpm run preview
67+
68+
# yarn
69+
yarn preview
70+
71+
# bun
72+
bun run preview
73+
```
74+
75+
Check out the [deployment documentation](https://nuxt.com/docs/getting-started/deployment) for more information.

nuxt-3/modules/fluent-vue.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { defineNuxtModule, addVitePlugin } from 'nuxt/kit'
2+
import { ExternalFluentPlugin } from 'unplugin-fluent-vue/vite'
3+
4+
export default defineNuxtModule({
5+
meta: {
6+
name: 'fluent-vue',
7+
},
8+
setup(_, nuxt) {
9+
addVitePlugin(ExternalFluentPlugin({
10+
locales: ['en', 'fr'],
11+
baseDir: nuxt.options.srcDir,
12+
ftlDir: nuxt.options.srcDir + '/translations',
13+
}))
14+
},
15+
});

nuxt-3/nuxt.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// https://nuxt.com/docs/api/configuration/nuxt-config
2+
export default defineNuxtConfig({
3+
devtools: { enabled: true }
4+
})

nuxt-3/package.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "nuxt-app",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"build": "nuxt build",
7+
"dev": "nuxt dev",
8+
"generate": "nuxt generate",
9+
"preview": "nuxt preview",
10+
"postinstall": "nuxt prepare"
11+
},
12+
"dependencies": {
13+
"@fluent/bundle": "^0.18.0",
14+
"fluent-vue": "^3.5.0",
15+
"nuxt": "^3.10.3",
16+
"vue": "^3.4.19",
17+
"vue-router": "^4.3.0"
18+
},
19+
"devDependencies": {
20+
"unplugin-fluent-vue": "^1.1.4"
21+
}
22+
}

nuxt-3/plugins/fluent-vue.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { FluentBundle } from '@fluent/bundle';
2+
import { createFluentVue } from 'fluent-vue';
3+
4+
export default defineNuxtPlugin((nuxtApp) => {
5+
const locales: Record<string, FluentBundle> = {
6+
'en': new FluentBundle('en'),
7+
'fr': new FluentBundle('fr'),
8+
};
9+
10+
const fluent = createFluentVue({
11+
bundles: [locales['en']],
12+
});
13+
14+
nuxtApp.vueApp.use(fluent);
15+
16+
return {
17+
provide: {
18+
changeLocale(locale: string) {
19+
const bundle = locales[locale] ?? locales['en'];
20+
fluent.bundles = [bundle];
21+
}
22+
}
23+
}
24+
});

0 commit comments

Comments
 (0)