All Projects → paulgv → nuxt-i18n-routing

paulgv / nuxt-i18n-routing

Licence: other
Localized routing with Nuxt.js

Programming Languages

javascript
184084 projects - #8 most used programming language
Vue
7211 projects

Projects that are alternatives of or similar to nuxt-i18n-routing

I18n Module
i18n for Nuxt
Stars: ✭ 808 (+2425%)
Mutual labels:  i18n, routing, nuxt
nuxt-i18n-boilerplate
A boilerplate for rapid application development using Nuxt i18n.
Stars: ✭ 20 (-37.5%)
Mutual labels:  i18n, nuxt
awrora-starter
Landing page template built with one of most popular javascript library Vue.JS, Vuetify (Material Design) and Nuxt.JS with SSR.
Stars: ✭ 38 (+18.75%)
Mutual labels:  i18n, nuxt
k-domains
A simple module to manage multiple subdomains with just one project
Stars: ✭ 41 (+28.13%)
Mutual labels:  routing, nuxt
Veluxi Starter
Veluxi Vue.js Starter Project with Nuxt JS and Vuetify
Stars: ✭ 39 (+21.88%)
Mutual labels:  i18n, nuxt
Nuxt Juejin Project
仿掘金web网站,使用服务端渲染。主要技术:nuxt + koa + vuex + axios + element-ui 。
Stars: ✭ 209 (+553.13%)
Mutual labels:  i18n, nuxt
Elefant
Elefant, the refreshingly simple PHP CMS and web framework.
Stars: ✭ 188 (+487.5%)
Mutual labels:  i18n, routing
nuxt-i18n-example
nuxt-i18n showcase project based on nuxt-starter template
Stars: ✭ 67 (+109.38%)
Mutual labels:  i18n, nuxt
Hangar
A plugin repository used for paper plugins
Stars: ✭ 150 (+368.75%)
Mutual labels:  nuxt
framework
The Hybrid Vue(3) Framework.
Stars: ✭ 7,597 (+23640.63%)
Mutual labels:  nuxt
bcp-47-normalize
Normalize, canonicalize, and format BCP 47 tags
Stars: ✭ 16 (-50%)
Mutual labels:  i18n
koro
A Bengali (বাংলা) version of the Go compiler and toolchain
Stars: ✭ 77 (+140.63%)
Mutual labels:  i18n
next-intl
A minimal, but complete solution for internationalization in Next.js apps. 🌐
Stars: ✭ 242 (+656.25%)
Mutual labels:  i18n
nuxt-basic-blog
A set of starter blog templates to use with Nuxt.
Stars: ✭ 47 (+46.88%)
Mutual labels:  nuxt
i18n.cr
Internationalization API ( i18n ) for Crystal!
Stars: ✭ 36 (+12.5%)
Mutual labels:  i18n
flow-router
🚦 Carefully extended flow-router for Meteor
Stars: ✭ 191 (+496.88%)
Mutual labels:  routing
RouteNow
RouteNow is a small fast library ⚡ that will help you in developing a SinglePage Application without any dependencies like jQuery, AngularJs, vue.js or any of those bulky frameworks.
Stars: ✭ 17 (-46.87%)
Mutual labels:  routing
supabase
An easy way to integrate Supabase with NuxtJS
Stars: ✭ 39 (+21.88%)
Mutual labels:  nuxt
routing-py
🌎 Python library to access all public routing, isochrones and matrix APIs in a consistent manner.
Stars: ✭ 106 (+231.25%)
Mutual labels:  routing
nuxt-humans-txt
🧑🏻👩🏻 "We are people, not machines" - An initiative to know the creators of a website. Contains the information about humans to the web building - A Nuxt Module to statically integrate and generate a humans.txt author file - Based on the HumansTxt Project.
Stars: ✭ 27 (-15.62%)
Mutual labels:  nuxt

nuxt-i18n-routing

Localized routing with Nuxt.js

nuxt-i18n module

Check out nuxt-i18n module which is based on the work you'll find here.

Info

This project showcases a way of achieving localized routing with Nuxt.js. It's not fully tested and you should expect that this might not work for your specific needs. In particular, nested routing has not been tried at all and might require additional work to be properly supported.

Configuration

In ~/config/index.js, we define the i18n configuration:

  • LOCALES is an array of languages available in the app
  • DEFAULT_LOCALE is the app's main language, routes for this language won't have a lang prefix
  • ROUTES_ALIASES is an object where custom paths can be defined for generated routes, each key should match one of Nuxt's original routes name. Use this if you want to translate some URLs in the app, visit the "About" page to see this in action.

Routes generator

In order to "localize" the routes, a generator function overrides all the routes that Nuxt generates by reading the pages/ directory contents. The generator is imported in nuxt.config.js and used in the extendRoutes method.

See the code in ~/utils/router.js.

Store

A small Vuex store module is used to persist user's locale preference accross pages.

See the code in ~/store/i18n/.

Plugin

A simple plugins is used to inialize vue-i18n which provides all translation features in the app.

See the code in ~/plugins/vue-i18n.js.

Middleware

A middleware, heavily inspired by Nuxt's i18n example, handles language switching using the language from the URL.

See the code in ~/middleware/i18n.js.

Mixin

A global mixin provides 2 methods responsible for generating links in the app:

  • getLocalizedRoute (route, locale) – Returns the path corresponding to a given route for the request language. If route is a string, it will be used as the route's name. The route's name should correspond to the original name that was generated by Nuxt. Refer to Nuxt doc to see how it generates routes names. If locale is omitted, the app's current locale is used.
  • getSwitchLocaleRoute (locale) – Returns the URL of the current page for the requested language.

In Vue components, display links as follows:

<!-- Using the route's name -->
<nuxt-link :to="getLocalizedRoute('index')">
  {{ $t('labels.home') }}
</nuxt-link>

<!-- Using a route object with parameters -->
<nuxt-link :to="getLocalizedRoute({ name: 'category-slug', params: { slug: 'landscapes' } })">
  {{ $t('categories.landscapes') }}
</nuxt-link>

See the code in ~/plugins/global-mixin.js.

Build Setup

# install dependencies
$ yarn

# serve with hot reload at localhost:3000
$ yarn dev

# build for production and launch server
$ yarn build
$ yarn start

# generate static project
$ yarn generate

For detailed explanation on how things work, checkout the Nuxt.js docs.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].