Skip to content

Commit 76e6323

Browse files
committed
Add SSR support for v-t directive
1 parent e6fa035 commit 76e6323

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

nuxt-2/components/Tutorial.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
<SwitchLocale />
2121

2222
<p class="mt-4 pt-1">
23-
Directive: <span v-t:message-from-ftl />
23+
Directive: <span class="text-gray-600" v-t:message-from-ftl />
2424
</p>
2525
<p class="mt-4 pt-1">
26-
Method: <span>{{ $t('message-from-ftl') }}</span>
26+
Method: <span class="text-gray-600">{{ $t('message-from-ftl') }}</span>
2727
</p>
2828
</div>
2929
<div class="flex justify-center pt-4 space-x-2">

nuxt-2/locales/en.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
message-from-ftl = This is a message from English ftl file
2+
.title = English title

nuxt-2/modules/fluent-vue.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,45 @@ export default function FluentVueModule () {
1212
type: 'javascript/auto',
1313
loader: require.resolve('fluent-vue-loader')
1414
})
15+
16+
const vueRule = config.module.rules.find(rule => rule.loader.includes('vue-loader'))
17+
18+
if (!vueRule) {
19+
console.error('Could not find vue-loader rule in webpack config')
20+
}
21+
22+
vueRule.options.compilerOptions = vueRule.options.compilerOptions || {}
23+
vueRule.options.compilerOptions.directives = vueRule.options.directives || {}
24+
vueRule.options.compilerOptions.directives.t = function (el, dir) {
25+
function rangeSetItem (
26+
item,
27+
range
28+
) {
29+
if (range) {
30+
if (range.start != null) {
31+
item.start = range.start
32+
}
33+
if (range.end != null) {
34+
item.end = range.end
35+
}
36+
}
37+
return item
38+
}
39+
40+
function addProp (el, name, value, range, dynamic) {
41+
(el.props || (el.props = [])).push(rangeSetItem({ name, value, dynamic }, range))
42+
el.plain = false
43+
}
44+
45+
const previousWrapData = el.wrapData
46+
el.wrapData = (code) => {
47+
if (previousWrapData)
48+
code = previousWrapData(code)
49+
50+
return `_b(${code},'${el.tag}',$ta('${dir.arg}'),false)`
51+
}
52+
53+
addProp(el, 'textContent', `_s($t('${dir.arg}'))`, dir)
54+
}
1555
})
1656
}

0 commit comments

Comments
 (0)
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