Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgv committed Jan 22, 2018
2 parents a866fb5 + 9e2b03c commit 00287e5
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 12 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

<a name="1.1.0"></a>
# [1.1.0](https://github.com/paulgv/nuxt-i18n/compare/v1.0.2...v1.1.0) (2018-01-22)


### Features

* Add ignorePaths option ([1a0fc57](https://github.com/paulgv/nuxt-i18n/commit/1a0fc57))



<a name="1.0.2"></a>
## [1.0.2](https://github.com/paulgv/nuxt-i18n/compare/v1.0.1...v1.0.2) (2017-12-07)

Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ In the app, you'll need to preserve the language when generating URLs. To do thi
| `defaultLocale` | String | The app's default locale, URLs for this language won't be prefixed with the locale code |
| `vueI18n` | Object | Configuration options for vue-i18n, refer to [the doc](http://kazupon.github.io/vue-i18n/en/api.html#constructor-options) for supported options |
| `routes` | Object | Custom routing configuration, if routes are omitted, Nuxt's default routes are used |
| `ignorePaths` | Array | A list of paths that should not be localized |


## Configuration example
Expand Down Expand Up @@ -232,7 +233,10 @@ module.exports = {
'category-slug': {
fr: '/categorie/:slug'
}
}
},
ignorePaths: [
'/fr/notlocalized'
]
}]
]
}
Expand Down
3 changes: 2 additions & 1 deletion lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module.exports = function (moduleOptions) {
baseRoutes: routes,
locales: options.locales,
defaultLocale: options.defaultLocale,
routesOptions: options.routes
routesOptions: options.routes,
ignorePaths: options.ignorePaths
})
routes.splice(0, routes.length)
routes.unshift(...newRoutes)
Expand Down
22 changes: 20 additions & 2 deletions lib/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,30 @@ const { has } = require('lodash')
* defaults to app's configured LOCALES
* @return {Array} Localized routes to be used in Nuxt config
*/
const generateRoutes = ({ baseRoutes, locales, defaultLocale, routesOptions, isChild = false }) => {
const generateRoutes = ({
baseRoutes,
locales,
defaultLocale,
routesOptions,
ignorePaths = [],
isChild = false }) => {
// Abort routes generation if no routes or locales specified
if (!baseRoutes || !locales) {
return []
}
const newRoutes = []
baseRoutes.forEach((baseRoute) => {
const localizedRoutes = []

// Extract routes that should not be localized
baseRoutes.forEach(route => {
if (ignorePaths.indexOf(route.path) !== -1) {
newRoutes.push(route)
} else {
localizedRoutes.push(route)
}
})

localizedRoutes.forEach(baseRoute => {
locales.forEach((locale) => {
const { component } = baseRoute
let { path, name, children } = baseRoute
Expand All @@ -24,6 +41,7 @@ const generateRoutes = ({ baseRoutes, locales, defaultLocale, routesOptions, isC
locales: [locale],
defaultLocale,
routesOptions,
ignorePaths,
isChild: true
})
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nuxt-i18n",
"version": "1.0.2",
"version": "1.1.0",
"description": "i18n for Nuxt",
"license": "MIT",
"contributors": [
Expand Down
11 changes: 4 additions & 7 deletions test/fixture/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,11 @@ module.exports = {
about: {
fr: '/a-propos',
en: '/about-us'
},
category: {
fr: '/categorie'
},
'category-slug': {
fr: '/categorie/:slug'
}
}
},
ignorePaths: [
'/fr/notlocalized'
]
}]
]
}
10 changes: 10 additions & 0 deletions test/fixture/pages/fr/notlocalized.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<template>
<div>
FR only
</div>
</template>

<script>
export default {
}
</script>
21 changes: 21 additions & 0 deletions test/module.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,27 @@ describe('Module', () => {
expect(html).toContain('<a href="/fr/">Accueil</a>')
})

test('/fr/notlocalized contains FR text', async () => {
let html = await get('/fr/notlocalized')
expect(html).toContain('FR only')
})

test('/notlocalized & /fr/fr/notlocalized return 404', async () => {
let response
try {
response = await get('/notlocalized')
} catch (error) {
response = error
}
expect(response.statusCode).toBe(404)
try {
response = await get('/fr/fr/notlocalized')
} catch (error) {
response = error
}
expect(response.statusCode).toBe(404)
})

test('/posts contains EN text, link to /fr/posts/ & link to /posts/my-slug', async () => {
let html = await get('/posts')
expect(html).toContain('Posts')
Expand Down

0 comments on commit 00287e5

Please sign in to comment.