-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement mergedWith helper method for global translations (#877)
- Loading branch information
Showing
3 changed files
with
111 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { beforeEach, describe, expect, it } from 'vitest' | ||
|
||
import { FluentBundle, FluentResource } from '@fluent/bundle' | ||
|
||
import type { FluentVue } from '../src' | ||
import { createFluentVue } from '../src' | ||
|
||
describe('mergedWith', () => { | ||
let bundleEn: FluentBundle | ||
let bundleUk: FluentBundle | ||
|
||
let fluent: FluentVue | ||
|
||
beforeEach(() => { | ||
bundleEn = new FluentBundle('en') | ||
bundleUk = new FluentBundle('uk') | ||
|
||
fluent = createFluentVue({ | ||
bundles: [bundleEn, bundleUk], | ||
}) | ||
}) | ||
|
||
it('returns global translations', () => { | ||
// Arrange | ||
bundleEn.addResource(new FluentResource('hello = Hello, World!')) | ||
|
||
// Act | ||
const { $t } = fluent.mergedWith({ en: new FluentResource('hello-two = Hello, World!') }) | ||
const translation = $t('hello') | ||
|
||
// Assert | ||
expect(translation).toEqual('Hello, World!') | ||
}) | ||
|
||
it('returns merged translation', () => { | ||
// Arrange | ||
bundleEn.addResource(new FluentResource('hello = Hello, World!')) | ||
|
||
// Act | ||
const { $t } = fluent.mergedWith({ en: new FluentResource('hello-two = Hello, World merged!') }) | ||
const translation = $t('hello-two') | ||
|
||
// Assert | ||
expect(translation).toEqual('Hello, World merged!') | ||
}) | ||
|
||
it('returns overridden global translations', () => { | ||
// Arrange | ||
bundleEn.addResource(new FluentResource('hello = Hello, World!')) | ||
|
||
// Act | ||
const { $t } = fluent.mergedWith({ en: new FluentResource('hello = Hello, World overridden!') }) | ||
const translation = $t('hello') | ||
|
||
// Assert | ||
expect(translation).toEqual('Hello, World overridden!') | ||
}) | ||
|
||
it('falls back to the next bundle', () => { | ||
// Arrange | ||
bundleEn.addResource(new FluentResource('hello = Hello, World!')) | ||
|
||
// Act | ||
const { $t } = fluent.mergedWith({ uk: new FluentResource('hello-two = Привіт, Світ!') }) | ||
const translation = $t('hello-two') | ||
|
||
// Assert | ||
expect(translation).toEqual('Привіт, Світ!') | ||
}) | ||
}) |
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