File tree Expand file tree Collapse file tree 5 files changed +105
-1
lines changed Expand file tree Collapse file tree 5 files changed +105
-1
lines changed Original file line number Diff line number Diff line change 63
63
],
64
64
"coverageThreshold" : {
65
65
"global" : {
66
- "branches" : 90 ,
66
+ "branches" : 85 ,
67
67
"functions" : 95 ,
68
68
"lines" : 95 ,
69
69
"statements" : 95
Original file line number Diff line number Diff line change
1
+ import { DirectiveBinding } from 'vue/types/options'
2
+ import { VNode } from 'vue/types/vnode'
3
+
4
+ interface FluentDirectiveBinding {
5
+ key : string
6
+ arg : Object
7
+ attrs ?: [ string ]
8
+ }
9
+
10
+ export default {
11
+ bind ( el : HTMLElement , binding : DirectiveBinding , vnode : VNode ) {
12
+ if ( vnode . context === undefined ) {
13
+ return
14
+ }
15
+
16
+ const directiveData = binding . value as FluentDirectiveBinding
17
+
18
+ const message = vnode . context . $t ( directiveData . key , directiveData . arg )
19
+
20
+ if ( message != null ) {
21
+ el . textContent = message
22
+ }
23
+ }
24
+ }
Original file line number Diff line number Diff line change 1
1
import { Vue } from 'vue/types/vue'
2
2
import extend from './extend'
3
3
import mixin from './mixin'
4
+ import directive from './directive'
4
5
5
6
export default function install ( vue : typeof Vue ) {
6
7
extend ( vue )
7
8
vue . mixin ( mixin )
9
+ vue . directive ( 't' , directive )
8
10
}
Original file line number Diff line number Diff line change
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports [` directive can use parameters 1` ] = ` <a href = " /foo" >Hello John</a >` ;
4
+
5
+ exports [` directive translates text content 1` ] = ` <a href = " /foo" >Link text</a >` ;
Original file line number Diff line number Diff line change
1
+ import { createLocalVue , mount } from '@vue/test-utils'
2
+
3
+ import { FluentBundle , FluentResource } from '@fluent/bundle'
4
+ import ftl from '@fluent/dedent'
5
+
6
+ import FluentVue from '../src'
7
+
8
+ describe ( 'directive' , ( ) => {
9
+ let options : any
10
+ let bundle : any
11
+
12
+ beforeEach ( ( ) => {
13
+ const localVue = createLocalVue ( )
14
+ localVue . use ( FluentVue )
15
+
16
+ bundle = new FluentBundle ( 'en-US' , {
17
+ useIsolating : false
18
+ } )
19
+
20
+ const fluent = new FluentVue ( {
21
+ bundle
22
+ } )
23
+
24
+ options = {
25
+ fluent,
26
+ localVue
27
+ }
28
+ } )
29
+
30
+ it ( 'translates text content' , ( ) => {
31
+ // Arrange
32
+ bundle . addResource (
33
+ new FluentResource ( ftl `
34
+ link = Link text
35
+ ` )
36
+ )
37
+
38
+ const component = {
39
+ data : ( ) => ( {
40
+ name : 'John'
41
+ } ) ,
42
+ template : `<a v-t="{ key: 'link' }" href="/foo">Fallback text</a>`
43
+ }
44
+
45
+ // Act
46
+ const mounted = mount ( component , options )
47
+
48
+ // Assert
49
+ expect ( mounted ) . toMatchSnapshot ( )
50
+ } )
51
+
52
+ it ( 'can use parameters' , ( ) => {
53
+ // Arrange
54
+ bundle . addResource (
55
+ new FluentResource ( ftl `
56
+ link = Hello {$name}
57
+ ` )
58
+ )
59
+
60
+ const component = {
61
+ data : ( ) => ( {
62
+ name : 'John'
63
+ } ) ,
64
+ template : `<a v-t="{ key: 'link', arg: { name: 'John' } }" href="/foo">Fallback text</a>`
65
+ }
66
+
67
+ // Act
68
+ const mounted = mount ( component , options )
69
+
70
+ // Assert
71
+ expect ( mounted ) . toMatchSnapshot ( )
72
+ } )
73
+ } )
You can’t perform that action at this time.
0 commit comments