![]() ![]() I will start with the Router.push method js // plugins/i18n-routing.js import Router from 'vue-router' // Save refs to original router methods. ![]() Before we can do that we need to save a reference to the original router methods because we are going to use them later. Fortunately for us, the VueRouter uses a class for the router, which means we could modify it's prototype and override the original methods. So go ahead a create a plugins/i18n-routing.js file. To correctly do this, you need to access the Router class methods before any usage of it comes up, one of the earliest places we can do this is by creating a nuxt plugin. What we are going to do is intercept all Router.push and Router.replace calls and pre-pend the locale code, then we call the original methods with the new localized path. This is why we are resorting to "Monkey Patching" which is one of the oldest methods in JavaScript to override some behavior. In this step by step guide you will learn how to add internationalization support, work with transla. This is a slightly harder problem, because unlike components we cannot cleanly introduce our locale pre-pending logic to router instance methods or the redirect function. Learn how to manage the i18n process of your Vue.js app. We have the traditional routing components: vue Language Aware Navigation We have various ways to redirect the current page in a Nuxt.js application. We tend to call this "search engine optimization" or as commonly refereed to as "SEO". These are not the types of applications I'm talking about in this Article, I'm talking about web apps with URLs like this: sh įor these applications including the language code in the URL is a necessity because it helps each audience able to reach the content they would identify with the most. These types of applications usually do not include the language code in their URLs. In many applications you may be using right now, the user may set their preferred language via a setting that saves it to the cookies ensuring the app can always infer the current language preferred by the user. So even if you are starting on a project with a single language it will almost be required at some point to add multi-language support to it. For as long as I can remember, building multi-language websites is the norm in Egypt and catering for multi-language audience is an expectation rather than a "nice-to-have". ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |