Skip to content
This repository has been archived by the owner on Dec 12, 2020. It is now read-only.

Commit

Permalink
fix: update i18n plugin to work (#352)
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov authored Jul 8, 2020
1 parent 604edfa commit dee2464
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 26 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ Spec | Description
<!-- prettier-ignore-start -->
Spec | Description
--- | ---
[i18n](cypress/component/advanced/i18n) | Testing component that uses [Vue I18n](https://kazupon.github.io/vue-i18n/) plugin
[mocking-axios](cypress/component/advanced/mocking-axios) | Mocking 3rd party module imports, like `axios` for fetching data
[mocking-components](cypress/component/advanced/mocking-components) | Mocking locally registered child components during tests
[mocking-imports](cypress/component/advanced/mocking-imports) | Stub ES6 imports from the tests
Expand Down
9 changes: 9 additions & 0 deletions cypress/component/advanced/i18n/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# i18n example

Using [vue-i18n](https://kazupon.github.io/vue-i18n/) and [@intlify/vue-i18n-loader](https://github.com/intlify/vue-i18n-loader/tree/master) stable.

See [TranslatedMessage.vue](TranslatedMessage.vue) and its test in [spec.js](spec.js)

![i18n test in action](./images/i18n.gif)

**Note:** the `vue-i18n-loader` requires a webpack rule, see Webpack config in the root folder.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- uses special loader to load i18n blocks -->
<!-- see http://kazupon.github.io/vue-i18n/en/sfc.html -->
<!-- see https://github.com/intlify/vue-i18n-loader -->
<i18n>
{
"en": {
Expand Down
Binary file added cypress/component/advanced/i18n/images/i18n.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
/// <reference types="cypress" />

// testing i18n component
// http://kazupon.github.io/vue-i18n
import TranslatedMessage from './TranslatedMessage.vue'
import VueI18n from 'vue-i18n'
import { mountCallback } from 'cypress-vue-unit-test'

// https://github.com/bahmutov/cypress-vue-unit-test/issues/332
describe.skip('VueI18n', () => {
describe('VueI18n', () => {
// need to use VueI18n as a plugin
const extensions = {
plugins: [VueI18n],
Expand All @@ -24,16 +21,17 @@ describe.skip('VueI18n', () => {
cy.viewport(400, 200)

cy.get('select').select('en').should('have.value', 'en')
cy.contains('message: hello')
// wait for good demo movie
cy.contains('message: hello').wait(1000)

cy.get('select').select('fa').should('have.value', 'fa')
cy.contains('message: سلام دنیا')
cy.contains('message: سلام دنیا').wait(1000)

cy.get('select').select('ja').should('have.value', 'ja')
cy.contains('message: こんにちは、世界')
cy.contains('message: こんにちは、世界').wait(1000)

cy.get('select').select('ru').should('have.value', 'ru')
cy.contains('message: Привет мир')
cy.contains('message: Привет мир').wait(1000)
})

// TODO how to load messages not from i18n block but from external JSON file?
Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"@babel/plugin-transform-modules-commonjs": "7.10.4",
"@cypress/code-coverage": "3.8.1",
"@cypress/webpack-preprocessor": "5.4.1",
"@kazupon/vue-i18n-loader": "0.5.0",
"@intlify/vue-i18n-loader": "1.0.0",
"babel-plugin-istanbul": "6.0.0",
"common-tags": "1.8.0",
"debug": "4.1.1",
Expand Down
13 changes: 6 additions & 7 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,19 @@ module.exports = {
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
// you need to specify `i18n` loaders key with
// `vue-i18n-loader` (https://github.com/kazupon/vue-i18n-loader)
i18n: '@kazupon/vue-i18n-loader',
},
},
},
// this will apply to both plain `.css` files
// AND `<style>` blocks in `.vue` files
{
test: /\.css$/,
use: ['vue-style-loader', 'css-loader'],
},
// https://github.com/intlify/vue-i18n-loader
{
resourceQuery: /blockType=i18n/,
type: 'javascript/auto',
loader: '@intlify/vue-i18n-loader',
},
],
},
plugins: [
Expand Down

0 comments on commit dee2464

Please sign in to comment.