Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(strategy): add PREFIX_AND_DEFAULT strategy #111

Merged
merged 3 commits into from
Aug 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/options-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Here are all the options available when configuring the module and their default
// Routes generation strategy, can be set to one of the following:
// - 'prefix_except_default': add locale prefix for every locale except default
// - 'prefix': add locale prefix for every locale
// - 'prefix_and_default': add locale prefix for every locale and default
strategy: 'prefix_except_default',

// Wether or not the translations should be lazy-loaded, if this is enabled,
Expand Down
6 changes: 5 additions & 1 deletion docs/routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ Using this strategy, all of your routes will have a locale prefix added except f

With this strategy, all routes will have a locale prefix.

To configure the strategy, use the `strategy` option. Make sure you have a `defaultLocale` defined if using **prefix_except_default** strategy.
### prefix_and_default

Using this strategy, in addition to 'prefix' strategy, the route add `/` that use the default language

To configure the strategy, use the `strategy` option. Make sure you have a `defaultLocale` defined if using **prefix_except_default** or **prefix_and_default** strategy.


```js
Expand Down
3 changes: 2 additions & 1 deletion src/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export const LOCALE_FILE_KEY = 'file'
// Options
export const STRATEGIES = {
PREFIX: 'prefix',
PREFIX_EXCEPT_DEFAULT: 'prefix_except_default'
PREFIX_EXCEPT_DEFAULT: 'prefix_except_default',
PREFIX_AND_DEFAULT: 'prefix_and_default'
}
export const COMPONENT_OPTIONS_KEY = 'nuxtI18n'
export const DEFAULT_OPTIONS = {
Expand Down
6 changes: 6 additions & 0 deletions src/helpers/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,19 @@ export const makeRoutes = (baseRoutes, {
// Skip default locale if strategy is PREFIX_EXCEPT_DEFAULT
!(locale === defaultLocale && strategy === STRATEGIES.PREFIX_EXCEPT_DEFAULT)
)

if (locale === defaultLocale && strategy === STRATEGIES.PREFIX_AND_DEFAULT) {
routes.push({...localizedRoute, path})
}

if (shouldAddPrefix) {
path = `/${locale}${path}`
}

localizedRoute.path = path

routes.push(localizedRoute)

}

return routes
Expand Down