Skip to content

Commit a3581fd

Browse files
committed
fix(directive): fix localization when element does not have attributes
1 parent d395b42 commit a3581fd

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

src/directive.ts

-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ export default {
2020
}
2121

2222
el.textContent = vnode.context.$fluent.formatPattern(msg.value, binding.value)
23-
if (vnode.data === undefined || vnode.data.attrs === undefined) {
24-
return
25-
}
2623

2724
for (const [attr] of Object.entries(binding.modifiers)) {
2825
el.setAttribute(

test/__snapshots__/directive.test.ts.snap

+2
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ exports[`directive can use parameters 1`] = `<a href="/foo">Hello John</a>`;
77
exports[`directive translates text content 1`] = `<a href="/foo">Link text</a>`;
88

99
exports[`directive warns about missing key arg 1`] = `<a href="/foo">Fallback text</a>`;
10+
11+
exports[`directive works without fallbacks 1`] = `<a aria-label="Localized aria">Hello John</a>`;

test/directive.test.ts

+23
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,27 @@ describe('directive', () => {
110110
// Assert
111111
expect(mounted).toMatchSnapshot()
112112
})
113+
114+
it('works without fallbacks', () => {
115+
// Arrange
116+
bundle.addResource(
117+
new FluentResource(ftl`
118+
link = Hello {$name}
119+
.aria-label = Localized aria
120+
`)
121+
)
122+
123+
const component = {
124+
data: () => ({
125+
name: 'John'
126+
}),
127+
template: `<a v-t:link.aria-label="{ name }"></a>`
128+
}
129+
130+
// Act
131+
const mounted = mount(component, options)
132+
133+
// Assert
134+
expect(mounted).toMatchSnapshot()
135+
})
113136
})

0 commit comments

Comments
 (0)