This repository has been archived by the owner on Dec 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Making i18n specs more maintainable. Covering additional use case. (#366
- Loading branch information
Showing
7 changed files
with
78 additions
and
26 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,16 @@ | ||
<!-- uses special loader to load i18n blocks --> | ||
<!-- see https://github.com/intlify/vue-i18n-loader --> | ||
<!-- You can also inline the translations like <i18n>{...}</i18n> --> | ||
<i18n src="./translations.json"/> | ||
|
||
<template> | ||
<div id="app"> | ||
<label for="locale">locale</label> | ||
<select v-model="$i18n.locale" id="locale"> | ||
<option v-for="locale in $i18n.availableLocales" :key="locale"> | ||
{{ locale }} | ||
</option> | ||
</select> | ||
<p>message: {{ $t('hello') }}</p> | ||
</div> | ||
</template> |
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,11 @@ | ||
<template> | ||
<div id="app"> | ||
<label for="locale">locale</label> | ||
<select v-model="$i18n.locale" id="locale"> | ||
<option v-for="locale in $i18n.availableLocales" :key="locale"> | ||
{{ locale }} | ||
</option> | ||
</select> | ||
<p>message: {{ $t('hello') }}</p> | ||
</div> | ||
</template> |
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 |
---|---|---|
@@ -1,31 +1,43 @@ | ||
/// <reference types="cypress" /> | ||
import Vue from 'vue' | ||
import TranslatedMessage from './TranslatedMessage.vue' | ||
import TranslatedMessageWithJSON from './TranslatedJSONMessage.vue' | ||
import TranslatedMessageI18nBlock from './TranslatedI18nMessage.vue' | ||
import VueI18n from 'vue-i18n' | ||
import { mountCallback } from 'cypress-vue-unit-test' | ||
import { mount } from 'cypress-vue-unit-test' | ||
import messages from './translations.json' | ||
|
||
Vue.use(VueI18n) | ||
const i18n = new VueI18n({ locale: 'en' }) | ||
function expectHelloWorldGreeting() { | ||
cy.viewport(400, 200) | ||
const allLocales = Cypress.vue.$i18n.availableLocales | ||
|
||
describe('VueI18n', () => { | ||
beforeEach(mountCallback(TranslatedMessage, { i18n })) | ||
|
||
it('shows English, Japanese and Russian greeting', () => { | ||
cy.viewport(400, 200) | ||
// ensure we don't strip locales | ||
expect(Object.keys(messages)).to.have.members(allLocales) | ||
|
||
cy.get('select').select('en').should('have.value', 'en') | ||
cy.contains('message: hello') | ||
allLocales.forEach((locale) => { | ||
cy.get('select').select(locale).should('have.value', locale) | ||
const hello = messages[locale].hello | ||
cy.contains(hello) | ||
}) | ||
} | ||
|
||
cy.get('select').select('fa').should('have.value', 'fa') | ||
cy.contains('message: سلام دنیا') | ||
describe('VueI18n', () => { | ||
Vue.use(VueI18n) | ||
|
||
cy.get('select').select('ja').should('have.value', 'ja') | ||
cy.contains('message: こんにちは、世界') | ||
describe('with i18n block', () => { | ||
beforeEach(() => { | ||
const i18n = new VueI18n({ locale: 'en' }) | ||
mount(TranslatedMessageI18nBlock, { i18n }) | ||
}) | ||
|
||
cy.get('select').select('ru').should('have.value', 'ru') | ||
cy.contains('message: Привет мир') | ||
it('shows HelloWorld for all locales', expectHelloWorldGreeting) | ||
}) | ||
|
||
// TODO how to load messages not from i18n block but from external JSON file? | ||
// then we could reuse the messages to check the contents | ||
describe('with messages argument', () => { | ||
beforeEach(() => { | ||
const i18n = new VueI18n({ locale: 'en', messages }) | ||
mount(TranslatedMessageWithJSON, { i18n }) | ||
}) | ||
|
||
it('shows HelloWorld for all locales', expectHelloWorldGreeting) | ||
}) | ||
}) |
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,14 @@ | ||
{ | ||
"en": { | ||
"hello": "hello world!" | ||
}, | ||
"fa": { | ||
"hello": "سلام دنیا" | ||
}, | ||
"ja": { | ||
"hello": "こんにちは、世界" | ||
}, | ||
"ru": { | ||
"hello": "Привет мир" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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