-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(component): add component for component interpolation
- Loading branch information
Showing
4 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Component } from 'vue/types' | ||
|
||
export default { | ||
name: 'i18n', | ||
functional: true, | ||
props: { | ||
path: { type: String, required: true }, | ||
tag: { type: String, default: 'span' }, | ||
data: { type: Object, default: () => ({}) } | ||
}, | ||
render(h, { parent, props, data }) { | ||
const key = props.path | ||
const fluent = parent.$fluent | ||
|
||
const translation = fluent.format(key) | ||
|
||
return h(props.tag, data, translation) | ||
} | ||
} as Component |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`component handles simple translations 1`] = `<span>Inner data</span>`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { createLocalVue, mount } from '@vue/test-utils' | ||
|
||
import { FluentBundle, FluentResource } from '@fluent/bundle' | ||
import ftl from '@fluent/dedent' | ||
|
||
import FluentVue from '../../src' | ||
|
||
describe('component', () => { | ||
let options: any | ||
let bundle: FluentBundle | ||
|
||
beforeEach(() => { | ||
const localVue = createLocalVue() | ||
localVue.use(FluentVue) | ||
|
||
bundle = new FluentBundle('en-US', { | ||
useIsolating: false | ||
}) | ||
|
||
const fluent = new FluentVue({ | ||
bundles: [bundle] | ||
}) | ||
|
||
options = { | ||
fluent, | ||
localVue | ||
} | ||
}) | ||
|
||
it('handles simple translations', () => { | ||
// Arrange | ||
bundle.addResource( | ||
new FluentResource(ftl` | ||
key = Inner data | ||
`) | ||
) | ||
|
||
const component = { | ||
template: '<i18n path="key"></i18n>' | ||
} | ||
|
||
// Act | ||
const mounted = mount(component, options) | ||
|
||
// Assert | ||
expect(mounted).toMatchSnapshot() | ||
}) | ||
}) |